Safety Systems

This section covers safety systems including arming checks, geofencing, and failsafe procedures.

AP_Arming (Arming System)

Header: libraries/AP_Arming/AP_Arming.h

Inheritance: None (top-level class)

Description: Arming system that performs pre-arm safety checks before enabling motor control. Prevents accidental motor activation and ensures all systems are operational.

Key Features:

  • Pre-arm checks for all sensors

  • GPS lock requirements

  • Compass calibration verification

  • Barometer health checks

  • RC input validation

Related Classes:

Usage Example:

#include <AP_Arming.h>

AP_Arming *arming = AP_Arming::get_singleton();

// Check if vehicle can be armed
if (arming->pre_arm_checks(true, failure_msg, sizeof(failure_msg))) {
    // Can arm
    arming->arm(AP_Arming::RudderArming);
}

// Disarm
arming->disarm();

AP_Fence (Geofence)

Header: libraries/AC_Fence/AC_Fence.h

Inheritance: None (top-level class)

Description: Geofencing system that prevents the vehicle from leaving a designated area. s cylindrical and polygon fence types.

Key Features:

  • Circular/cylindrical fence

  • Polygon fence support

  • Floor and ceiling limits

  • Automatic return behavior

  • Fence breach notification

Related Classes:

  • AC_Fence_Backend - Fence protocol backends

Usage Example:

#include <AC_Fence.h>

AC_Fence *fence = AC_Fence::get_singleton();

// Enable fence
fence->enable();

// Check if inside fence
if (fence->get_breach_status() != AC_Fence::BreachNone) {
    // Outside fence - take action
    fence->return_to_home();
}

AP_AdvancedFailsafe (Advanced Failsafe)

Header: libraries/AP_AdvancedFailsafe/AP_AdvancedFailsafe.h

Description: Advanced failsafe system that handles communication loss, GPS failure, and other emergency situations.

Key Features:

  • RC loss failsafe

  • GCS (Ground Control Station) loss failsafe

  • GPS loss behavior

  • Battery failsafe

  • Customizable failsafe actions

Failsafe Actions:

  • Continue (continue mission)

  • Return to Launch (RTL)

  • Land

  • SmartRTL

  • Brake

Usage Example:

AP_AdvancedFailsafe *afs = AP_AdvancedFailsafe::get_singleton();

// Set failsafe behavior
afs->set_gcs_failsafe(AP_AdvancedFailsafe::Failsafe_Return);
afs->set_rc_failsafe(AP_AdvancedFailsafe::Failsafe_Land);

AC_Avoidance (Obstacle Avoidance)

Header: libraries/AC_Avoidance/AC_Avoidance.h

Description: Obstacle avoidance system using sensors like rangefinders and vision systems.

Avoidance Types:

  • Stop - Stop before obstacle

  • Slide - Move around obstacle

  • Altitude Hold - Climb over obstacle

Usage Example:

AC_Avoidance *avoid = AC_Avoidance::get_singleton();

// Enable avoidance
avoid->enable();

// Check for avoidance action
Vector3f desired_velocity;
if (avoid->avoid_collision(desired_velocity)) {
    // Apply avoidance
    // ...
}