mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-24 07:09:48 +08:00
mag_cal: fix race condition causing invalid mag calibration
In some cases, the fitness of the optimizer does not shrink at each iteration, causing the "decreasing fitness check" to fail. This stops the optimization and returns with sub-optimal, or unrealistic results.
This commit is contained in:
@@ -587,8 +587,13 @@ calibrate_return mag_calibrate_all(orb_advert_t *mavlink_log_pub, int32_t cal_ma
|
||||
sphere_fit_success = true;
|
||||
|
||||
} else {
|
||||
// stop here if fit has previously succeeded
|
||||
if (sphere_fit_success) {
|
||||
// stop here if fit has previously succeeded an if it is good enough
|
||||
// TODO: extract those conditions for the unit test
|
||||
if (sphere_fit_success
|
||||
&& (i > 10)
|
||||
&& (fitness < 0.01f)
|
||||
&& (sphere_radius[cur_mag] >= 0.2f)
|
||||
&& (sphere_radius[cur_mag] <= 0.7f)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user