APM_Control: reduce the number of parameter saves in autotune

don't save a parameter unless it has changed by 0.1%
This commit is contained in:
Andrew Tridgell 2014-04-17 17:20:40 +10:00
parent ccc7d36493
commit b4c5f31b17
2 changed files with 19 additions and 4 deletions

View File

@ -260,16 +260,29 @@ void AP_AutoTune::check_save(void)
last_save_ms = hal.scheduler->millis();
}
/*
set a float and save a float if it has changed by more than
0.1%. This reduces the number of insignificant EEPROM writes
*/
void AP_AutoTune::save_float_if_changed(AP_Float &v, float value)
{
float old_value = v.get();
v.set(value);
if (value <= 0 || fabsf((value-old_value)/value) > 0.001f) {
v.save();
}
}
/*
save a set of gains
*/
void AP_AutoTune::save_gains(const ATGains &v)
{
current = last_save;
current.tau.set_and_save_ifchanged(v.tau);
current.P.set_and_save_ifchanged(v.P);
current.I.set_and_save_ifchanged(v.I);
current.D.set_and_save_ifchanged(v.D);
save_float_if_changed(current.tau, v.tau);
save_float_if_changed(current.P, v.P);
save_float_if_changed(current.I, v.I);
save_float_if_changed(current.D, v.D);
current.rmax.set_and_save_ifchanged(v.rmax);
current.imax.set_and_save_ifchanged(v.imax);
last_save = current;

View File

@ -85,6 +85,8 @@ private:
void write_log_headers(void);
void write_log(float servo, float demanded, float achieved);
void save_float_if_changed(AP_Float &v, float value);
};
#endif // __AP_AUTOTUNE_H__