Skip to content

Commit 0615c45

Browse files
committed
AC_AttitudeControl: added set_xy_control_scale_factor()
allows for systemID to reduce XY gains in pos controlled modes
1 parent 16266ed commit 0615c45

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

libraries/AC_AttitudeControl/AC_PosControl.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,10 @@ void AC_PosControl::update_xy_controller()
679679
// add velocity feed-forward scaled to compensate for optical flow measurement induced EKF noise
680680
vel_target *= ahrsControlScaleXY;
681681

682+
if (_xy_control_scale_factor > 0) {
683+
vel_target *= _xy_control_scale_factor;
684+
}
685+
682686
_vel_target.xy() = vel_target;
683687
_vel_target.xy() += _vel_desired.xy() + _vel_offset.xy();
684688

@@ -694,6 +698,12 @@ void AC_PosControl::update_xy_controller()
694698
// acceleration to correct for velocity error and scale PID output to compensate for optical flow measurement induced EKF noise
695699
accel_target *= ahrsControlScaleXY;
696700

701+
if (_xy_control_scale_factor > 0) {
702+
accel_target *= _xy_control_scale_factor;
703+
}
704+
705+
_xy_control_scale_factor = 0;
706+
697707
// pass the correction acceleration to the target acceleration output
698708
_accel_target.xy() = accel_target;
699709
_accel_target.xy() += _accel_desired.xy() + _accel_offset.xy();

libraries/AC_AttitudeControl/AC_PosControl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ class AC_PosControl
140140
/// stop_vel_xy_stabilisation - sets the target to the current position and velocity to the current velocity to remove any position and velocity corrections from the system
141141
void stop_vel_xy_stabilisation();
142142

143+
/// set a single loop XY control scale factor. Set to zero to disable
144+
void set_xy_control_scale_factor(float xy_scale_factor) {
145+
_xy_control_scale_factor = xy_scale_factor;
146+
}
147+
143148
/// update_xy_controller - runs the horizontal position controller correcting position, velocity and acceleration errors.
144149
/// Position and velocity errors are converted to velocity and acceleration targets using PID objects
145150
/// Desired velocity and accelerations are added to these corrections as they are calculated
@@ -540,6 +545,7 @@ class AC_PosControl
540545
float _vel_z_control_ratio = 2.0f; // confidence that we have control in the vertical axis
541546
Vector2f _disturb_pos; // position disturbance generated by system ID mode
542547
Vector2f _disturb_vel; // velocity disturbance generated by system ID mode
548+
float _xy_control_scale_factor; // single loop scale factor for XY control
543549

544550
// output from controller
545551
float _roll_target; // desired roll angle in centi-degrees calculated by position controller

0 commit comments

Comments
 (0)