ArduPilot / ardupilot

ArduPlane, ArduCopter, ArduRover, ArduSub source
http://ardupilot.org/
GNU General Public License v3.0
10.86k stars 17.31k forks source link

BUG: AP_AHRS_DCM.cpp has a bug at correct_centrifugal in drift_correction function #26431

Open luweiagi opened 7 months ago

luweiagi commented 7 months ago

https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_AHRS/AP_AHRS_DCM.cpp#L785

    if (should_correct_centrifugal() && (_have_gps_lock || fly_forward)) {
        ...
    }

should be fixed as:

    if (should_correct_centrifugal() && (_have_gps_lock || (fly_forward && airspeed_sensor_enabled()))) {
        ...
    }

Because if we have no airspeed sensor, then the ground velocity is not correct, so we can not estimate centrifugal using velocity change per second.

Why ground velocity is not correct if no airspeed sensor when GPS is unusable? Because we can see here: https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_AHRS/AP_AHRS_DCM.cpp#L707

    if (!have_gps() || _gps.status() < AP_GPS::GPS_OK_FIX_3D || _gps.num_sats() < _gps_minsats) {
        ...

        float airspeed = _last_airspeed;
#if AP_AIRSPEED_ENABLED
        if (airspeed_sensor_enabled()) {
            airspeed = AP::airspeed()->get_airspeed();
        }
#endif

        // use airspeed to estimate our ground velocity in
        // earth frame by subtracting the wind
        velocity = _dcm_matrix.colx() * airspeed;

        // add in wind estimate
        velocity += _wind;
        ...
    } else {

ground velocity = airspeed + wind But, we can see that if airspeed sensor is not install or not usable, airspeed is always equal to _last_airspeed = 0.0f, so velocity is not right.

I don't know who I should @? @lthall @amilcarlucas ?

rmackay9 commented 7 months ago

@luweiagi,

This is more for @tridge and @priseborough I think.