Skip to content

Commit 7c318a3

Browse files
mahima-yogaMaEtUgR
authored andcommitted
MulticopterPositionControl: prevent velocity integrator filling up from stale acceleration setpoints
When position control is disabled, clear the setpoint properly to prevent stale values. This fixes a bug where switching to position mode in the same control loop as a hover thrust estimate update could fill up the velocity integrator.
1 parent 0375f1a commit 7c318a3

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/modules/mc_pos_control/MulticopterPositionControl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ void MulticopterPositionControl::Run()
408408
} else if (previous_position_control_enabled && !_vehicle_control_mode.flag_multicopter_position_control_enabled) {
409409
// clear existing setpoint when controller is no longer active
410410
_setpoint = PositionControl::empty_trajectory_setpoint;
411+
_control.setInputSetpoint(_setpoint);
411412
}
412413
}
413414
}

src/modules/mc_pos_control/PositionControl/PositionControl.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,11 @@ void PositionControl::updateHoverThrust(const float hover_thrust_new)
8484
const float previous_hover_thrust = _hover_thrust;
8585
setHoverThrust(hover_thrust_new);
8686

87-
_vel_int(2) += (_acc_sp(2) - CONSTANTS_ONE_G) * previous_hover_thrust / _hover_thrust
88-
+ CONSTANTS_ONE_G - _acc_sp(2);
87+
if (PX4_ISFINITE(_acc_sp(2))) {
88+
_vel_int(2) += (_acc_sp(2) - CONSTANTS_ONE_G) * previous_hover_thrust / _hover_thrust
89+
+ CONSTANTS_ONE_G - _acc_sp(2);
90+
}
91+
8992
}
9093

9194
void PositionControl::setState(const PositionControlStates &states)

0 commit comments

Comments
 (0)