mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-25 16:51:16 +08:00
fix(commander): introduce a mode_not_supported flag to route rovers to Stabilized mode on position loss (#28696)
* Refactor rover failsafe: Replace Parked mode with mode_req_not_possible flag * Rename unsupported flag and restrict from ground station UI * Complete global rename of mode_not_supported flag * Apply PX4 CI code formatting * Apply PX4 CI code formatting for ui.hpp * Restrict VTOL/Descend on rovers and reroute fallback to disarm * docs(rover): add failsafe fallback cascade to manual modes * fix(failsafe): update rover fallback docs, honor COM_POS_FS_ACT, and add unit test * style: fix indentation for CI * docs: move rover failsafe sequence to end of page and format * docs(rover): move failsafe fallback sequence to drive modes overview The fallback cascade applies across rover drive modes rather than to Manual mode specifically, so it belongs on the parent overview page. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Hamish Willee <hamishwillee@gmail.com> --------- Signed-off-by: Hamish Willee <hamishwillee@gmail.com> Co-authored-by: Hamish Willee <hamishwillee@gmail.com>
This commit is contained in:
1 parent
49b856b500
commit
d57419e2c8
10 files changed
+110
-30
No files matched your search
@@ -26,3 +26,14 @@ Selecting any other mode than those listed below will either stop the rover or c
|
||||
| ------------------------------- | ----------------------------------------------------------------------- |
|
||||
| [Mission](auto.md#mission-mode) | Automatic mode that causes the vehicle to execute a predefined mission. |
|
||||
| [Return](auto.md#return-mode) | Automatic mode that returns the vehicle to the launch position. |
|
||||
|
||||
## Failsafe Fallback Sequence
|
||||
|
||||
If a rover loses navigation while in an autonomous or semi-autonomous mode that relies on it, such as losing GNSS while in **Position** mode, PX4 will fall back to the mode that maintains the most control given the (remaining) available sensor information.
|
||||
|
||||
The failure cascade sequence with a manual controller available is: **Position -> Stabilized -> Acro -> Manual**
|
||||
|
||||
If manual control input is not available, the fallback cascade continues to: **Hold -> RTL -> Disarm**
|
||||
|
||||
Note that rovers will not use unsupported multicopter modes, such as Altitude or Descend.
|
||||
If the failsafe system attempts to force the rover into an unsupported `Descend` state, the rover will safely bypass termination and automatically fall back to the action defined by the `COM_POS_FS_ACT` parameter.
|
||||
@@ -20,7 +20,7 @@ uint32 mode_req_wind_and_flight_time_compliance # if set, mode cannot be entered
|
||||
uint32 mode_req_prevent_arming # if set, cannot arm while in this mode
|
||||
uint32 mode_req_manual_control
|
||||
uint32 mode_req_other # other requirements, not covered above (for external modes)
|
||||
|
||||
uint32 mode_not_supported # if set, mode is not supported by the current vehicle architecture
|
||||
|
||||
# Mode requirements
|
||||
bool angular_velocity_invalid # Angular velocity invalid
|
||||
|
||||
+22
-22
@@ -43,29 +43,29 @@ namespace mode_util
|
||||
/**
|
||||
* @return Bitmask with all valid modes
|
||||
*/
|
||||
static inline uint32_t getValidNavStates()
|
||||
static inline uint32_t getValidNavStates(uint32_t mode_not_supported = 0)
|
||||
{
|
||||
return (1u << vehicle_status_s::NAVIGATION_STATE_MANUAL) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_ALTCTL) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_ALTITUDE_CRUISE) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_MANUAL_PARKING) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_POSCTL) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_AUTO_MISSION) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_AUTO_LOITER) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_GUIDED_COURSE) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_AUTO_RTL) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_POSITION_SLOW) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_ACRO) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_TERMINATION) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_OFFBOARD) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_STAB) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_AUTO_TAKEOFF) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_AUTO_LAND) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_DESCEND) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_AUTO_FOLLOW_TARGET) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_AUTO_PRECLAND) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_ORBIT) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_AUTO_VTOL_TAKEOFF);
|
||||
return ((1u << vehicle_status_s::NAVIGATION_STATE_MANUAL) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_ALTCTL) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_ALTITUDE_CRUISE) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_MANUAL_PARKING) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_POSCTL) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_AUTO_MISSION) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_AUTO_LOITER) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_GUIDED_COURSE) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_AUTO_RTL) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_POSITION_SLOW) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_ACRO) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_TERMINATION) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_OFFBOARD) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_STAB) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_AUTO_TAKEOFF) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_AUTO_LAND) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_DESCEND) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_AUTO_FOLLOW_TARGET) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_AUTO_PRECLAND) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_ORBIT) |
|
||||
(1u << vehicle_status_s::NAVIGATION_STATE_AUTO_VTOL_TAKEOFF)) & ~mode_not_supported;
|
||||
|
||||
static_assert(vehicle_status_s::NAVIGATION_STATE_MAX == 31, "update valid nav states");
|
||||
}
|
||||
|
||||
@@ -2164,7 +2164,7 @@ void Commander::run()
|
||||
updateControlMode();
|
||||
|
||||
// vehicle_status publish (after prearm/preflight updates above)
|
||||
_mode_management.getModeStatus(_vehicle_status.valid_nav_states_mask, _vehicle_status.can_set_nav_states_mask);
|
||||
_mode_management.getModeStatus(_vehicle_status.valid_nav_states_mask, _vehicle_status.can_set_nav_states_mask, _failsafe_flags);
|
||||
_vehicle_status.accepts_offboard_setpoints = _mode_management.currentModeAcceptsOffboardSetpoints(_vehicle_status.nav_state);
|
||||
_vehicle_status.timestamp = hrt_absolute_time();
|
||||
_vehicle_status_pub.publish(_vehicle_status);
|
||||
|
||||
@@ -178,6 +178,17 @@ void ModeChecks::checkAndReport(const Context &context, Report &reporter)
|
||||
reporter.clearCanRunBits((NavModes)reporter.failsafeFlags().mode_req_manual_control);
|
||||
}
|
||||
|
||||
if (reporter.failsafeFlags().mode_not_supported != 0) {
|
||||
/* EVENT
|
||||
* @description
|
||||
* The selected mode is not supported by the vehicle type.
|
||||
*/
|
||||
reporter.armingCheckFailure((NavModes)reporter.failsafeFlags().mode_not_supported, health_component_t::system,
|
||||
events::ID("check_modes_not_supported"),
|
||||
events::Log::Error, "Mode not supported");
|
||||
reporter.clearCanRunBits((NavModes)reporter.failsafeFlags().mode_not_supported);
|
||||
}
|
||||
|
||||
if (reporter.failsafeFlags().mode_req_other != 0) {
|
||||
// Here we expect there is already an event reported for the failing check (this is for external modes)
|
||||
reporter.clearCanRunBits((NavModes)reporter.failsafeFlags().mode_req_other);
|
||||
|
||||
@@ -736,9 +736,10 @@ void ModeManagement::checkConfigOverrides()
|
||||
}
|
||||
}
|
||||
|
||||
void ModeManagement::getModeStatus(uint32_t &valid_nav_state_mask, uint32_t &can_set_nav_state_mask) const
|
||||
void ModeManagement::getModeStatus(uint32_t &valid_nav_state_mask, uint32_t &can_set_nav_state_mask,
|
||||
const failsafe_flags_s &failsafe_flags) const
|
||||
{
|
||||
valid_nav_state_mask = mode_util::getValidNavStates();
|
||||
valid_nav_state_mask = mode_util::getValidNavStates(failsafe_flags.mode_not_supported);
|
||||
can_set_nav_state_mask = valid_nav_state_mask
|
||||
& ~((1u << vehicle_status_s::NAVIGATION_STATE_TERMINATION)
|
||||
| (1u << vehicle_status_s::NAVIGATION_STATE_DESCEND));
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include <uORB/topics/vehicle_status.h>
|
||||
#include <uORB/topics/vehicle_control_mode.h>
|
||||
#include <uORB/topics/config_overrides.h>
|
||||
#include <uORB/topics/failsafe_flags.h>
|
||||
|
||||
#include <lib/modes/ui.hpp>
|
||||
#include "UserModeIntention.hpp"
|
||||
@@ -164,7 +165,7 @@ public:
|
||||
|
||||
void printStatus() const;
|
||||
|
||||
void getModeStatus(uint32_t &valid_nav_state_mask, uint32_t &can_set_nav_state_mask) const;
|
||||
void getModeStatus(uint32_t &valid_nav_state_mask, uint32_t &can_set_nav_state_mask, const failsafe_flags_s &failsafe_flags) const;
|
||||
|
||||
bool currentModeAcceptsOffboardSetpoints(uint8_t nav_state) const;
|
||||
|
||||
@@ -231,9 +232,9 @@ public:
|
||||
|
||||
void printStatus() const {}
|
||||
|
||||
void getModeStatus(uint32_t &valid_nav_state_mask, uint32_t &can_set_nav_state_mask) const
|
||||
void getModeStatus(uint32_t &valid_nav_state_mask, uint32_t &can_set_nav_state_mask, const failsafe_flags_s &failsafe_flags) const
|
||||
{
|
||||
valid_nav_state_mask = mode_util::getValidNavStates();
|
||||
valid_nav_state_mask = mode_util::getValidNavStates(failsafe_flags.mode_not_supported);
|
||||
can_set_nav_state_mask = valid_nav_state_mask & ~(1u << vehicle_status_s::NAVIGATION_STATE_TERMINATION);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ void getModeRequirements(uint8_t vehicle_type, failsafe_flags_s &flags)
|
||||
flags.mode_req_prevent_arming = 0;
|
||||
flags.mode_req_manual_control = 0;
|
||||
flags.mode_req_other = 0;
|
||||
flags.mode_not_supported = 0;
|
||||
|
||||
// NAVIGATION_STATE_MANUAL
|
||||
setRequirement(vehicle_status_s::NAVIGATION_STATE_MANUAL, flags.mode_req_manual_control);
|
||||
@@ -72,6 +73,10 @@ void getModeRequirements(uint8_t vehicle_type, failsafe_flags_s &flags)
|
||||
setRequirement(vehicle_status_s::NAVIGATION_STATE_ALTCTL, flags.mode_req_local_alt);
|
||||
setRequirement(vehicle_status_s::NAVIGATION_STATE_ALTCTL, flags.mode_req_manual_control);
|
||||
|
||||
if (vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROVER) {
|
||||
setRequirement(vehicle_status_s::NAVIGATION_STATE_ALTCTL, flags.mode_not_supported);
|
||||
}
|
||||
|
||||
// NAVIGATION_STATE_ALTITUDE_CRUISE
|
||||
setRequirement(vehicle_status_s::NAVIGATION_STATE_ALTITUDE_CRUISE, flags.mode_req_angular_velocity);
|
||||
setRequirement(vehicle_status_s::NAVIGATION_STATE_ALTITUDE_CRUISE, flags.mode_req_attitude);
|
||||
@@ -79,6 +84,10 @@ void getModeRequirements(uint8_t vehicle_type, failsafe_flags_s &flags)
|
||||
setRequirement(vehicle_status_s::NAVIGATION_STATE_ALTITUDE_CRUISE,
|
||||
flags.mode_req_manual_control); // COM_RCL_EXCEPT can override this
|
||||
|
||||
if (vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROVER) {
|
||||
setRequirement(vehicle_status_s::NAVIGATION_STATE_ALTITUDE_CRUISE, flags.mode_not_supported);
|
||||
}
|
||||
|
||||
// NAVIGATION_STATE_POSCTL
|
||||
setRequirement(vehicle_status_s::NAVIGATION_STATE_POSCTL, flags.mode_req_angular_velocity);
|
||||
setRequirement(vehicle_status_s::NAVIGATION_STATE_POSCTL, flags.mode_req_attitude);
|
||||
@@ -159,6 +168,10 @@ void getModeRequirements(uint8_t vehicle_type, failsafe_flags_s &flags)
|
||||
setRequirement(vehicle_status_s::NAVIGATION_STATE_DESCEND, flags.mode_req_attitude);
|
||||
setRequirement(vehicle_status_s::NAVIGATION_STATE_DESCEND, flags.mode_req_prevent_arming);
|
||||
|
||||
if (vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROVER) {
|
||||
setRequirement(vehicle_status_s::NAVIGATION_STATE_DESCEND, flags.mode_not_supported);
|
||||
}
|
||||
|
||||
// NAVIGATION_STATE_TERMINATION
|
||||
setRequirement(vehicle_status_s::NAVIGATION_STATE_TERMINATION, flags.mode_req_prevent_arming);
|
||||
|
||||
@@ -224,6 +237,10 @@ void getModeRequirements(uint8_t vehicle_type, failsafe_flags_s &flags)
|
||||
setRequirement(vehicle_status_s::NAVIGATION_STATE_AUTO_VTOL_TAKEOFF, flags.mode_req_local_position);
|
||||
}
|
||||
|
||||
if (vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROVER) {
|
||||
setRequirement(vehicle_status_s::NAVIGATION_STATE_AUTO_VTOL_TAKEOFF, flags.mode_not_supported);
|
||||
}
|
||||
|
||||
// NAVIGATION_STATE_EXTERNALx: handled outside
|
||||
|
||||
static_assert(vehicle_status_s::NAVIGATION_STATE_MAX == 31, "update mode requirements");
|
||||
|
||||
@@ -936,3 +936,33 @@ TEST_F(FailsafeTest, NoNotificationForDisabledFailsafe)
|
||||
EXPECT_EQ(failsafe.selectedAction(), FailsafeBase::Action::None);
|
||||
EXPECT_EQ(notifications, notifications_before);
|
||||
}
|
||||
|
||||
TEST_F(FailsafeTest, RoverUnsupportedDescendToDisarm)
|
||||
{
|
||||
FailsafeTester failsafe(nullptr);
|
||||
|
||||
failsafe_flags_s failsafe_flags{};
|
||||
FailsafeBase::State state{};
|
||||
state.armed = true;
|
||||
state.user_intended_mode = vehicle_status_s::NAVIGATION_STATE_POSCTL;
|
||||
state.vehicle_type = vehicle_status_s::VEHICLE_TYPE_ROVER;
|
||||
hrt_abstime time = 3847124342;
|
||||
bool stick_override_request = false;
|
||||
|
||||
// 1. Simulate a Rover by marking Descend as unsupported
|
||||
failsafe_flags.mode_not_supported |= (1u << vehicle_status_s::NAVIGATION_STATE_DESCEND);
|
||||
|
||||
// 2. Trigger a failure that normally cascades to Hold, then Descend
|
||||
failsafe_flags.mission_failure = true;
|
||||
state.user_intended_mode = vehicle_status_s::NAVIGATION_STATE_AUTO_MISSION;
|
||||
|
||||
time += 10_ms;
|
||||
failsafe.update(time, state, false, stick_override_request, failsafe_flags);
|
||||
|
||||
// 3. Advance time past the Hold delay (3+ seconds) to trigger the Descend fallback
|
||||
time += 6_s;
|
||||
failsafe.update(time, state, false, stick_override_request, failsafe_flags);
|
||||
|
||||
// 4. Verify that because Descend is unsupported, the action safely diverted to Disarm
|
||||
ASSERT_EQ(failsafe.selectedAction(), FailsafeBase::Action::Disarm);
|
||||
}
|
||||
@@ -609,6 +609,14 @@ void FailsafeBase::getSelectedAction(const State &state, const failsafe_flags_s
|
||||
|
||||
returned_state.cause = Cause::Generic;
|
||||
|
||||
// If descend is not supported (e.g. for rovers), safely disarm instead of terminating.
|
||||
// However, if the user explicitly configured the position failsafe action to Terminate, honor it.
|
||||
if ((status_flags.mode_not_supported & (1u << vehicle_status_s::NAVIGATION_STATE_DESCEND))
|
||||
&& _param_com_pos_fs_act.get() != (int32_t)PositionFailsafeAction::Terminate) {
|
||||
selected_action = Action::Disarm;
|
||||
break;
|
||||
}
|
||||
|
||||
// fallthrough
|
||||
case Action::Terminate:
|
||||
selected_action = Action::Terminate;
|
||||
@@ -722,7 +730,8 @@ bool FailsafeBase::modeCanRun(const failsafe_flags_s &status_flags, uint8_t mode
|
||||
(!status_flags.auto_mission_missing || ((status_flags.mode_req_mission & mode_mask) == 0)) &&
|
||||
(!status_flags.offboard_control_signal_lost || ((status_flags.mode_req_offboard_signal & mode_mask) == 0)) &&
|
||||
(!status_flags.home_position_invalid || ((status_flags.mode_req_home_position & mode_mask) == 0)) &&
|
||||
((status_flags.mode_req_other & mode_mask) == 0);
|
||||
((status_flags.mode_req_other & mode_mask) == 0) &&
|
||||
((status_flags.mode_not_supported & mode_mask) == 0);
|
||||
}
|
||||
|
||||
bool FailsafeBase::deferFailsafes(bool enabled, int timeout_s)
|
||||
|
||||
Reference in new issue
Block a user