Utilities & Hardware

This section covers utility libraries, storage, ADC, and hardware interfaces.

Storage

AP_Param (Parameter Storage)

Already covered in mission.rst. See Mission, Parameters & Motors.

Storage Manager

Header: libraries/StorageManager/StorageManager.h

Description: Abstract storage interface for EEPROM, FRAM, flash.

Usage Example:

#include <StorageManager.h>

StorageAccess *storage = StorageManager::get(StorageManager::StorageParam);

// Write data
storage->write_block(0, data, sizeof(data));

// Read data
storage->read_block(0, buffer, sizeof(buffer));

AP_FlashLog (Flash Logging)

Header: libraries/AP_FlashLog/AP_FlashLog.h

Description: Flash-based logging for parameters and data.

AP_ROMFS (ROM File System)

Header: libraries/AP_ROMFS/AP_ROMFS.h

Description: Read-only file system for configuration files.


Analog & Digital IO

AP_ADC (Analog to Digital)

Header: libraries/AP_ADC/AP_ADC.h

Description: Analog input reading from ADC channels.

Usage Example:

#include <AP_ADC.h>

AP_ADC *adc = AP_ADC::get_singleton();

// Read ADC channel
float voltage = adc->read_adc(0) * 3.3f / 4096.0f;

AP_GPIO (General Purpose IO)

Header: libraries/AP_GPIO/AP_GPIO.h

Description: GPIO pin control.

Usage Example:

// Set pin mode
hal.gpio->pinMode(LED_PIN, HAL_GPIO_OUTPUT);

// Write
hal.gpio->digitalWrite(LED_PIN, HAL_GPIO_HIGH);

Timing & Scheduling

AP_Scheduler (Task Scheduler)

Header: libraries/AP_Scheduler/AP_Scheduler.h

Description: Main loop task scheduling system.

Usage Example:

AP_Scheduler *scheduler = AP_Scheduler::get_singleton();

// Register task
scheduler->register_task(update_50hz, "50Hz Loop", 1000);

AP_Stats (Runtime Statistics)

Header: libraries/AP_Stats/AP_Stats.h

Description: Runtime statistics tracking (CPU usage, loop time, etc.).

Usage Example:

AP_Stats *stats = AP_Stats::get_singleton();

// Get loop time
uint32_t loop_time_us = stats->get_loop_time();

// Get CPU usage
float cpu_usage = stats->get_cpu_usage();

Logging

DataFlash (Flight Log)

Header: libraries/DataFlash/

Description: Binary flight log storage.

Log Messages:

  • ATT - Attitude

  • GPS - GPS data

  • BARO - Barometer data

  • MAG - Compass data

  • IMU - Accelerometer/Gyro

  • REL - Relay events

  • CAM - Camera events

Usage Example:

#include <DataFlash.h>

DataFlash *df = DataFlash::get_singleton();

// Log a message
df->Log_Write("MSG", "Message", "s", message_str);

// Start logging
df->StartNewLog();

// Stop logging
df->StopLogging();

Utilities

AP_Math (Math Library)

Common mathematical utilities:

  • Vector2f, Vector3f, Vector3p - Vector classes

  • Matrix3f, Matrix3h - Matrix classes

  • Quaternion - Quaternion rotation

  • wrap_angles - Angle wrapping functions

  • lerp - Linear interpolation

Filter Library

Header: libraries/Filter/

Common filters:

  • LowPassFilter - Simple low-pass filter

  • ButterworthFilter - Butterworth filter

  • SlewFilter - Rate limiter

  • PID - PID controller (see AC_PID)

AP_Buffer (Circular Buffer)

Header: libraries/AP_Buffer/

Circular buffer for data storage.

See Also