fix: take current trim values into account when doing trim calibration

This commit is contained in:
tumbili 2015-06-12 13:50:02 +02:00
parent e7765d77f6
commit 7e44a23411
1 changed files with 14 additions and 4 deletions

View File

@ -68,16 +68,26 @@ int do_trim_calibration(int mavlink_fd)
orb_copy(ORB_ID(manual_control_setpoint), sub_man, &sp);
/* set parameters */
float p = sp.y;
/* load trim values which are active */
float roll_trim_active;
param_get(param_find("TRIM_ROLL"), &roll_trim_active);
float pitch_trim_active;
param_get(param_find("TRIM_PITCH"), &pitch_trim_active);
float yaw_trim_active;
param_get(param_find("TRIM_YAW"), &yaw_trim_active);
/* set parameters: the new trim values are the combination of active trim values
and the values coming from the remote control of the user
*/
float p = sp.y + roll_trim_active;
int p1r = param_set(param_find("TRIM_ROLL"), &p);
/*
we explicitly swap sign here because the trim is added to the actuator controls
which are moving in an inverse sense to manual pitch inputs
*/
p = -sp.x;
p = -sp.x + pitch_trim_active;
int p2r = param_set(param_find("TRIM_PITCH"), &p);
p = sp.r;
p = sp.r + yaw_trim_active;
int p3r = param_set(param_find("TRIM_YAW"), &p);
/* store to permanent storage */