Copter: bug fix to set sonar_alt_health to zero when disabled

This commit is contained in:
rmackay9 2013-01-31 17:00:28 +09:00
parent 70371be4a1
commit 9c3b9907dd
2 changed files with 10 additions and 2 deletions

View File

@ -2094,8 +2094,10 @@ static void update_altitude()
baro_rate = constrain(baro_rate, -500, 500);
// read in sonar altitude and calculate sonar rate
if(g.sonar_enabled) {
sonar_alt = read_sonar();
sonar_alt = read_sonar();
// start calculating the sonar_rate as soon as valid sonar readings start coming in so that we are ready when the sonar_alt_health becomes 3
// Note: post 2.9.1 release we will remove the sonar_rate variable completely
if(sonar_alt_health > 1) {
sonar_rate = (sonar_alt - old_sonar_alt) * 10;
sonar_rate = constrain(sonar_rate, -150, 150);
}

View File

@ -35,6 +35,12 @@ static int32_t read_barometer(void)
static int16_t read_sonar(void)
{
#if CONFIG_SONAR == ENABLED
// exit immediately if sonar is disabled
if( !g.sonar_enabled ) {
sonar_alt_health = 0;
return 0;
}
int16_t temp_alt = sonar->read();
if (temp_alt >= sonar->min_distance && temp_alt <= sonar->max_distance * 0.70f) {