Peripherals & Extensions

This section covers camera control, gimbals, relays, and other peripherals.

AP_Scripting (Lua Scripting)

Header: libraries/AP_Scripting/AP_Scripting.h

Description: Lua scripting support for custom flight modes, sensors, and behaviors.

Key Features:

  • Lua runtime in firmware

  • Custom flight modes

  • Sensor processing

  • Navigation scripts

  • Trigger control

Usage Example (Lua):

-- Custom flight mode
function update()
    -- Read sensors
    local alt = ahrs:get_altitude()

    -- Control
    if alt < 10 then
        -- Low altitude action
    end
end

-- Register update callback
ahrs:register_update_callback(update)

Common Scripting APIs:

  • ahrs - Attitude and Heading Reference

  • gps - GPS data

  • baro - Barometer data

  • compass - Compass data

  • vehicle - Vehicle state and control

  • mission - Mission commands


AP_Camera (Camera Control)

Header: libraries/AP_Camera/AP_Camera.h

Description: Camera control for triggering photos and videos.

Warning

doxygenclass: Cannot find class “AP_Camera” in doxygen xml output for project “ArduPilot” from directory: /home/runner/work/APMapi/APMapi/docs/../build/output-xml

Key Features:

  • Photo triggering

  • Video recording

  • Intervalometer

  • Mount integration

Usage Example:

#include <AP_Camera.h>

AP_Camera *camera = AP_Camera::get_singleton();

// Take photo
camera->take_picture();

// Start/stop video
camera->start_video();
camera->stop_video();

// Set interval
camera->set_interval(2.0f);  // seconds

AP_Mount (Camera Gimbal)

Header: libraries/AP_Mount/AP_Mount.h

Description: Camera gimbal/mount control for stabilization and targeting.

Supported Gimbals:

  • Servo gimbals

  • MAVLink gimbals

  • Alexmos Gimbal

  • STorM32 Gimbal

  • Gremsy Gimbal

Usage Example:

#include <AP_Mount.h>

AP_Mount *mount = AP_Mount::get_singleton();

// Set mount mode
mount->set_mode(0, AP_Mount::Mode::MAVLink);

// Target angles (roll, pitch, yaw in radians)
mount->set_roll(0, 0.1f);
mount->set_pitch(0, -0.5f);
mount->set_yaw(0, 1.0f);

// Target a location
mount->set_target_location(0, target_location);

AP_Relay (GPIO Relay)

Header: libraries/AP_Relay/AP_Relay.h

Description: General purpose IO for relay/switch control.

Usage Example:

#include <AP_Relay.h>

AP_Relay *relay = AP_Relay::get_singleton();

// Turn relay on/off
relay->set(0, true);   // Relay 0 on
relay->set(0, false);  // Relay 0 off

// Toggle
relay->toggle(0);

AP_ServoRelayEvents

Header: libraries/AP_ServoRelayEvents/AP_ServoRelayEvents.h

Description: Trigger events based on servo positions or RC input.

Usage Example:

// Configure in parameters
// RELAY0 = 54 (servo 5)
// SERVO5_MIN = 1000
// SERVO5_MAX = 2000
// RELAY0_FUNCTION = 0 (default)

AP_SerialLED (WS2812 LED)

Header: libraries/AP_SerialLED/AP_SerialLED.h

Description: Addressable LED (WS2812/NeoPixel) control.

Usage Example:

#include <AP_SerialLED.h>

AP_SerialLED *leds = AP_SerialLED::get_singleton();

// Set LED color (RGB)
leds->set_rgb(0, 255, 0, 0);  // Red

AP_Button (Button Input)

Header: libraries/AP_Button/AP_Button.h

Description: Physical button handling for safety, calibration, etc.

Usage Example:

#include <AP_Button.h>

AP_Button *button = AP_Button::get_singleton();

// Check button state
if (button->get_state(0) == AP_Button::Button_State::PRESSED) {
    // Button pressed
}

See Also