GCS_MAVLink: fixed bug setting parameters to default values

in copter if you try to set RATE_RLL_D to 0 when you haven't
prevviously changed it then it would set it, but would revert on the
next reboot. This is because of the special case handling of a set to
the "default" value. That default value is unaware of the PID
constructors

this fixes that behaviour by forcing a save if the parameter changes
value
This commit is contained in:
Andrew Tridgell 2015-08-10 17:27:02 +10:00
parent 269f1fd99a
commit 9352f05133
1 changed files with 16 additions and 2 deletions

View File

@ -556,13 +556,27 @@ void GCS_MAVLINK::handle_param_set(mavlink_message_t *msg, DataFlash_Class *Data
strncpy(key, (char *)packet.param_id, AP_MAX_NAME_SIZE);
key[AP_MAX_NAME_SIZE] = 0;
vp = AP_Param::set_param_by_name(key, packet.param_value, &var_type);
// find existing param so we can get the old value
vp = AP_Param::find(key, &var_type);
if (vp == NULL) {
return;
}
float old_value = vp->cast_to_float(var_type);
// set the value
vp->set_float(packet.param_value, var_type);
/*
we force the save if the value is not equal to the old
value. This copes with the use of override values in
constructors, such as PID elements. Otherwise a set to the
default value which differs from the constructor value doesn't
save the change
*/
bool force_save = !is_equal(packet.param_value, old_value);
// save the change
vp->save();
vp->save(force_save);
// Report back the new value if we accepted the change
// we send the value we actually set, which could be