mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-22 06:14:14 +08:00
c970a822a0
* refactor(battery_simulator): remove SIM_BAT_ENABLE
disable instead with SIM_BAT_DRAIN <= 0
* fix(battery_simulator): disable battery sim only if SIM_BAT_DRAIN strictly < 0
* fix(battery_simulator): disable if 0, adjust limit to 0
* fix(battery_simulator): remove constraining again
now that SIM_BAT_DRAIN=0 means the module is not started we are safe
from division by zero again (param compare has a tolerance of 1e-7)
* fix(battery_simulator): constrain param to min of 1
to avoid division by zero.
This reverts commit 6380c4fdee.
* fix(battery_simulator): remove arbitrary param max
* fix(battery_simulator): reword long param description
Co-authored-by: Jacob Dahl <37091262+dakejahl@users.noreply.github.com>
* fix(battery_simulator): reword short param description
Co-authored-by: Jacob Dahl <37091262+dakejahl@users.noreply.github.com>
---------
Co-authored-by: Jacob Dahl <37091262+dakejahl@users.noreply.github.com>
71 lines
3.3 KiB
Markdown
71 lines
3.3 KiB
Markdown
# Simulate Failsafes
|
|
|
|
[Failsafes](../config/safety.md) define the safe limits/conditions under which you can safely use PX4, and the action that will be performed if a failsafe is triggered (for example, landing, holding position, or returning to a specified point).
|
|
|
|
In SITL some failsafes are disabled by default to enable easier simulation usage.
|
|
This topic explains how you can test safety-critical behavior in SITL simulation before attempting it in the real world.
|
|
|
|
::: info
|
|
You can also test failsafes using [HITL simulation](../simulation/hitl.md).
|
|
HITL uses the normal configuration parameters of your flight controller.
|
|
:::
|
|
|
|
## Data Link Loss
|
|
|
|
The _Data Link Loss_ failsafe (unavailability of external data via MAVLink) is enabled by default.
|
|
This makes the simulation only usable with a connected GCS, SDK, or other MAVLink application.
|
|
|
|
Set the parameter [NAV_DLL_ACT](../advanced_config/parameter_reference.md#NAV_DLL_ACT) to the desired failsafe action to change the behavior.
|
|
For example, set to `0` to disable it.
|
|
|
|
::: info
|
|
All parameters in SITL including this one get reset when you do `make clean`.
|
|
:::
|
|
|
|
## RC Link Loss
|
|
|
|
The _RC Link Loss_ failsafe (unavailability of data from a remote control) is enabled by default.
|
|
This makes the simulation only usable with either an active MAVLink or remote control connection.
|
|
|
|
Set the parameter [NAV_RCL_ACT](../advanced_config/parameter_reference.md#NAV_RCL_ACT) to the desired failsafe action to change the behavior.
|
|
For example, set to `0` to disable it.
|
|
|
|
::: info
|
|
All parameters in SITL including this one get reset when you do `make clean`.
|
|
:::
|
|
|
|
## Low Battery
|
|
|
|
The simulated battery is implemented to never run out of energy, and by default only depletes to 50% of its capacity and hence reported voltage.
|
|
This enables testing of battery indication in GCS UIs without triggering low battery reactions that might interrupt other testing.
|
|
|
|
To change this minimal battery percentage value use the parameter [SIM_BAT_MIN_PCT](../advanced_config/parameter_reference.md#SIM_BAT_MIN_PCT).
|
|
|
|
To control how fast the battery depletes to the minimal value use the parameter [SIM_BAT_DRAIN](../advanced_config/parameter_reference.md#SIM_BAT_DRAIN).
|
|
|
|
:::tip
|
|
By changing [SIM_BAT_MIN_PCT](../advanced_config/parameter_reference.md#SIM_BAT_MIN_PCT) in flight, you can also test regaining capacity to simulate inaccurate battery state estimation or in-air charging technology.
|
|
:::
|
|
|
|
The simulated battery can be completely disabled by setting [SIM_BAT_DRAIN](../advanced_config/parameter_reference.md#SIM_BAT_DRAIN) to 0. This is useful, for example, if you provide an external battery simulation via MAVLink.
|
|
|
|
## Sensor/System Failure
|
|
|
|
[Failure injection](../debug/failure_injection.md) can be used to simulate different types of failures in many sensors and systems.
|
|
For example, this can be used to simulate absent or intermittent GPS, RC signal that has stopped or got stuck on a particular value, failure of the avoidance system, and much more.
|
|
|
|
For example, to simulate GPS failure:
|
|
|
|
1. Enable the parameter [SYS_FAILURE_EN](../advanced_config/parameter_reference.md#SYS_FAILURE_EN).
|
|
1. Enter the following commands on the SITL instance _pxh shell_:
|
|
|
|
```sh
|
|
# Turn (all) GPS off
|
|
failure gps off
|
|
|
|
# Turn (all) GPS on
|
|
failure gps ok
|
|
```
|
|
|
|
See [System Failure Injection](../debug/failure_injection.md) for a list of supported target sensors and failure modes.
|