mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-22 14:19:57 +08:00
feat(commander)!: combine battery and bingo fuel failsafe into COM_LOW_BAT_ACT (#29620)
This commit is contained in:
1 parent
fedc33bdea
commit
c6ddbe1499
9 files changed
+132
-84
No files matched your search
@@ -298,7 +298,6 @@
|
||||
1 1 COM_FLTMODE4 11 6
|
||||
1 1 COM_FLTMODE5 -1 6
|
||||
1 1 COM_FLTMODE6 8 6
|
||||
1 1 COM_FLTT_LOW_ACT 3 6
|
||||
1 1 COM_FLT_TIME_MAX -1 6
|
||||
1 1 COM_FORCE_SAFETY 0 6
|
||||
1 1 COM_HLDL_LOSS_T 120 6
|
||||
|
||||
+35
-18
@@ -77,37 +77,54 @@ QGC allows users to set some aspects of the landing behaviour, such as the time
|
||||
|
||||
### Battery level failsafe
|
||||
|
||||
The low battery failsafe is triggered when the battery capacity drops below battery failafe level values.
|
||||
The battery level failsafe is triggered when the battery capacity drops below battery failsafe level values.
|
||||
You can configure both the levels and the failsafe actions at each level in QGroundControl.
|
||||
|
||||

|
||||
|
||||
The most common configuration is to set the values and action as above (with `Warn > Failsafe > Emergency`), and to set the [Failsafe Action](#COM_LOW_BAT_ACT) to warn at "warn level", trigger Return mode at "Failsafe level", and land immediately at "Emergency level".
|
||||
You should set the failsafe levels with `Warn > Failsafe > Emergency` as shown above.
|
||||
Note that PX4 will warn if the battery drops to the "Warn level" for any of action settings.
|
||||
|
||||
The failsafe actions can then be set to one of:
|
||||
|
||||
- `0: Warning` — Warn only.
|
||||
- `2: Land mode` — Land at the "Failsafe level".
|
||||
- `3: Distance-aware return, Critical level return, Emergency level land` (recommended) — Return mode at the "Failsafe" (critical) level, Land at the "Emergency" level, plus the [distance-aware return failsafe](#distance-aware-return-failsafe).
|
||||
- `5: Critical level return, Emergency level land` — Same as `3`, but without the [distance-aware return failsafe](#distance-aware-return-failsafe) (only warns).
|
||||
|
||||
The settings and underlying parameters are shown below.
|
||||
|
||||
| Setting | Parameter | Description |
|
||||
| --------------------------------------------------- | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
|
||||
| <a id="COM_LOW_BAT_ACT"></a>Failsafe Action | [COM_LOW_BAT_ACT](../advanced_config/parameter_reference.md#COM_LOW_BAT_ACT) | Warn, Return, or Land based when capacity drops below the trigger levels. |
|
||||
| <a id="BAT_LOW_THR"></a>Battery Warn Level | [BAT_LOW_THR](../advanced_config/parameter_reference.md#BAT_LOW_THR) | Percentage capacity for warnings (or other actions). |
|
||||
| <a id="BAT_CRIT_THR"></a>Battery Failsafe Level | [BAT_CRIT_THR](../advanced_config/parameter_reference.md#BAT_CRIT_THR) | Percentage capacity for Return action (or other actions if a single action selected). |
|
||||
| <a id="BAT_EMERGEN_THR"></a>Battery Emergency Level | [BAT_EMERGEN_THR](../advanced_config/parameter_reference.md#BAT_EMERGEN_THR) | Percentage capacity for triggering Land (immediately) action. |
|
||||
| Setting | Parameter | Description |
|
||||
| --------------------------------------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
|
||||
| <a id="COM_LOW_BAT_ACT"></a>Failsafe Action | [COM_LOW_BAT_ACT](../advanced_config/parameter_reference.md#COM_LOW_BAT_ACT) | Warn, Return, or Land based when capacity drops below the trigger levels. Option `3` adds distance-aware return. |
|
||||
| <a id="BAT_LOW_THR"></a>Battery Warn Level | [BAT_LOW_THR](../advanced_config/parameter_reference.md#BAT_LOW_THR) | Percentage capacity for warnings (or other actions). |
|
||||
| <a id="BAT_CRIT_THR"></a>Battery Failsafe Level | [BAT_CRIT_THR](../advanced_config/parameter_reference.md#BAT_CRIT_THR) | Percentage capacity for Return action (or other actions if a single action selected). |
|
||||
| <a id="BAT_EMERGEN_THR"></a>Battery Emergency Level | [BAT_EMERGEN_THR](../advanced_config/parameter_reference.md#BAT_EMERGEN_THR) | Percentage capacity for triggering Land (immediately) action. |
|
||||
|
||||
### Flight Time Failsafes
|
||||
### Distance-Aware Return Failsafe
|
||||
|
||||
There are several other "battery related" failsafe mechanisms that may be configured using parameters:
|
||||
The _distance-aware return_ failsafe engages [Return mode](../flight_modes/return.md) when the estimated remaining flight time drops to the time needed to return (in aviation this point is known as "bingo fuel").
|
||||
Unlike the [battery level failsafe](#battery-level-failsafe), it accounts for how far away the vehicle is: it triggers earlier when the return destination is far away, and later when it is close.
|
||||
|
||||
It is enabled by setting [COM_LOW_BAT_ACT](#COM_LOW_BAT_ACT) to `3`.
|
||||
With all other options PX4 only warns.
|
||||
|
||||
PX4 compares the time needed to return, estimated along the current Return mode path with the safety margin set by [RTL_TIME_FACTOR](../advanced_config/parameter_reference.md#RTL_TIME_FACTOR) and [RTL_TIME_MARGIN](../advanced_config/parameter_reference.md#RTL_TIME_MARGIN), against the remaining flight time of the battery with the least time left.
|
||||
Once Return mode has been triggered, it is not cancelled if the estimate improves again on the way back.
|
||||
|
||||
::: warning
|
||||
The failsafe needs a remaining flight time estimate, such as from the battery capacity ([BAT1_CAPACITY](../advanced_config/parameter_reference.md#BAT1_CAPACITY)) or a [smart battery](../smart_batteries/index.md).
|
||||
Without one it never triggers, and the vehicle is only protected by the [battery level failsafe](#battery-level-failsafe).
|
||||
:::
|
||||
|
||||
### Other Battery Related Failsafes
|
||||
|
||||
- The "remaining flight time for safe return" failsafe ([COM_FLTT_LOW_ACT](#COM_FLTT_LOW_ACT)) is engaged when PX4 estimates that the vehicle has just enough battery remaining for a return mode landing.
|
||||
You can configure this to ignore the failsafe, warn, or engage Return mode.
|
||||
- The "maximum flight time failsafe" ([COM_FLT_TIME_MAX](#COM_FLT_TIME_MAX)) allows you to set a maximum flight time after takeoff, at which the vehicle will automatically enter return mode (it will also "warn" at 90% of this time). This is like a "hard coded" estimate of the total flight time in a battery. The feature is disabled by default.
|
||||
- The "minimum battery" for arming parameter ([COM_ARM_BAT_MIN](#COM_ARM_BAT_MIN)) prevents arming in the first place if the battery level is below the specified value.
|
||||
|
||||
The settings and underlying parameters are shown below.
|
||||
|
||||
| Setting | Parameter | Description |
|
||||
| -------------------------------------------------------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| <a id="COM_FLTT_LOW_ACT"></a> Low flight time for safe return action | [COM_FLTT_LOW_ACT](../advanced_config/parameter_reference.md#COM_FLTT_LOW_ACT) | Action when return mode can only just reach safety with remaining battery. `0`: None (default), `1`: Warning, `3`: Return mode. |
|
||||
| <a id="COM_FLT_TIME_MAX"></a> Maximum flight time failsafe level | [COM_FLT_TIME_MAX](../advanced_config/parameter_reference.md#COM_FLT_TIME_MAX) | Maximum allowed flight time before Return mode will be engaged, in seconds. `-1`: Disabled (default). |
|
||||
| Setting | Parameter | Description |
|
||||
| ---------------------------------------------------------------- | ------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- |
|
||||
| <a id="COM_FLT_TIME_MAX"></a> Maximum flight time failsafe level | [COM_FLT_TIME_MAX](../advanced_config/parameter_reference.md#COM_FLT_TIME_MAX) | Maximum allowed flight time before Return mode will be engaged, in seconds. `-1`: Disabled (default). |
|
||||
|
||||
## Manual Control Loss Failsafe
|
||||
|
||||
|
||||
@@ -85,6 +85,13 @@ For users upgrading from v1.17, please take a moment to review the following bef
|
||||
The `-r` command-line rotation flag is removed; set the mounting orientation via [SENS_AFBR_ROT](../advanced_config/parameter_reference.md#SENS_AFBR_ROT) instead.
|
||||
([PX4-Autopilot#27385](https://github.com/PX4/PX4-Autopilot/pull/27385))
|
||||
|
||||
12. **Check the distance-aware return (remaining flight time) failsafe.**
|
||||
`COM_FLTT_LOW_ACT` has been removed and its function is part of [COM_LOW_BAT_ACT](../advanced_config/parameter_reference.md#COM_LOW_BAT_ACT) again: option `3` engages Return mode when the remaining flight time is only just enough to return. All other options only warn.
|
||||
This restores the behaviour that `COM_LOW_BAT_ACT=3` had with otherwise default parameters in v1.12 to v1.16; v1.17 was the exception, as it disabled the distance-aware return by default (`COM_FLTT_LOW_ACT=0`).
|
||||
`COM_FLTT_LOW_ACT` is not migrated: if you use `COM_LOW_BAT_ACT=3` and do not want distance-aware return, change it to the new option `5`.
|
||||
See [Distance-Aware Return Failsafe](../config/safety.md#distance-aware-return-failsafe).
|
||||
([PX4-Autopilot#26955](https://github.com/PX4/PX4-Autopilot/pull/26955))
|
||||
|
||||
## Hardware Support
|
||||
|
||||
### New Flight Controllers
|
||||
@@ -180,6 +187,7 @@ For users upgrading from v1.17, please take a moment to review the following bef
|
||||
|
||||
## Safety
|
||||
|
||||
- [Distance-aware return failsafe](../config/safety.md#distance-aware-return-failsafe) (also known as "bingo fuel"): engaging Return mode when the remaining flight time is only just enough to return is now part of [COM_LOW_BAT_ACT](../advanced_config/parameter_reference.md#COM_LOW_BAT_ACT) `3` (the new option `5` opts out), instead of the separate `COM_FLTT_LOW_ACT`. See the [Upgrade Guide](#upgrade-guide). ([PX4-Autopilot#26955](https://github.com/PX4/PX4-Autopilot/pull/26955))
|
||||
- Rotary-wing vehicles now support uncommanded altitude loss detection: if the vehicle descends more than [FD_ALT_LOSS](../advanced_config/parameter_reference.md#FD_ALT_LOSS) meters below its setpoint in altitude-controlled flight, flight termination (and parachute deployment) is triggered. See [Altitude Loss Trigger](../config/safety.md#altitude-loss-trigger). ([PX4-Autopilot#26837](https://github.com/PX4/PX4-Autopilot/pull/26837))
|
||||
- [Parachute health failsafe](../peripherals/parachute.md): extended [COM_PARACHUTE](../advanced_config/parameter_reference.md#COM_PARACHUTE) from a boolean into a configurable arming check and in-flight failsafe action parameter (Warning, Error, Return, or Land). The previously enabled value `COM_PARACHUTE=1` (Warning) now only warns without preventing arming; use `COM_PARACHUTE=2` (Error) or higher to prevent arming when the parachute system is missing or unhealthy. ([PX4-Autopilot#26918](https://github.com/PX4/PX4-Autopilot/pull/26918))
|
||||
- [GNSS check failsafe](../config/safety.md#gnss-check-failsafe): new failsafe that monitors the number of usable GNSS receivers with a 3D fix and their position consistency. The required number of receivers is set via [SYS_HAS_NUM_GNSS](../advanced_config/parameter_reference.md#SYS_HAS_NUM_GNSS) and the failsafe action via [COM_GNSSLOSS_ACT](../advanced_config/parameter_reference.md#COM_GNSSLOSS_ACT). ([PX4-Autopilot#26863](https://github.com/PX4/PX4-Autopilot/pull/26863))
|
||||
|
||||
@@ -317,12 +317,12 @@ void BatteryChecks::rtlEstimateCheck(const Context &context, Report &reporter, f
|
||||
&& rtl_time_estimate.safe_time_estimate * hysteresis_factor >= worst_battery_time_s;
|
||||
|
||||
|
||||
// Only report if the failsafe action is enabled, otherwise the condition has no effect
|
||||
if (reporter.failsafeFlags().battery_low_remaining_time && _param_com_fltt_low_act.get() > 0) {
|
||||
// Every COM_LOW_BAT_ACT option at least warns on low remaining flight time (distance-aware return options return)
|
||||
if (reporter.failsafeFlags().battery_low_remaining_time) {
|
||||
/* EVENT
|
||||
* @description
|
||||
* <profile name="dev">
|
||||
* This check can be configured via <param>COM_FLTT_LOW_ACT</param> parameter.
|
||||
* The action (warning or distance-aware return) can be configured via <param>COM_LOW_BAT_ACT</param> parameter.
|
||||
* </profile>
|
||||
*/
|
||||
reporter.armingCheckFailure(NavModes::All, health_component_t::battery, events::ID("check_battery_rem_flight_time_low"),
|
||||
|
||||
@@ -58,7 +58,6 @@ private:
|
||||
|
||||
DEFINE_PARAMETERS_CUSTOM_PARENT(HealthAndArmingCheckBase,
|
||||
(ParamFloat<px4::params::COM_ARM_BAT_MIN>) _param_com_arm_bat_min,
|
||||
(ParamInt<px4::params::CBRK_SUPPLY_CHK>) _param_cbrk_supply_chk,
|
||||
(ParamInt<px4::params::COM_FLTT_LOW_ACT>) _param_com_fltt_low_act
|
||||
(ParamInt<px4::params::CBRK_SUPPLY_CHK>) _param_cbrk_supply_chk
|
||||
)
|
||||
};
|
||||
@@ -157,13 +157,17 @@ parameters:
|
||||
description:
|
||||
short: Battery failsafe mode
|
||||
long: |-
|
||||
Action the system takes at critical battery. See also BAT_CRIT_THR and BAT_EMERGEN_THR
|
||||
for definition of battery states.
|
||||
Action when the battery drops below the critical (BAT_CRIT_THR) or emergency (BAT_EMERGEN_THR) level.
|
||||
|
||||
Option 3 also engages Return mode when the remaining flight time is only just enough to return (distance-aware return, with the margin set by RTL_TIME_FACTOR and RTL_TIME_MARGIN).
|
||||
This needs a remaining flight time estimate, such as from BATn_CAPACITY or a smart battery.
|
||||
The other options only warn.
|
||||
type: enum
|
||||
values:
|
||||
0: Warning
|
||||
2: Land mode
|
||||
3: Return at critical level, land at emergency level
|
||||
3: Distance-aware return, Critical level return, Emergency level land
|
||||
5: Critical level return, Emergency level land
|
||||
default: 0
|
||||
COM_FAIL_ACT_T:
|
||||
description:
|
||||
@@ -760,19 +764,6 @@ parameters:
|
||||
decimal: 1
|
||||
increment: 0.1
|
||||
unit: m/s
|
||||
COM_FLTT_LOW_ACT:
|
||||
description:
|
||||
short: Remaining flight time low failsafe
|
||||
long: |-
|
||||
Action the system takes when the remaining flight time is below
|
||||
the estimated time it takes to reach the RTL destination.
|
||||
type: enum
|
||||
values:
|
||||
0: None
|
||||
1: Warning
|
||||
3: Return
|
||||
default: 0
|
||||
increment: 1
|
||||
COM_MODE_ARM_CHK:
|
||||
description:
|
||||
short: Allow external mode registration while armed
|
||||
|
||||
@@ -165,6 +165,9 @@ FailsafeBase::ActionOptions Failsafe::fromActuatorFailureActParam(int param_valu
|
||||
return options;
|
||||
}
|
||||
|
||||
// "battery level" to handle the remaining flight time (Distance-aware return)
|
||||
static constexpr uint8_t BATTERY_WARNING_DISTANCE_AWARE_RETURN = UINT8_MAX;
|
||||
|
||||
FailsafeBase::ActionOptions Failsafe::fromBatteryWarningActParam(int param_value, uint8_t battery_warning)
|
||||
{
|
||||
ActionOptions options{};
|
||||
@@ -187,6 +190,7 @@ FailsafeBase::ActionOptions Failsafe::fromBatteryWarningActParam(int param_value
|
||||
switch ((LowBatteryAction)param_value) {
|
||||
case LowBatteryAction::Return:
|
||||
case LowBatteryAction::ReturnOrLand:
|
||||
case LowBatteryAction::ReturnOrLandWithoutDistanceAwareReturn:
|
||||
options.action = Action::RTL;
|
||||
break;
|
||||
|
||||
@@ -210,8 +214,9 @@ FailsafeBase::ActionOptions Failsafe::fromBatteryWarningActParam(int param_value
|
||||
options.action = Action::RTL;
|
||||
break;
|
||||
|
||||
case LowBatteryAction::ReturnOrLand:
|
||||
case LowBatteryAction::Land:
|
||||
case LowBatteryAction::ReturnOrLand:
|
||||
case LowBatteryAction::ReturnOrLandWithoutDistanceAwareReturn:
|
||||
options.action = Action::Land;
|
||||
break;
|
||||
|
||||
@@ -221,6 +226,24 @@ FailsafeBase::ActionOptions Failsafe::fromBatteryWarningActParam(int param_value
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BATTERY_WARNING_DISTANCE_AWARE_RETURN:
|
||||
options.action = Action::Warn;
|
||||
options.cause = Cause::RemainingFlightTimeLow;
|
||||
|
||||
switch ((LowBatteryAction)param_value) {
|
||||
case LowBatteryAction::Return:
|
||||
case LowBatteryAction::ReturnOrLand:
|
||||
options.action = Action::RTL;
|
||||
options.clear_condition = ClearCondition::OnModeChangeOrDisarm;
|
||||
break;
|
||||
|
||||
case LowBatteryAction::Warning:
|
||||
case LowBatteryAction::Land:
|
||||
case LowBatteryAction::ReturnOrLandWithoutDistanceAwareReturn:
|
||||
options.action = Action::Warn;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
@@ -444,36 +467,6 @@ FailsafeBase::ActionOptions Failsafe::fromParachuteActParam(int param_value)
|
||||
return options;
|
||||
}
|
||||
|
||||
FailsafeBase::ActionOptions Failsafe::fromRemainingFlightTimeLowActParam(int param_value)
|
||||
{
|
||||
ActionOptions options{};
|
||||
|
||||
options.allow_user_takeover = UserTakeoverAllowed::Auto;
|
||||
options.cause = Cause::RemainingFlightTimeLow;
|
||||
|
||||
switch (command_after_remaining_flight_time_low(param_value)) {
|
||||
case command_after_remaining_flight_time_low::None:
|
||||
options.action = Action::None;
|
||||
break;
|
||||
|
||||
case command_after_remaining_flight_time_low::Warning:
|
||||
options.action = Action::Warn;
|
||||
break;
|
||||
|
||||
case command_after_remaining_flight_time_low::Return_mode:
|
||||
options.action = Action::RTL;
|
||||
options.clear_condition = ClearCondition::OnModeChangeOrDisarm;
|
||||
break;
|
||||
|
||||
default:
|
||||
options.action = Action::None;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
FailsafeBase::ActionOptions Failsafe::fromOdidFailActParam(int param_value)
|
||||
{
|
||||
ActionOptions options{};
|
||||
@@ -625,10 +618,6 @@ void Failsafe::checkStateAndMode(const hrt_abstime &time_us, const State &state,
|
||||
|
||||
CHECK_FAILSAFE(status_flags, geofence_breached, fromGfActParam(_param_gf_action.get()).cannotBeDeferred());
|
||||
|
||||
// Battery flight time remaining failsafe
|
||||
CHECK_FAILSAFE(status_flags, battery_low_remaining_time,
|
||||
ActionOptions(fromRemainingFlightTimeLowActParam(_param_com_fltt_low_act.get())));
|
||||
|
||||
const hrt_abstime spoolup = static_cast<hrt_abstime>(_param_com_spoolup_time.get() * 1_s);
|
||||
|
||||
if ((_armed_time != 0) && (time_us < _armed_time + spoolup)) {
|
||||
@@ -674,6 +663,9 @@ void Failsafe::checkStateAndMode(const hrt_abstime &time_us, const State &state,
|
||||
break;
|
||||
}
|
||||
|
||||
// Battery flight time remaining failsafe (Distance-aware return)
|
||||
CHECK_FAILSAFE(status_flags, battery_low_remaining_time,
|
||||
ActionOptions(fromBatteryWarningActParam(_param_com_low_bat_act.get(), BATTERY_WARNING_DISTANCE_AWARE_RETURN)));
|
||||
|
||||
// Handle fails during spoolup just after arming
|
||||
if ((_armed_time != 0) && (time_us < _armed_time + spoolup)) {
|
||||
|
||||
@@ -66,7 +66,8 @@ private:
|
||||
Warning = 0, // Warning
|
||||
Return = 1, // Return mode (deprecated)
|
||||
Land = 2, // Land mode
|
||||
ReturnOrLand = 3 // Return mode at critically low level, Land mode at current position if reaching dangerously low levels
|
||||
ReturnOrLand = 3, // Return mode at critically low level, Land mode at current position if reaching dangerously low levels, plus distance-aware return
|
||||
ReturnOrLandWithoutDistanceAwareReturn = 5 // ReturnOrLand, but only warn when the remaining flight time is only just enough to return
|
||||
};
|
||||
|
||||
enum class offboard_loss_failsafe_mode : int32_t {
|
||||
@@ -145,12 +146,6 @@ private:
|
||||
Land_mode = 5
|
||||
};
|
||||
|
||||
enum class command_after_remaining_flight_time_low : int32_t {
|
||||
None = 0,
|
||||
Warning = 1,
|
||||
Return_mode = 3
|
||||
};
|
||||
|
||||
enum class open_drone_id_failsafe_mode : int32_t {
|
||||
None = 0,
|
||||
Warning = 1,
|
||||
@@ -184,7 +179,6 @@ private:
|
||||
static Action fromOffboardLossActParam(int param_value, uint8_t &user_intended_mode);
|
||||
static ActionOptions fromHighWindLimitActParam(int param_value);
|
||||
static ActionOptions fromPosLowActParam(int param_value);
|
||||
static ActionOptions fromRemainingFlightTimeLowActParam(int param_value);
|
||||
static ActionOptions fromOdidFailActParam(int param_value);
|
||||
static ActionOptions fromParachuteActParam(int param_value);
|
||||
static ActionOptions fromGnssLossActParam(int param_value);
|
||||
@@ -235,7 +229,6 @@ private:
|
||||
(ParamInt<px4::params::COM_OBL_RC_ACT>) _param_com_obl_rc_act,
|
||||
(ParamInt<px4::params::COM_QC_ACT>) _param_com_qc_act,
|
||||
(ParamInt<px4::params::COM_WIND_MAX_ACT>) _param_com_wind_max_act,
|
||||
(ParamInt<px4::params::COM_FLTT_LOW_ACT>) _param_com_fltt_low_act,
|
||||
(ParamInt<px4::params::COM_POS_LOW_ACT>) _param_com_pos_low_act,
|
||||
(ParamInt<px4::params::COM_ARM_ODID>) _param_com_arm_odid,
|
||||
(ParamInt<px4::params::COM_PARACHUTE>) _param_com_parachute,
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "failsafe.h"
|
||||
#include <uORB/topics/battery_status.h>
|
||||
#include <uORB/topics/vehicle_status.h>
|
||||
#include "../ModeUtil/mode_requirements.hpp"
|
||||
|
||||
@@ -760,3 +761,51 @@ TEST_F(FailsafeTest, FallbackStabilizedRequiresManualControl)
|
||||
// because local altitude loss blocks both AUTO_RTL and AUTO_LAND.
|
||||
EXPECT_EQ(failsafe.selectedAction(), FailsafeBase::Action::Descend);
|
||||
}
|
||||
|
||||
TEST_F(FailsafeTest, BatteryFailsafeUsesLowBatActParam)
|
||||
{
|
||||
// Each param value is exercised on its own fresh Failsafe instance, to avoid
|
||||
// action hysteresis/clear-conditions from one value leaking into the next.
|
||||
auto selectedActionFor = [](int32_t com_low_bat_act, uint8_t battery_warning, bool remaining_flight_time_low) {
|
||||
param_set(param_handle(px4::params::COM_LOW_BAT_ACT), &com_low_bat_act);
|
||||
|
||||
// Disable the generic user-takeover hold delay (set to 5s in SetUp()) so a newly
|
||||
// triggered RTL/Land is selected immediately instead of Hold-then-RTL/Land.
|
||||
float com_fail_act_t = 0.f;
|
||||
param_set(param_handle(px4::params::COM_FAIL_ACT_T), &com_fail_act_t);
|
||||
|
||||
Failsafe failsafe(nullptr);
|
||||
|
||||
failsafe_flags_s failsafe_flags{};
|
||||
mode_util::getModeRequirements(vehicle_status_s::VEHICLE_TYPE_ROTARY_WING, failsafe_flags);
|
||||
|
||||
FailsafeBase::State state{};
|
||||
state.armed = true;
|
||||
state.vehicle_type = vehicle_status_s::VEHICLE_TYPE_ROTARY_WING;
|
||||
|
||||
// Arm without battery warning, a battery warning that is already present at arming only warns
|
||||
failsafe.update(5_s, state, false, false, failsafe_flags);
|
||||
|
||||
failsafe_flags.battery_warning = battery_warning;
|
||||
failsafe_flags.battery_low_remaining_time = remaining_flight_time_low;
|
||||
failsafe.update(5_s + 10_ms, state, false, false, failsafe_flags);
|
||||
return failsafe.selectedAction();
|
||||
};
|
||||
|
||||
static constexpr uint8_t kNone = battery_status_s::WARNING_NONE;
|
||||
static constexpr uint8_t kCritical = battery_status_s::WARNING_CRITICAL;
|
||||
static constexpr uint8_t kEmergency = battery_status_s::WARNING_EMERGENCY;
|
||||
|
||||
// Remaining flight time low: only the distance-aware return option returns, all others warn
|
||||
EXPECT_EQ(selectedActionFor(0, kNone, true), FailsafeBase::Action::Warn); // Warning
|
||||
EXPECT_EQ(selectedActionFor(2, kNone, true), FailsafeBase::Action::Warn); // Land mode
|
||||
// Distance-aware return, Critical level return, Emergency level land
|
||||
EXPECT_EQ(selectedActionFor(3, kNone, true), FailsafeBase::Action::RTL);
|
||||
EXPECT_EQ(selectedActionFor(5, kNone, true), FailsafeBase::Action::Warn); // Critical level return, Emergency level land
|
||||
|
||||
// Battery levels: the option without distance-aware return acts like the one with it
|
||||
EXPECT_EQ(selectedActionFor(3, kCritical, false), FailsafeBase::Action::RTL);
|
||||
EXPECT_EQ(selectedActionFor(5, kCritical, false), FailsafeBase::Action::RTL);
|
||||
EXPECT_EQ(selectedActionFor(3, kEmergency, false), FailsafeBase::Action::Land);
|
||||
EXPECT_EQ(selectedActionFor(5, kEmergency, false), FailsafeBase::Action::Land);
|
||||
}
|
||||
Reference in new issue
Block a user