diff --git a/src/modules/mc_pos_control/MulticopterPositionControl.cpp b/src/modules/mc_pos_control/MulticopterPositionControl.cpp index 173f0937b4..e8a3d5234d 100644 --- a/src/modules/mc_pos_control/MulticopterPositionControl.cpp +++ b/src/modules/mc_pos_control/MulticopterPositionControl.cpp @@ -290,7 +290,7 @@ void MulticopterPositionControl::Run() if (_vehicle_control_mode.flag_multicopter_position_control_enabled) { - _trajectory_setpoint_sub.update(&_setpoint); + const bool is_trajectory_setpoint_updated = _trajectory_setpoint_sub.update(&_setpoint); // adjust existing (or older) setpoint with any EKF reset deltas if (_setpoint.timestamp < local_pos.timestamp) { @@ -361,22 +361,25 @@ void MulticopterPositionControl::Run() _vehicle_constraints.want_takeoff, _vehicle_constraints.speed_up, false, time_stamp_now); - const bool not_taken_off = (_takeoff.getTakeoffState() < TakeoffState::rampup); - const bool flying = (_takeoff.getTakeoffState() >= TakeoffState::flight); - const bool flying_but_ground_contact = (flying && _vehicle_land_detected.ground_contact); + const bool flying = (_takeoff.getTakeoffState() >= TakeoffState::flight); - // make sure takeoff ramp is not amended by acceleration feed-forward - if (!flying) { - _setpoint.acceleration[2] = NAN; - } + if (is_trajectory_setpoint_updated) { + // make sure takeoff ramp is not amended by acceleration feed-forward + if (!flying) { + _setpoint.acceleration[2] = NAN; + } - if (not_taken_off || flying_but_ground_contact) { - // we are not flying yet and need to avoid any corrections - reset_setpoint_to_nan(_setpoint); - Vector3f(0.f, 0.f, 100.f).copyTo(_setpoint.acceleration); // High downwards acceleration to make sure there's no thrust + const bool not_taken_off = (_takeoff.getTakeoffState() < TakeoffState::rampup); + const bool flying_but_ground_contact = (flying && _vehicle_land_detected.ground_contact); - // prevent any integrator windup - _control.resetIntegral(); + if (not_taken_off || flying_but_ground_contact) { + // we are not flying yet and need to avoid any corrections + reset_setpoint_to_nan(_setpoint); + Vector3f(0.f, 0.f, 100.f).copyTo(_setpoint.acceleration); // High downwards acceleration to make sure there's no thrust + + // prevent any integrator windup + _control.resetIntegral(); + } } // limit tilt during takeoff ramupup