Skip to content

FC Data

Ashish Jaiswal edited this page Jul 21, 2026 · 2 revisions

FC-Data.h

Flight controller data access: raw sensor readings and fused state estimates (attitude, rate, position, velocity).

Enumerations

FC_Sensors_e

Selects the sensor for Sensor_Get().

typedef enum {
    Accelerometer,    // Acceleration sensor
    Gyroscope,        // Rotation rate sensor
    Magnetometer,     // Magnetic field sensor
    Barometer         // Pressure sensor
} FC_Sensors_e;

BARO_Data_e

Selects which barometer reading Sensor_Get() returns.

typedef enum {
    Pressure,         // Barometric pressure
    Temperature       // Temperature reading
} BARO_Data_e;

FC_Estimate_e

Selects the estimate for Estimate_Get().

typedef enum {
    Angle,           // Attitude angles
    Rate,            // Rotation rates
    Position,        // Position estimates
    Velocity         // Velocity estimates
} FC_Estimate_e;

Parameter enums

The functions below also take these enums (defined in axis.h):

typedef enum { X = 0, Y, Z, Net_Acc } axis_e;          // Net_Acc = net acceleration magnitude
typedef enum { AG_ROLL = 0, AG_PITCH, AG_YAW } angle_e;

Functions

int32_t Sensor_Get(FC_Sensors_e _sensor, axis_e _axis)

Returns a scaled reading from the Accelerometer, Gyroscope, or Magnetometer for the given axis (Net_Acc gives the accelerometer's net magnitude). Returns 0 for unsupported types. Sensor data is live, so read it in plutoLoop().

void plutoLoop ( void ) {
    int32_t accelX = Sensor_Get ( Accelerometer, X );
    int32_t gyroZ  = Sensor_Get ( Gyroscope, Z );
    Monitor_Print ( "AccelX: ", accelX );
}

int32_t Sensor_Get(FC_Sensors_e _sensor, BARO_Data_e _data)

Returns barometer data: pressure in units of 100millibar, or temperature in units of 100degreeCelsius. _sensor must be Barometer.

void plutoLoop ( void ) {
    int32_t pressure = Sensor_Get ( Barometer, Pressure );      // 100 * mbar
    int32_t temp     = Sensor_Get ( Barometer, Temperature );   // 100 * degC
    Monitor_Print ( "Pressure: ", pressure );
}

int16_t Estimate_Get(FC_Estimate_e _estimateOf, axis_e _axis)

Returns a Rate, Position, or Velocity estimate for the X, Y, or Z axis (for Position, Z is altitude).

void plutoLoop ( void ) {
    int16_t altitude = Estimate_Get ( Position, Z );   // altitude
    int16_t yawRate  = Estimate_Get ( Rate, Z );       // yaw rate
    Monitor_Print ( "Altitude: ", altitude );
}

Warning: Velocity estimates are only valid when localization sensors (GPS, optical flow, UWB, etc.) are in use.

int16_t Estimate_Get(FC_Estimate_e _estimateOf, angle_e _angle)

Returns an attitude angle. _estimateOf must be Angle. Roll and pitch are in deciDegrees; yaw (heading) is in degrees.

void plutoLoop ( void ) {
    int16_t roll    = Estimate_Get ( Angle, AG_ROLL );    // deciDegrees
    int16_t pitch   = Estimate_Get ( Angle, AG_PITCH );   // deciDegrees
    int16_t heading = Estimate_Get ( Angle, AG_YAW );     // degrees
    Monitor_Print ( "Heading: ", heading );
}

Usage Example

Sensor and estimate values are live, so read them every loop in plutoLoop().

#include "PlutoPilot.h"

void plutoLoop ( void ) {
    // Raw IMU
    int32_t accelX = Sensor_Get ( Accelerometer, X );
    int32_t gyroZ  = Sensor_Get ( Gyroscope, Z );

    // Barometer
    int32_t pressure = Sensor_Get ( Barometer, Pressure );   // 100 * mbar

    // Fused attitude estimates
    int16_t roll     = Estimate_Get ( Angle, AG_ROLL );      // deciDegrees
    int16_t heading  = Estimate_Get ( Angle, AG_YAW );       // degrees
    int16_t altitude = Estimate_Get ( Position, Z );         // altitude

    Monitor_Print ( "Roll: ",     roll );
    Monitor_Print ( "Heading: ",  heading );
    Monitor_Print ( "Altitude: ", altitude );
}

Clone this wiki locally