mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-27 01:50:34 +08:00
fix(mc_pos_control): stop the velocity limit cutting out the braking feedforward (#28350)
* fix(mc_pos_control): stop the velocity limit cutting out the braking feedforward Signed-off-by: LeonardoHaitzmann <leonardo.haitzmann@auterion.com> * fix(flight_mode_manager): key emergency braking on the measured velocity Signed-off-by: LeonardoHaitzmann <leonardo.haitzmann@auterion.com> * fix(MulticoperPositionControl): decaying velocity limit when entering position control instead of shared emergency_braking state * fix(MulticoperPositionControl): static velocity limit decay * fix(MulticopterPositionControl): takeoff state machine, switch from Altitude to Position --------- Signed-off-by: LeonardoHaitzmann <leonardo.haitzmann@auterion.com> Co-authored-by: Matthias Grob <maetugr@gmail.com>
This commit is contained in:
1 parent
377dcbfa6a
commit
2750a9bd27
4 files changed
+93
-23
No files matched your search
@@ -39,6 +39,7 @@
|
||||
#include <float.h>
|
||||
|
||||
using namespace matrix;
|
||||
using namespace time_literals;
|
||||
|
||||
bool FlightTaskAuto::activate(const trajectory_setpoint_s &last_setpoint)
|
||||
{
|
||||
@@ -211,9 +212,8 @@ bool FlightTaskAuto::update()
|
||||
_updateTrajConstraints();
|
||||
|
||||
if (_is_emergency_braking_active) {
|
||||
// Re-seed the trajectory to the measured state every cycle so controller saturation doesn't
|
||||
// cause a velocity error inversion during emergency braking.
|
||||
_position_smoothing.forceSetVelocity(_velocity);
|
||||
// Keep the trajectory position on the vehicle so the position error doesn't get corrected at
|
||||
// the expense of the braking feedforward.
|
||||
_position_smoothing.forceSetPosition(_position);
|
||||
}
|
||||
|
||||
@@ -731,24 +731,54 @@ void FlightTaskAuto::_ekfResetHandlerHeading(const float delta_psi)
|
||||
void FlightTaskAuto::_checkEmergencyBraking()
|
||||
{
|
||||
if (!_is_emergency_braking_active) {
|
||||
// activate emergency braking if significantly outside of velocity bounds
|
||||
// Activate emergency braking if either the vehicle or the trajectory is significantly outside of
|
||||
// velocity bounds. activate() seeds the trajectory from the previous task's setpoint, which
|
||||
// is not bounded by this task's limits.
|
||||
const float factor = 1.3f;
|
||||
const bool is_vertical_speed_exceeded = _position_smoothing.getCurrentVelocityZ() >
|
||||
(factor * _param_mpc_z_vel_max_dn.get())
|
||||
|| _position_smoothing.getCurrentVelocityZ() < -(factor * _param_mpc_z_vel_max_up.get());
|
||||
const bool is_horizontal_speed_exceeded = _position_smoothing.getCurrentVelocityXY().longerThan(
|
||||
factor * _param_mpc_xy_vel_max.get());
|
||||
const float speed_down = math::max(_velocity(2), _position_smoothing.getCurrentVelocityZ());
|
||||
const float speed_up = -math::min(_velocity(2), _position_smoothing.getCurrentVelocityZ());
|
||||
const float speed_horizontal = math::max(Vector2f(_velocity).norm(),
|
||||
_position_smoothing.getCurrentVelocityXY().norm());
|
||||
// _updateTrajConstraints() lets ordinary descents past MPC_Z_VEL_MAX_DN, so the margin has to be
|
||||
// taken against what guidance can actually reach or a downdraft would trigger braking mid-mission.
|
||||
const float max_speed_down = math::max(_param_mpc_z_vel_max_dn.get(), 1.2f * _param_mpc_z_v_auto_dn.get());
|
||||
const bool is_vertical_speed_exceeded = (speed_down > factor * max_speed_down)
|
||||
|| (speed_up > factor * _param_mpc_z_vel_max_up.get());
|
||||
const bool is_horizontal_speed_exceeded = speed_horizontal > (factor * _param_mpc_xy_vel_max.get());
|
||||
|
||||
if (is_vertical_speed_exceeded || is_horizontal_speed_exceeded) {
|
||||
_is_emergency_braking_active = true;
|
||||
// Start the braking ramp from the vehicle not the reference.
|
||||
_position_smoothing.forceSetVelocity(_velocity);
|
||||
|
||||
_emergency_braking_best_speed = math::max(fabsf(_velocity(2)), Vector2f(_velocity).norm());
|
||||
_emergency_braking_progress_timestamp = _time_stamp_current;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Deactivate emergency braking once slow enough for ordinary guidance to finish the stop.
|
||||
// Must clear velocity estimate noise, otherwise braking latches and guidance never resumes.
|
||||
if (math::isInRange(_position_smoothing.getCurrentVelocityZ(), -1.f, 1.f)
|
||||
&& !_position_smoothing.getCurrentVelocityXY().longerThan(1.f)) {
|
||||
// Check the measured velocity since the trajectory reaches zero well before the vehicle does.
|
||||
const bool is_slow_enough = math::isInRange(_velocity(2), -1.f, 1.f)
|
||||
&& !Vector2f(_velocity).longerThan(1.f);
|
||||
|
||||
// Track the lowest speed reached and deactivate emergency braking if it stops improving.
|
||||
// Avoids getting stuck in emergency braking.
|
||||
const float speed = math::max(fabsf(_velocity(2)), Vector2f(_velocity).norm());
|
||||
|
||||
if (speed < _emergency_braking_best_speed - 0.5f) {
|
||||
_emergency_braking_best_speed = speed;
|
||||
_emergency_braking_progress_timestamp = _time_stamp_current;
|
||||
}
|
||||
|
||||
const bool is_not_slowing_down = _time_stamp_current > _emergency_braking_progress_timestamp + 3_s;
|
||||
|
||||
if (is_slow_enough || is_not_slowing_down) {
|
||||
_is_emergency_braking_active = false;
|
||||
|
||||
// Hand back a trajectory that ordinary guidance can take over. Emergency braking runs the smoother at
|
||||
// 1g right up to the release, so its acceleration state is still around 9.8 m/s^2 while its
|
||||
// velocity state is near zero.
|
||||
_position_smoothing.forceSetAcceleration({0.f, 0.f, 0.f});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,6 +151,8 @@ protected:
|
||||
matrix::Vector3f _land_position;
|
||||
WaypointType _type_previous{WaypointType::idle}; /**< Previous type of current target triplet. */
|
||||
bool _is_emergency_braking_active{false};
|
||||
float _emergency_braking_best_speed{0.f}; /**< lowest speed reached since braking was activated */
|
||||
hrt_abstime _emergency_braking_progress_timestamp{}; /**< last time the braking was still slowing down */
|
||||
bool _want_takeoff{false};
|
||||
|
||||
DEFINE_PARAMETERS_CUSTOM_PARENT(FlightTask,
|
||||
|
||||
@@ -394,17 +394,27 @@ void MulticopterPositionControl::Run()
|
||||
_sample_interval_s.update(dt);
|
||||
|
||||
if (_vehicle_control_mode_sub.updated()) {
|
||||
const bool previous_position_control_enabled = _vehicle_control_mode.flag_multicopter_position_control_enabled;
|
||||
const vehicle_control_mode_s previous = _vehicle_control_mode;
|
||||
|
||||
if (_vehicle_control_mode_sub.copy(&_vehicle_control_mode)) {
|
||||
if (!previous_position_control_enabled && _vehicle_control_mode.flag_multicopter_position_control_enabled) {
|
||||
if (!previous.flag_multicopter_position_control_enabled && _vehicle_control_mode.flag_multicopter_position_control_enabled) {
|
||||
_time_position_control_enabled = _vehicle_control_mode.timestamp;
|
||||
|
||||
} else if (previous_position_control_enabled && !_vehicle_control_mode.flag_multicopter_position_control_enabled) {
|
||||
} else if (previous.flag_multicopter_position_control_enabled && !_vehicle_control_mode.flag_multicopter_position_control_enabled) {
|
||||
// clear existing setpoint when controller is no longer active
|
||||
_setpoint = PositionControl::empty_trajectory_setpoint;
|
||||
_control.setInputSetpoint(_setpoint);
|
||||
}
|
||||
|
||||
// Restart the decaying velocity limits when the controlled axes change e.g. altitude to position or VTOL back transition
|
||||
if ((previous.flag_multicopter_position_control_enabled != _vehicle_control_mode.flag_multicopter_position_control_enabled)
|
||||
|| (previous.flag_control_velocity_enabled != _vehicle_control_mode.flag_control_velocity_enabled)
|
||||
|| (previous.flag_control_climb_rate_enabled != _vehicle_control_mode.flag_control_climb_rate_enabled)) {
|
||||
_vel_limit_xy = NAN;
|
||||
_vel_limit_up = NAN;
|
||||
_vel_limit_down = NAN;
|
||||
_time_vel_limit_reset = _vehicle_control_mode.timestamp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -524,10 +534,8 @@ void MulticopterPositionControl::Run()
|
||||
? _param_mpc_tiltmax_lnd.get() : _param_mpc_tiltmax_air.get();
|
||||
_control.setTiltLimit(_tilt_limit_slew_rate.update(math::radians(tilt_limit_deg), dt));
|
||||
|
||||
const float speed_up = _takeoff.updateRamp(dt,
|
||||
PX4_ISFINITE(_vehicle_constraints.speed_up) ? _vehicle_constraints.speed_up : _param_mpc_z_vel_max_up.get());
|
||||
const float speed_down = PX4_ISFINITE(_vehicle_constraints.speed_down) ? _vehicle_constraints.speed_down :
|
||||
_param_mpc_z_vel_max_dn.get();
|
||||
const float speed_up = PX4_ISFINITE(_vehicle_constraints.speed_up) ? _vehicle_constraints.speed_up : _param_mpc_z_vel_max_up.get();
|
||||
const float speed_down = PX4_ISFINITE(_vehicle_constraints.speed_down) ? _vehicle_constraints.speed_down : _param_mpc_z_vel_max_dn.get();
|
||||
|
||||
// Allow ramping from zero thrust on takeoff
|
||||
const float minimum_thrust = flying ? _param_mpc_thr_min.get() : 0.f;
|
||||
@@ -539,10 +547,34 @@ void MulticopterPositionControl::Run()
|
||||
max_speed_xy = math::min(max_speed_xy, vehicle_local_position.vxy_max);
|
||||
}
|
||||
|
||||
_control.setVelocityLimits(
|
||||
max_speed_xy,
|
||||
math::min(speed_up, _param_mpc_z_vel_max_up.get()), // takeoff ramp starts with negative velocity limit
|
||||
math::max(speed_down, 0.f));
|
||||
float limit_speed_up = math::min(speed_up, _param_mpc_z_vel_max_up.get());
|
||||
float limit_speed_down = math::max(speed_down, 0.f);
|
||||
|
||||
// When changing mode flying faster than the limit, allow braking with a decaying limit to
|
||||
// avoid a large velocity error from clamping alone driving the integrator against the brake.
|
||||
// The limit starts at the measured speed, holds while the jerk limited braking builds up and then
|
||||
// ramps down open loop, so it doesn't interfere with the brake but is guaranteed to reach the configured limit.
|
||||
const auto decayingLimit = [&](float & ramp, float measured_speed, float limit) {
|
||||
if (PX4_ISFINITE(ramp)) {
|
||||
if (vehicle_local_position.timestamp_sample > _time_vel_limit_reset + 1_s) {
|
||||
ramp = math::max(ramp - 5.f * dt, 0.f);
|
||||
}
|
||||
|
||||
} else {
|
||||
ramp = PX4_ISFINITE(measured_speed) ? math::max(measured_speed, 0.f) : 0.f;
|
||||
}
|
||||
|
||||
return math::max(limit, ramp);
|
||||
};
|
||||
|
||||
const Vector2f velocity_xy(states.velocity);
|
||||
max_speed_xy = decayingLimit(_vel_limit_xy, velocity_xy.norm(), max_speed_xy);
|
||||
limit_speed_up = decayingLimit(_vel_limit_up, -states.velocity(2), limit_speed_up);
|
||||
limit_speed_down = decayingLimit(_vel_limit_down, states.velocity(2), limit_speed_down);
|
||||
|
||||
limit_speed_up = _takeoff.updateRamp(dt, limit_speed_up); // Takeoff ramp goes last to not be overridden
|
||||
|
||||
_control.setVelocityLimits(max_speed_xy, limit_speed_up, limit_speed_down);
|
||||
|
||||
_control.setInputSetpoint(_setpoint);
|
||||
|
||||
|
||||
@@ -116,6 +116,12 @@ private:
|
||||
hrt_abstime _time_stamp_last_loop{0}; /**< time stamp of last loop iteration */
|
||||
hrt_abstime _time_position_control_enabled{0};
|
||||
|
||||
// Velocity limits decaying from a speed higher than maximum after a control mode change to the configured maximum
|
||||
float _vel_limit_xy{NAN};
|
||||
float _vel_limit_up{NAN};
|
||||
float _vel_limit_down{NAN};
|
||||
hrt_abstime _time_vel_limit_reset{0};
|
||||
|
||||
trajectory_setpoint_s _setpoint{PositionControl::empty_trajectory_setpoint};
|
||||
trajectory_setpoint_s _last_valid_setpoint{PositionControl::empty_trajectory_setpoint};
|
||||
vehicle_control_mode_s _vehicle_control_mode{};
|
||||
|
||||
Reference in new issue
Block a user