Skip to content

Commit 649d3a3

Browse files
lthalltridge
authored andcommitted
AC_PosControl: Fix slow target decay decay problem
1 parent 78d45a5 commit 649d3a3

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

libraries/AC_AttitudeControl/AC_PosControl.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -454,12 +454,12 @@ void AC_PosControl::init_xy_controller_stopping_point()
454454
/// This function decays the output acceleration by 95% every half second to achieve a smooth transition to zero requested acceleration.
455455
void AC_PosControl::relax_velocity_controller_xy()
456456
{
457-
init_xy_controller();
458-
459-
// decay resultant acceleration and therefore current attitude target to zero
457+
// decay acceleration and therefore current attitude target to zero
458+
// this will be reset by init_xy_controller() if !is_active_xy()
460459
float decay = 1.0 - _dt / (_dt + POSCONTROL_RELAX_TC);
461460
_accel_target.xy() *= decay;
462-
_pid_vel_xy.set_integrator(_accel_target - _accel_desired);
461+
462+
init_xy_controller();
463463
}
464464

465465
/// reduce response for landing
@@ -494,7 +494,9 @@ void AC_PosControl::init_xy_controller()
494494
// Set desired accel to zero because raw acceleration is prone to noise
495495
_accel_desired.xy().zero();
496496

497-
lean_angles_to_accel_xy(_accel_target.x, _accel_target.y);
497+
if (!is_active_xy()) {
498+
lean_angles_to_accel_xy(_accel_target.x, _accel_target.y);
499+
}
498500

499501
// limit acceleration using maximum lean angles
500502
float angle_max = MIN(_attitude_control.get_althold_lean_angle_max_cd(), get_lean_angle_max_cd());
@@ -1024,9 +1026,9 @@ Vector3f AC_PosControl::lean_angles_to_accel(const Vector3f& att_target_euler) c
10241026
const float cos_yaw = cosf(att_target_euler.z);
10251027

10261028
return Vector3f{
1027-
(GRAVITY_MSS * 100) * (-cos_yaw * sin_pitch * cos_roll - sin_yaw * sin_roll) / MAX(cos_roll * cos_pitch, 0.1f),
1028-
(GRAVITY_MSS * 100) * (-sin_yaw * sin_pitch * cos_roll + cos_yaw * sin_roll) / MAX(cos_roll * cos_pitch, 0.1f),
1029-
(GRAVITY_MSS * 100)
1029+
(GRAVITY_MSS * 100.0f) * (-cos_yaw * sin_pitch * cos_roll - sin_yaw * sin_roll) / MAX(cos_roll * cos_pitch, 0.1f),
1030+
(GRAVITY_MSS * 100.0f) * (-sin_yaw * sin_pitch * cos_roll + cos_yaw * sin_roll) / MAX(cos_roll * cos_pitch, 0.1f),
1031+
(GRAVITY_MSS * 100.0f)
10301032
};
10311033
}
10321034

0 commit comments

Comments
 (0)