mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-29 05:13:34 +08:00
reapply PR 18614 to refactored FlightTaskAuto
This commit is contained in:
committed by
Mathieu Bresciani
parent
cbd6e735ad
commit
9345f68a93
@@ -132,6 +132,14 @@ public:
|
|||||||
return {getCurrentAccelerationX(), getCurrentAccelerationY(), getCurrentAccelerationZ()};
|
return {getCurrentAccelerationX(), getCurrentAccelerationY(), getCurrentAccelerationZ()};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return float Current trajectory acceleration in X and Y
|
||||||
|
*/
|
||||||
|
inline Vector2f getCurrentAccelerationXY() const
|
||||||
|
{
|
||||||
|
return {getCurrentAccelerationX(), getCurrentAccelerationY()};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return float Current trajectory velocity in X
|
* @return float Current trajectory velocity in X
|
||||||
*/
|
*/
|
||||||
@@ -164,6 +172,14 @@ public:
|
|||||||
return {getCurrentVelocityX(), getCurrentVelocityY(), getCurrentVelocityZ()};
|
return {getCurrentVelocityX(), getCurrentVelocityY(), getCurrentVelocityZ()};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return float Current trajectory velocity in X and Y
|
||||||
|
*/
|
||||||
|
inline Vector2f getCurrentVelocityXY() const
|
||||||
|
{
|
||||||
|
return {getCurrentVelocityX(), getCurrentVelocityY()};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return float Current trajectory position in X
|
* @return float Current trajectory position in X
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -184,6 +184,7 @@ bool FlightTaskAuto::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bool should_wait_for_yaw_align = _param_mpc_yaw_mode.get() == 4 && !_yaw_sp_aligned;
|
const bool should_wait_for_yaw_align = _param_mpc_yaw_mode.get() == 4 && !_yaw_sp_aligned;
|
||||||
|
const bool force_zero_velocity_setpoint = should_wait_for_yaw_align || _is_emergency_braking_active;
|
||||||
_updateTrajConstraints();
|
_updateTrajConstraints();
|
||||||
PositionSmoothing::PositionSmoothingSetpoints smoothed_setpoints;
|
PositionSmoothing::PositionSmoothingSetpoints smoothed_setpoints;
|
||||||
_position_smoothing.generateSetpoints(
|
_position_smoothing.generateSetpoints(
|
||||||
@@ -191,7 +192,7 @@ bool FlightTaskAuto::update()
|
|||||||
waypoints,
|
waypoints,
|
||||||
_velocity_setpoint,
|
_velocity_setpoint,
|
||||||
_deltatime,
|
_deltatime,
|
||||||
should_wait_for_yaw_align,
|
force_zero_velocity_setpoint,
|
||||||
smoothed_setpoints
|
smoothed_setpoints
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -728,12 +729,23 @@ void FlightTaskAuto::_ekfResetHandlerHeading(float delta_psi)
|
|||||||
void FlightTaskAuto::_checkEmergencyBraking()
|
void FlightTaskAuto::_checkEmergencyBraking()
|
||||||
{
|
{
|
||||||
if (!_is_emergency_braking_active) {
|
if (!_is_emergency_braking_active) {
|
||||||
if (_position_smoothing.getCurrentVelocityZ() > (2.f * _param_mpc_z_vel_max_dn.get())) {
|
// activate emergency braking if significantly outside of velocity bounds
|
||||||
|
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_cruise.get());
|
||||||
|
|
||||||
|
if (is_vertical_speed_exceeded || is_horizontal_speed_exceeded) {
|
||||||
_is_emergency_braking_active = true;
|
_is_emergency_braking_active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (fabsf(_position_smoothing.getCurrentVelocityZ()) < 0.01f) {
|
// deactivate emergency braking when the vehicle has come to a full stop
|
||||||
|
if (_position_smoothing.getCurrentVelocityZ() < 0.01f
|
||||||
|
&& _position_smoothing.getCurrentVelocityZ() > -0.01f
|
||||||
|
&& !_position_smoothing.getCurrentVelocityXY().longerThan(0.01f)) {
|
||||||
_is_emergency_braking_active = false;
|
_is_emergency_braking_active = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -781,15 +793,16 @@ void FlightTaskAuto::_updateTrajConstraints()
|
|||||||
_position_smoothing.setMaxJerk({max_jerk, max_jerk, max_jerk}); // TODO : Should be computed using heading
|
_position_smoothing.setMaxJerk({max_jerk, max_jerk, max_jerk}); // TODO : Should be computed using heading
|
||||||
|
|
||||||
if (_is_emergency_braking_active) {
|
if (_is_emergency_braking_active) {
|
||||||
// When initializing with large downward velocity, allow 1g of vertical
|
// When initializing with large velocity, allow 1g of
|
||||||
// acceleration for fast braking
|
// acceleration in 1s on all axes for fast braking
|
||||||
_position_smoothing.setMaxAccelerationZ(9.81f);
|
_position_smoothing.setMaxAcceleration({9.81f, 9.81f, 9.81f});
|
||||||
_position_smoothing.setMaxJerkZ(9.81f);
|
_position_smoothing.setMaxJerk({9.81f, 9.81f, 9.81f});
|
||||||
|
|
||||||
// If the current velocity is beyond the usual constraints, tell
|
// If the current velocity is beyond the usual constraints, tell
|
||||||
// the controller to exceptionally increase its saturations to avoid
|
// the controller to exceptionally increase its saturations to avoid
|
||||||
// cutting out the feedforward
|
// cutting out the feedforward
|
||||||
_constraints.speed_down = math::max(fabsf(_position_smoothing.getCurrentVelocityZ()), _param_mpc_z_vel_max_dn.get());
|
_constraints.speed_down = math::max(fabsf(_position_smoothing.getCurrentVelocityZ()), _param_mpc_z_vel_max_dn.get());
|
||||||
|
_constraints.speed_up = math::max(fabsf(_position_smoothing.getCurrentVelocityZ()), _param_mpc_z_vel_max_up.get());
|
||||||
|
|
||||||
} else if (_unsmoothed_velocity_setpoint(2) < 0.f) { // up
|
} else if (_unsmoothed_velocity_setpoint(2) < 0.f) { // up
|
||||||
float z_accel_constraint = _param_mpc_acc_up_max.get();
|
float z_accel_constraint = _param_mpc_acc_up_max.get();
|
||||||
|
|||||||
Reference in New Issue
Block a user