fix(mc_att_control): gate the yaw rate command during the arming gesture

This prevents the yawspeed filter from accumulating a large value during
stick gesture arming
This commit is contained in:
bresch authored and Matthias Grob committed 2026-09-29 10:36:45 +02:00
1 parent d6817b8fdf
commit 19ed79efa1
4 files changed
+42 -2

No files matched your search

+1 -1
View File
@@ -44,7 +44,7 @@ StickYaw::StickYaw(ModuleParams *parent) :
void StickYaw::reset(const float yaw, const float unaided_yaw)
{
// The filter state outlives deactivation; a reset means there is no stick history to carry over.
_yawspeed_filter.reset(0.f);
resetYawspeed();
if (PX4_ISFINITE(unaided_yaw)) {
_yaw_error_lpf.reset(wrap_pi(yaw - unaided_yaw));
+2
View File
@@ -52,6 +52,8 @@ public:
~StickYaw() = default;
void reset(float yaw, float unaided_yaw = NAN);
void resetYawspeed() { _yawspeed_filter.reset(0.f); }
void ekfResetHandler(float delta_yaw);
void generateYawSetpoint(float &yawspeed_setpoint, float &yaw_setpoint, float stick_yaw, float yaw, float deltatime,
float unaided_yaw = NAN);
+35
View File
@@ -60,6 +60,41 @@ TEST(StickYawTest, ResetClearsYawspeedFilter)
EXPECT_EQ(yawspeed_sp, 0.f);
}
TEST(StickYawTest, ResetYawspeedClearsChargeButKeepsHeadingLock)
{
// Gating the yaw rate during the arming gesture needs the command at zero immediately and the
// heading lock intact.
param_control_autosave(false);
StickYaw stick_yaw{nullptr};
float yawspeed_sp = 0.f;
float yaw_sp = NAN;
const float dt = 0.01f;
// GIVEN: a heading locked at 0 and the yawspeed filter charged by a full-deflection stick
stick_yaw.reset(0.f, 0.f);
for (int i = 0; i < 500; i++) {
stick_yaw.generateYawSetpoint(yawspeed_sp, yaw_sp, 1.f, 0.f, dt, 0.f);
}
EXPECT_GT(yawspeed_sp, 0.1f);
// WHEN: the gesture gate clears the charge and holds the stick input at zero
for (int i = 0; i < 5; i++) {
stick_yaw.resetYawspeed();
stick_yaw.generateYawSetpoint(yawspeed_sp, yaw_sp, 0.f, 0.f, dt, 0.f);
EXPECT_EQ(yawspeed_sp, 0.f);
}
// THEN: releasing the gate with the stick centred does not release a charge either
stick_yaw.generateYawSetpoint(yawspeed_sp, yaw_sp, 0.f, 0.f, dt, 0.f);
EXPECT_EQ(yawspeed_sp, 0.f);
// AND: the heading re-locks at the current yaw
EXPECT_TRUE(PX4_ISFINITE(yaw_sp));
}
TEST(StickYawTest, UnaidedYawNanTransitionNoYawJump)
{
// When unaided_yaw transitions from finite to NAN mid-flight,
@@ -151,10 +151,13 @@ MulticopterAttitudeControl::generate_attitude_setpoint(const Quatf &q, float dt)
if (arming_gesture) {
_yaw_setpoint_stabilized = NAN;
_stick_yaw.resetYawspeed();
}
const float yaw = Eulerf(q).psi();
const float yaw_stick_input = Sticks::expoDeadzone(_manual_control_setpoint.yaw, .6f, _param_man_deadzone.get());
const float yaw_stick_input = arming_gesture
? 0.f
: Sticks::expoDeadzone(_manual_control_setpoint.yaw, .6f, _param_man_deadzone.get());
_stick_yaw.generateYawSetpoint(attitude_setpoint.yaw_sp_move_rate, _yaw_setpoint_stabilized, yaw_stick_input, yaw, dt,
_unaided_heading);