@@ -70,8 +70,10 @@ bool FlightTaskAuto::activate(const trajectory_setpoint_s &last_setpoint)
70
70
71
71
_position_smoothing.reset (accel_prev, vel_prev, pos_prev);
72
72
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
+
75
77
_updateTrajConstraints ();
76
78
_is_emergency_braking_active = false ;
77
79
_time_last_cruise_speed_override = 0 ;
@@ -191,7 +193,7 @@ bool FlightTaskAuto::update()
191
193
// no valid heading -> generate heading in this flight task
192
194
// Generate heading along trajectory if possible, otherwise hold the previous yaw setpoint
193
195
if (!_generateHeadingAlongTraj ()) {
194
- _yaw_setpoint = _yaw ;
196
+ _yaw_setpoint = _yaw_setpoint_previous ;
195
197
}
196
198
}
197
199
@@ -256,7 +258,7 @@ void FlightTaskAuto::_prepareLandSetpoints()
256
258
257
259
if (sticks_xy.longerThan (FLT_EPSILON)) {
258
260
// Ensure no unintended yawing when nudging horizontally during initial heading alignment
259
- _land_heading = _yaw ;
261
+ _land_heading = _yaw_setpoint_previous ;
260
262
}
261
263
262
264
rcHelpModifyYaw (_land_heading);
@@ -302,19 +304,28 @@ void FlightTaskAuto::_prepareLandSetpoints()
302
304
void FlightTaskAuto::_smoothYaw ()
303
305
{
304
306
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 ()));
305
309
306
310
_yaw_sp_aligned = true ;
307
311
312
+ Vector2f (_yaw_setpoint, 0 .f ).print ();
313
+
308
314
if (PX4_ISFINITE (_yaw_setpoint)) {
315
+ const float yaw_sp_unsmoothed = _yaw_setpoint;
309
316
_heading_smoothing.update (_yaw_setpoint, _deltatime);
310
- float yaw_sp_prev = _yaw_setpoint;
311
317
_yaw_setpoint = _heading_smoothing.getSmoothedHeading ();
312
318
_yawspeed_setpoint = _heading_smoothing.getSmoothedHeadingRate ();
313
319
314
320
// 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 );
316
325
}
317
326
327
+ _yaw_setpoint_previous = _yaw_setpoint;
328
+
318
329
if (PX4_ISFINITE (_yawspeed_setpoint)) {
319
330
// The yaw setpoint is aligned when its rate is not saturated
320
331
_yaw_sp_aligned = _yaw_sp_aligned && (fabsf (_yawspeed_setpoint) < yawrate_max);
@@ -710,7 +721,7 @@ void FlightTaskAuto::_ekfResetHandlerVelocityZ(float delta_vz)
710
721
711
722
void FlightTaskAuto::_ekfResetHandlerHeading (float delta_psi)
712
723
{
713
- _yaw_setpoint += delta_psi;
724
+ _yaw_setpoint_previous += delta_psi;
714
725
}
715
726
716
727
void FlightTaskAuto::_checkEmergencyBraking ()
@@ -820,12 +831,6 @@ void FlightTaskAuto::_updateTrajConstraints()
820
831
// correction required by the altitude/vertical position controller
821
832
_constraints.speed_down = math::max (_constraints.speed_down , 1 .2f * _param_mpc_z_v_auto_dn.get ());;
822
833
_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);
829
834
}
830
835
831
836
bool FlightTaskAuto::_highEnoughForLandingGear ()
0 commit comments