From c726623da2059445e689e051e219d85676c55191 Mon Sep 17 00:00:00 2001 From: Vishal Kotak Date: Tue, 24 Nov 2026 00:32:43 -0800 Subject: [PATCH 1/2] fix(commander): check the mapped rover sticks before arming (#29899) * fix(commander): check the mapped rover sticks before arming Since rovers map their sticks with RO_STICK_MAP, the throttle stick is no longer always the one that drives them. With RO_STICK_MAP=2 commander still checked the left vertical stick, so a rover could be armed with the right stick pushed fully forward. Run the sticks through the rover stick mapping and deny arming when the forward stick, or the lateral stick on a mecanum rover, is off center. Assisted-by: Claude:claude-opus-5-5 * fix(commander): check the rover's tank sticks in manual parking Manual parking on differential and mecanum rovers drives the left and right wheels with the vertical sticks and ignores RO_STICK_MAP, so the mapped check could still let the rover arm with a wheel stick pushed. Assisted-by: Claude:claude-opus-5-5 * style(rover): wrap the sticksCommandMotion signature for astyle Assisted-by: Claude:claude-opus-5-5 * fix(commander): check each tank stick on its own in manual parking In manual parking each vertical stick drives one side of wheels, so averaging them let a rover arm while turning on the spot or with one stick partly pushed. Assisted-by: Claude:claude-opus-5-5 * refactor(rover): rename tank_sticks to tank_style_sticks Review feedback. Assisted-by: Claude:claude-opus-5-5 --------- Co-authored-by: Vishal Kotak <22182951+vishalkotak@users.noreply.github.com> --- src/lib/rover_control/RoverControl.cpp | 16 ++ src/lib/rover_control/RoverControl.hpp | 12 ++ src/lib/rover_control/RoverControlTest.cpp | 172 +++++++++++++++++++++ src/modules/commander/CMakeLists.txt | 1 + src/modules/commander/Commander.cpp | 26 +++- src/modules/commander/Commander.hpp | 3 + 6 files changed, 228 insertions(+), 2 deletions(-) diff --git a/src/lib/rover_control/RoverControl.cpp b/src/lib/rover_control/RoverControl.cpp index 063eeef19a1..b75c64c302f 100644 --- a/src/lib/rover_control/RoverControl.cpp +++ b/src/lib/rover_control/RoverControl.cpp @@ -64,6 +64,22 @@ ManualSticks mapSticks(const manual_control_setpoint_s &manual_control_setpoint, } } +bool sticksCommandMotion(const manual_control_setpoint_s &manual_control_setpoint, int32_t stick_map, bool can_drive_sideways, + bool tank_style_sticks) +{ + const float arming_stick_threshold = 0.2f; + const ManualSticks sticks = mapSticks(manual_control_setpoint, stick_map); + const bool lateral = can_drive_sideways && fabsf(sticks.lateral) >= arming_stick_threshold; + + if (tank_style_sticks) { + const float left = manual_control_setpoint.throttle; + const float right = manual_control_setpoint.pitch; + return fabsf(left) >= arming_stick_threshold || fabsf(right) >= arming_stick_threshold || lateral; + } + + return fabsf(sticks.forward) >= arming_stick_threshold || lateral; +} + float throttleControl(SlewRate &motor_setpoint, const float throttle_setpoint, const float current_motor_setpoint, const float max_accel, const float max_decel, const float max_thr_spd, const float dt) diff --git a/src/lib/rover_control/RoverControl.hpp b/src/lib/rover_control/RoverControl.hpp index 435863126cb..c2e9095a0c3 100644 --- a/src/lib/rover_control/RoverControl.hpp +++ b/src/lib/rover_control/RoverControl.hpp @@ -81,6 +81,18 @@ enum class StickMapping : int32_t { */ ManualSticks mapSticks(const manual_control_setpoint_s &manual_control_setpoint, int32_t stick_map); +/** + * Checks whether the sticks command the rover to drive, used to deny arming with sticks off center. + * @param manual_control_setpoint Stick inputs + * @param stick_map Selected mapping (RO_STICK_MAP), unknown values use StickMapping::Mode3 + * @param can_drive_sideways True for rovers that use the lateral stick (mecanum) + * @param tank_style_sticks True in manual parking on differential and mecanum rovers, where the left and right + * vertical sticks drive the left and right wheels instead of the stick mapping + * @return True if a stick that drives the wheels is deflected by 0.2 or more + */ +bool sticksCommandMotion(const manual_control_setpoint_s &manual_control_setpoint, int32_t stick_map, bool can_drive_sideways, + bool tank_style_sticks); + /** * Applies acceleration/deceleration slew rate to a throttle setpoint. * @param motor_setpoint Throttle setpoint with applied slew rate [-1, 1] (Updated by this function) diff --git a/src/lib/rover_control/RoverControlTest.cpp b/src/lib/rover_control/RoverControlTest.cpp index 3d86a2aef4e..af8322d2d39 100644 --- a/src/lib/rover_control/RoverControlTest.cpp +++ b/src/lib/rover_control/RoverControlTest.cpp @@ -1223,3 +1223,175 @@ TEST(speedControl, signChangeReverseWithoutDecelerationLimit) // THEN: the acceleration limit applies as before EXPECT_NEAR(adjusted_speed, 1.f - kSignChangeMaxAccel * kDt, 1e-6f); } + +static constexpr int32_t kStickMapMode2 = static_cast(RoverControl::StickMapping::Mode2); +static constexpr bool kCanDriveSideways = true; // Mecanum, so the lateral stick is checked too + +TEST(sticksCommandMotion, centeredSticks) +{ + // GIVEN: all sticks centered + manual_control_setpoint_s manual_control_setpoint{}; + + // WHEN: checked with stick mapping mode 2 (left: yaw, right: forward & lateral) + const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, kCanDriveSideways, false); + + // THEN: no motion is commanded + EXPECT_FALSE(commands_motion); +} + +TEST(sticksCommandMotion, forwardOnRightStick) +{ + // GIVEN: the right stick pushed fully forward, with the left vertical stick centered + manual_control_setpoint_s manual_control_setpoint{}; + manual_control_setpoint.pitch = 1.f; + + // WHEN: checked with stick mapping mode 2, where the right vertical stick drives forward + const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, kCanDriveSideways, false); + + // THEN: motion is commanded + EXPECT_TRUE(commands_motion); +} + +TEST(sticksCommandMotion, backwardOnRightStick) +{ + // GIVEN: the right stick pulled fully back + manual_control_setpoint_s manual_control_setpoint{}; + manual_control_setpoint.pitch = -1.f; + + // WHEN: checked with stick mapping mode 2 + const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, kCanDriveSideways, false); + + // THEN: motion is commanded + EXPECT_TRUE(commands_motion); +} + +TEST(sticksCommandMotion, lateralOnRightStick) +{ + // GIVEN: the right stick pushed fully to the side + manual_control_setpoint_s manual_control_setpoint{}; + manual_control_setpoint.roll = 1.f; + + // WHEN: checked with stick mapping mode 2, where the right horizontal stick drives sideways + const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, kCanDriveSideways, false); + + // THEN: motion is commanded + EXPECT_TRUE(commands_motion); +} + +TEST(sticksCommandMotion, lateralOnRoverThatCannotDriveSideways) +{ + // GIVEN: the right stick pushed fully to the side + manual_control_setpoint_s manual_control_setpoint{}; + manual_control_setpoint.roll = 1.f; + + // WHEN: checked for a rover that doesn't use the lateral stick (differential, Ackermann) + const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, false, false); + + // THEN: no motion is commanded + EXPECT_FALSE(commands_motion); +} + +TEST(sticksCommandMotion, unusedLeftVerticalStick) +{ + // GIVEN: the left vertical stick pushed fully forward, which is the stick commander checked before + manual_control_setpoint_s manual_control_setpoint{}; + manual_control_setpoint.throttle = 1.f; + + // WHEN: checked with stick mapping mode 2, where the left vertical stick is not used + const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, kCanDriveSideways, false); + + // THEN: no motion is commanded + EXPECT_FALSE(commands_motion); +} + +TEST(sticksCommandMotion, yawOnly) +{ + // GIVEN: the left stick pushed fully to the side + manual_control_setpoint_s manual_control_setpoint{}; + manual_control_setpoint.yaw = 1.f; + + // WHEN: checked with stick mapping mode 2, where the left horizontal stick turns the rover + const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, kCanDriveSideways, false); + + // THEN: turning alone does not count as motion + EXPECT_FALSE(commands_motion); +} + +TEST(sticksCommandMotion, belowThreshold) +{ + // GIVEN: the forward stick deflected just below the 0.2 threshold + manual_control_setpoint_s manual_control_setpoint{}; + manual_control_setpoint.pitch = 0.19f; + + // WHEN: checked with stick mapping mode 2 + const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, kCanDriveSideways, false); + + // THEN: no motion is commanded + EXPECT_FALSE(commands_motion); +} + +TEST(sticksCommandMotion, atThreshold) +{ + // GIVEN: the forward stick deflected exactly to the 0.2 threshold + manual_control_setpoint_s manual_control_setpoint{}; + manual_control_setpoint.pitch = 0.2f; + + // WHEN: checked with stick mapping mode 2 + const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, kCanDriveSideways, false); + + // THEN: motion is commanded, matching the previous throttle check that only allowed arming below 0.2 + EXPECT_TRUE(commands_motion); +} + +TEST(sticksCommandMotion, parkingLeftStickForward) +{ + // GIVEN: the left stick pushed fully forward + manual_control_setpoint_s manual_control_setpoint{}; + manual_control_setpoint.throttle = 1.f; + + // WHEN: checked in manual parking, where the left vertical stick drives the left wheels whatever the stick mapping + const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, false, true); + + // THEN: motion is commanded + EXPECT_TRUE(commands_motion); +} + +TEST(sticksCommandMotion, parkingRightStickForward) +{ + // GIVEN: the right stick pushed fully forward + manual_control_setpoint_s manual_control_setpoint{}; + manual_control_setpoint.pitch = 1.f; + + // WHEN: checked in manual parking, where the right vertical stick drives the right wheels + const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, false, true); + + // THEN: motion is commanded + EXPECT_TRUE(commands_motion); +} + +TEST(sticksCommandMotion, parkingTurnOnTheSpot) +{ + // GIVEN: the left stick pushed fully forward and the right stick pulled fully back + manual_control_setpoint_s manual_control_setpoint{}; + manual_control_setpoint.throttle = 1.f; + manual_control_setpoint.pitch = -1.f; + + // WHEN: checked in manual parking, where this turns the rover on the spot + const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, false, true); + + // THEN: motion is commanded, since both sides of wheels are driven + EXPECT_TRUE(commands_motion); +} + +TEST(sticksCommandMotion, parkingOneStickPartly) +{ + // GIVEN: the left stick pushed to 0.3 and the right stick centered + manual_control_setpoint_s manual_control_setpoint{}; + manual_control_setpoint.throttle = 0.3f; + + // WHEN: checked in manual parking + const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, false, true); + + // THEN: motion is commanded, since the left wheels are driven + EXPECT_TRUE(commands_motion); +} diff --git a/src/modules/commander/CMakeLists.txt b/src/modules/commander/CMakeLists.txt index 2aabe2b6129..15b1d405076 100644 --- a/src/modules/commander/CMakeLists.txt +++ b/src/modules/commander/CMakeLists.txt @@ -83,6 +83,7 @@ px4_add_module( hysteresis mode_util MulticopterThrowLaunch + rover_control sensor_calibration world_magnetic_model atmosphere diff --git a/src/modules/commander/Commander.cpp b/src/modules/commander/Commander.cpp index 2b4a97257dc..a445993141e 100644 --- a/src/modules/commander/Commander.cpp +++ b/src/modules/commander/Commander.cpp @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -696,8 +697,26 @@ transition_result_t Commander::arm(arm_disarm_reason_t calling_reason, bool run_ bool throttle_safe; if (_vehicle_status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROVER) { - // Rovers: center stick = stop, safe to arm near center - throttle_safe = (fabsf(_last_manual_throttle) < 0.2f); + // Rovers: centered sticks = stop. RO_STICK_MAP decides which sticks drive forward and sideways, + // it only exists if a rover module is built, otherwise the default mapping is used. + int32_t stick_map = 0; + + if (_param_ro_stick_map != PARAM_INVALID) { + param_get(_param_ro_stick_map, &stick_map); + } + + // CA_AIRFRAME: 6 = differential rover, 13 = mecanum rover. Only mecanum rovers use the lateral stick. + // In manual parking both drive the left and right wheels with the vertical sticks, not RO_STICK_MAP. + int32_t airframe = 0; + + if (_param_ca_airframe != PARAM_INVALID) { + param_get(_param_ca_airframe, &airframe); + } + + const bool can_drive_sideways = (airframe == 13); + const bool manual_parking = (_vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_MANUAL_PARKING); + const bool tank_style_sticks = manual_parking && (airframe == 6 || airframe == 13); + throttle_safe = !RoverControl::sticksCommandMotion(_last_manual_control_setpoint, stick_map, can_drive_sideways, tank_style_sticks); } else if (_vehicle_control_mode.flag_control_climb_rate_enabled) { // Climb-rate modes (AltCtl, PosCtl, etc.): center = hover, safe at or below center @@ -834,6 +853,8 @@ Commander::Commander() : param_t param_mav_sys_id = param_find("MAV_SYS_ID"); _param_mav_type = param_find("MAV_TYPE"); _param_rc_map_fltmode = param_find("RC_MAP_FLTMODE"); + _param_ro_stick_map = param_find("RO_STICK_MAP"); + _param_ca_airframe = param_find("CA_AIRFRAME"); int32_t value_int32 = 0; @@ -3184,6 +3205,7 @@ void Commander::manualControlCheck() if (manual_control_updated && manual_control_setpoint.valid) { _last_manual_throttle = manual_control_setpoint.throttle; + _last_manual_control_setpoint = manual_control_setpoint; if (isArmed()) { // Hand control back to the pilot when they override with the sticks (see MAN_OVERRIDE_SPD). diff --git a/src/modules/commander/Commander.hpp b/src/modules/commander/Commander.hpp index 3ec1cfb2fd4..2d04f743386 100644 --- a/src/modules/commander/Commander.hpp +++ b/src/modules/commander/Commander.hpp @@ -285,6 +285,7 @@ private: bool _mode_switch_mapped{false}; float _last_manual_throttle{-1.f}; + manual_control_setpoint_s _last_manual_control_setpoint{}; bool _manual_control_lost_prev{false}; ///< previous manual_control_signal_lost state, for edge detection bool _arm_tune_played{false}; @@ -339,6 +340,8 @@ private: // optional parameters param_t _param_mav_type{PARAM_INVALID}; param_t _param_rc_map_fltmode{PARAM_INVALID}; + param_t _param_ro_stick_map{PARAM_INVALID}; + param_t _param_ca_airframe{PARAM_INVALID}; DEFINE_PARAMETERS( (ParamFloat) _param_com_disarm_land, From d090301e480480ceb128280a21f2727091466db2 Mon Sep 17 00:00:00 2001 From: Mahima Yoga Date: Tue, 24 Nov 2026 12:15:45 +0100 Subject: [PATCH 2/2] fix(FwModeManager): use terrain altitude in tip-strike logic during landing (#29952) --- src/modules/fw_mode_manager/FixedWingModeManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/fw_mode_manager/FixedWingModeManager.cpp b/src/modules/fw_mode_manager/FixedWingModeManager.cpp index 81dcbc4aab1..851142ac3c5 100644 --- a/src/modules/fw_mode_manager/FixedWingModeManager.cpp +++ b/src/modules/fw_mode_manager/FixedWingModeManager.cpp @@ -1615,7 +1615,7 @@ FixedWingModeManager::control_auto_landing_straight(const hrt_abstime &now, cons fw_lateral_ctrl_sp.lateral_acceleration = sp.lateral_acceleration_feedforward; _lateral_ctrl_sp_pub.publish(fw_lateral_ctrl_sp); - const float roll_wingtip_strike = getMaxRollAngleNearGround(_current_altitude, _takeoff_ground_alt); + const float roll_wingtip_strike = getMaxRollAngleNearGround(_current_altitude, terrain_alt); _ctrl_configuration_handler.setLateralAccelMax(rollAngleToLateralAccel(roll_wingtip_strike)); /* longitudinal guidance */