Skip to content

Commit cd85bc0

Browse files
committed
FlightTaskAuto: Smooth yaw follow-up, bring back necessary previous yaw setpoint and reset smoothing when yaw is not locked
1 parent 49e1e63 commit cd85bc0

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/modules/flight_mode_manager/tasks/Auto/FlightTaskAuto.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ bool FlightTaskAuto::activate(const trajectory_setpoint_s &last_setpoint)
7070

7171
_position_smoothing.reset(accel_prev, vel_prev, pos_prev);
7272

73-
const float heading = PX4_ISFINITE(last_setpoint.yaw) ? last_setpoint.yaw : _yaw;
74-
_heading_smoothing.reset(heading, 0.f);
73+
_yaw_setpoint_previous = last_setpoint.yaw;
74+
_heading_smoothing.reset(PX4_ISFINITE(last_setpoint.yaw) ? last_setpoint.yaw : _yaw,
75+
PX4_ISFINITE(last_setpoint.yawspeed) ? last_setpoint.yawspeed : 0.f);
76+
7577
_updateTrajConstraints();
7678
_is_emergency_braking_active = false;
7779
_time_last_cruise_speed_override = 0;
@@ -191,7 +193,7 @@ bool FlightTaskAuto::update()
191193
// no valid heading -> generate heading in this flight task
192194
// Generate heading along trajectory if possible, otherwise hold the previous yaw setpoint
193195
if (!_generateHeadingAlongTraj()) {
194-
_yaw_setpoint = _yaw;
196+
_yaw_setpoint = _yaw_setpoint_previous;
195197
}
196198
}
197199

@@ -256,7 +258,7 @@ void FlightTaskAuto::_prepareLandSetpoints()
256258

257259
if (sticks_xy.longerThan(FLT_EPSILON)) {
258260
// Ensure no unintended yawing when nudging horizontally during initial heading alignment
259-
_land_heading = _yaw;
261+
_land_heading = _yaw_setpoint_previous;
260262
}
261263

262264
rcHelpModifyYaw(_land_heading);
@@ -302,19 +304,28 @@ void FlightTaskAuto::_prepareLandSetpoints()
302304
void FlightTaskAuto::_smoothYaw()
303305
{
304306
const float yawrate_max = math::radians(_param_mpc_yawrauto_max.get());
307+
_heading_smoothing.setMaxHeadingRate(yawrate_max);
308+
_heading_smoothing.setMaxHeadingAccel(math::radians(_param_mpc_yawrauto_acc.get()));
305309

306310
_yaw_sp_aligned = true;
307311

312+
Vector2f(_yaw_setpoint, 0.f).print();
313+
308314
if (PX4_ISFINITE(_yaw_setpoint)) {
315+
const float yaw_sp_unsmoothed = _yaw_setpoint;
309316
_heading_smoothing.update(_yaw_setpoint, _deltatime);
310-
float yaw_sp_prev = _yaw_setpoint;
311317
_yaw_setpoint = _heading_smoothing.getSmoothedHeading();
312318
_yawspeed_setpoint = _heading_smoothing.getSmoothedHeadingRate();
313319

314320
// The yaw setpoint is aligned when it is within tolerance
315-
_yaw_sp_aligned = fabsf(matrix::wrap_pi(yaw_sp_prev - _yaw_setpoint)) < math::radians(_param_mis_yaw_err.get());
321+
_yaw_sp_aligned = fabsf(matrix::wrap_pi(yaw_sp_unsmoothed - _yaw_setpoint)) < math::radians(_param_mis_yaw_err.get());
322+
323+
} else {
324+
_heading_smoothing.reset(_yaw, 0.f);
316325
}
317326

327+
_yaw_setpoint_previous = _yaw_setpoint;
328+
318329
if (PX4_ISFINITE(_yawspeed_setpoint)) {
319330
// The yaw setpoint is aligned when its rate is not saturated
320331
_yaw_sp_aligned = _yaw_sp_aligned && (fabsf(_yawspeed_setpoint) < yawrate_max);
@@ -710,7 +721,7 @@ void FlightTaskAuto::_ekfResetHandlerVelocityZ(float delta_vz)
710721

711722
void FlightTaskAuto::_ekfResetHandlerHeading(float delta_psi)
712723
{
713-
_yaw_setpoint += delta_psi;
724+
_yaw_setpoint_previous += delta_psi;
714725
}
715726

716727
void FlightTaskAuto::_checkEmergencyBraking()
@@ -820,12 +831,6 @@ void FlightTaskAuto::_updateTrajConstraints()
820831
// correction required by the altitude/vertical position controller
821832
_constraints.speed_down = math::max(_constraints.speed_down, 1.2f * _param_mpc_z_v_auto_dn.get());;
822833
_constraints.speed_up = math::max(_constraints.speed_up, 1.2f * _param_mpc_z_v_auto_up.get());;
823-
824-
// Update constrains of heading smoothing
825-
const float yawrate_max = math::radians(_param_mpc_yawrauto_max.get());
826-
const float yawrate_acc = math::radians(_param_mpc_yawrauto_acc.get());
827-
_heading_smoothing.setMaxHeadingRate(yawrate_max);
828-
_heading_smoothing.setMaxHeadingAccel(yawrate_acc);
829834
}
830835

831836
bool FlightTaskAuto::_highEnoughForLandingGear()

src/modules/flight_mode_manager/tasks/Auto/FlightTaskAuto.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@
4747
#include <uORB/topics/vehicle_status.h>
4848
#include <lib/geo/geo.h>
4949
#include <lib/mathlib/math/filter/AlphaFilter.hpp>
50+
#include <lib/motion_planning/HeadingSmoothing.hpp>
5051
#include <lib/motion_planning/PositionSmoothing.hpp>
5152
#include <lib/stick_yaw/StickYaw.hpp>
5253
#include <lib/weather_vane/WeatherVane.hpp>
5354
#include "Sticks.hpp"
5455
#include "StickAccelerationXY.hpp"
55-
#include "HeadingSmoothing.hpp"
5656

5757
/**
5858
* This enum has to agree with position_setpoint_s type definition
@@ -137,6 +137,7 @@ class FlightTaskAuto : public FlightTask
137137
State _current_state{State::none};
138138
float _target_acceptance_radius{0.0f}; /**< Acceptances radius of the target */
139139

140+
float _yaw_setpoint_previous{NAN}; /**< Used because _yaw_setpoint is overwritten in multiple places */
140141
HeadingSmoothing _heading_smoothing;
141142
bool _yaw_sp_aligned{false};
142143

0 commit comments

Comments
 (0)