jeudi 24 novembre 2016

Is output data out of controlled if nothing to do in else stamement

1 cm is occasionally received in the serial input from a Lidar-lite V3 where there're two very difference contiguous distance value (ex. 500 & 700). I use if-else statement to remove 1 cm data in below function. This function is supposed to return distance always, therefore, people said I should not use if-else in the function otherwise output data will be out of controlled in else statement, due to nothing to do.

int LIDARLite::distance(bool biasCorrection, char lidarliteAddress)
{
    if (biasCorrection)
    {
        // Take acquisition & correlation processing with receiver bias correction
        write(0x00, 0x04, lidarliteAddress);
    }
    else
    {
        // Take acquisition & correlation processing without receiver bias correction
        write(0x00, 0x03, lidarliteAddress);
    }
    // Array to store high and low bytes of distance
    byte distanceArray[2];
    // Read two bytes from register 0x8f (autoincrement for reading 0x0f and 0x10)
    read(0x8f, 2, distanceArray, true, lidarliteAddress);
    // Shift high byte and add to low byte
    int distance = (distanceArray[0] << 8) + distanceArray[1];
    return(distance);
    /*//    return(distance);*/
    int readdistance = distance;
    if (readdistance > 1 ){
        return(distance);
    }
    else { 
    }
    delay(10);
    /*return(distance);*/
} /* LIDARLite::distance */

I want to know if there's any alternative way to remove 1cm output.

Aucun commentaire:

Enregistrer un commentaire