# Simulate Failsafes

[Failsafes](https://px4.gitbook.io/px4-user-guide/config/safety) 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.

:::note You can also test failsafes using [HITL simulation](https://px4.gitbook.io/px4-user-guide/development/simulation/hitl). 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](https://px4.gitbook.io/px4-user-guide/advanced_config/parameter_reference#NAV_DLL_ACT) to the desired failsafe action to change the behavior. For example, set to `0` to disable it.

:::note 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](https://px4.gitbook.io/px4-user-guide/advanced_config/parameter_reference#NAV_RCL_ACT) to the desired failsafe action to change the behavior. For example, set to `0` to disable it.

:::note 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](https://px4.gitbook.io/px4-user-guide/advanced_config/parameter_reference#SIM_BAT_MIN_PCT).

To control how fast the battery depletes to the minimal value use the parameter [SIM\_BAT\_DRAIN](https://px4.gitbook.io/px4-user-guide/advanced_config/parameter_reference#SIM_BAT_DRAIN).

:::tip By changing [SIM\_BAT\_MIN\_PCT](https://px4.gitbook.io/px4-user-guide/advanced_config/parameter_reference#SIM_BAT_MIN_PCT) in flight, you can also test regaining capacity to simulate inaccurate battery state estimation or in-air charging technology. :::

## Sensor/System Failure

[Failure injection](https://px4.gitbook.io/px4-user-guide/development/debug/failure_injection) 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](https://px4.gitbook.io/px4-user-guide/advanced_config/parameter_reference#SYS_FAILURE_EN).
2. Enter the following commands on the SITL instance *pxh shell*:

   ```bash
   # Turn (all) GPS off
   failure gps off

   # Turn (all) GPS on
   failure gps ok
   ```

See [System Failure Injection](https://px4.gitbook.io/px4-user-guide/development/debug/failure_injection) for a list of supported target sensors and failure modes.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://px4.gitbook.io/px4-user-guide/development/simulation/failsafes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
