Skip to content

FC Config

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

FC-Config.h

Flight controller configuration: loop frequency, PID tuning, desired angle/rate/position setpoints, and failsafe control.

Structures

PID

Holds the three gains for one PID controller.

typedef struct {
    uint8_t p;    // Proportional gain
    uint8_t i;    // Integral gain
    uint8_t d;    // Derivative gain
} PID;

Enumerations

pid_profile_e

Selects which controller get_PIDProfile() / set_PIDProfile() acts on.

typedef enum {
    PID_ROLL,     // Roll axis PID
    PID_PITCH,    // Pitch axis PID
    PID_YAW,      // Yaw axis PID
    PID_ALT,      // Altitude PID
    PID_USER      // User-defined PID
} pid_profile_e;

failsafe_e

Selects which failsafe Failsafe_enable() / Failsafe_disable() acts on.

typedef enum {
    LOW_BATTERY,          // Low battery failsafe
    INFLIGHT_LOW_BATTERY, // In-flight low battery failsafe
    CRASH,                // Crash detection failsafe
    ALL                   // All failsafes at once
} failsafe_e;

Parameter enums

The angle and position functions below take these enums (defined in axis.h):

typedef enum { AG_ROLL = 0, AG_PITCH, AG_YAW } angle_e;   // used by angle/rate functions
typedef enum { X = 0, Y, Z, Net_Acc } axis_e;             // position functions act on Z (altitude) only

Functions

void setUserLoopFrequency(float frequency)

Sets the main control loop frequency in Hz (clamped to 3.5 - 2000 Hz). Set it once at startup.

void plutoInit ( void ) {
    setUserLoopFrequency ( 100.0f );   // run the control loop at 100 Hz
}

void get_PIDProfile(pid_profile_e PROFILE, PID *pid)

Reads the current gains for a profile into your PID struct. Handy as a one-time readout in onLoopStart() (runs when Developer Mode activates, so the monitor is attached).

void onLoopStart ( void ) {
    PID roll;
    get_PIDProfile ( PID_ROLL, &roll );
    Monitor_Print ( "Roll P: ", roll.p );
}

void set_PIDProfile(pid_profile_e PROFILE, PID *pid)

Writes new gains for a profile. Tune once at startup.

void plutoInit ( void ) {
    PID rollPID = { 50, 25, 15 };      // p, i, d
    set_PIDProfile ( PID_ROLL, &rollPID );
}

void setDefault_PIDProfile(void)

Resets every PID profile back to its default gains.

void plutoInit ( void ) {
    setDefault_PIDProfile();
}

int32_t getDesiredAngle(angle_e ANGLE)

Returns the current desired angle (in deci-degrees) for roll, pitch, or yaw.

void plutoLoop ( void ) {
    int32_t rollTarget = getDesiredAngle ( AG_ROLL );   // deci-degrees
    Monitor_Print ( "Roll target: ", rollTarget );
}

void setDesiredAngle(angle_e ANGLE, int32_t angle)

Commands a desired angle in deci-degrees (150 = 15 degrees). Set every loop.

void plutoLoop ( void ) {
    setDesiredAngle ( AG_ROLL, 150 );    // lean 15 degrees right
    setDesiredAngle ( AG_PITCH, -100 );  // pitch 10 degrees forward
}

int32_t getDesiredRate(angle_e ANGLE)

Returns the current desired rotational rate for the given axis.

void plutoLoop ( void ) {
    int32_t yawRate = getDesiredRate ( AG_YAW );
    Monitor_Print ( "Yaw rate: ", yawRate );
}

void setDesiredRate(angle_e ANGLE, int32_t rate)

Commands a desired rotational rate for the given axis (used in ACRO/rate mode).

void plutoLoop ( void ) {
    setDesiredRate ( AG_YAW, 200 );   // rotate about yaw
}

int32_t getDesiredPositions(axis_e AXIS)

Returns the desired position for an axis. Only Z (altitude) is meaningful; other axes return 0.

void plutoLoop ( void ) {
    int32_t targetAlt = getDesiredPositions ( Z );   // desired altitude
    Monitor_Print ( "Target alt: ", targetAlt );
}

void setDesiredPosition(axis_e AXIS, int32_t position)

Sets an absolute desired position. Acts on Z (altitude) only; other axes are ignored.

void plutoLoop ( void ) {
    setDesiredPosition ( Z, 100 );   // hold 100 cm altitude
}

void DesiredPosition_setRelative(axis_e AXIS, int32_t position)

Adjusts the desired position relative to the current one. Acts on Z only.

void plutoLoop ( void ) {
    DesiredPosition_setRelative ( Z, 20 );   // climb 20 cm from current target
}

void Failsafe_enable(failsafe_e FAILSAFE)

Enables a failsafe (or ALL). A one-time enable, so do it in onLoopStart().

void onLoopStart ( void ) {
    Failsafe_enable ( LOW_BATTERY );
    Failsafe_enable ( CRASH );
}

void Failsafe_disable(failsafe_e FAILSAFE)

Disables a failsafe (or ALL).

void onLoopStart ( void ) {
    Failsafe_disable ( CRASH );   // disable crash failsafe
}

Usage Example

#include "PlutoPilot.h"

// Power-up: hardware config that must always apply.
void plutoInit ( void ) {
    setUserLoopFrequency ( 100.0f );        // 100 Hz control loop

    PID rollPID = { 50, 25, 15 };           // custom roll tuning
    set_PIDProfile ( PID_ROLL, &rollPID );
}

// Dev button pressed: one-time enables before the loop starts.
void onLoopStart ( void ) {
    Failsafe_enable ( LOW_BATTERY );        // arm the failsafes
    Failsafe_enable ( CRASH );
}

// Runs every loop while Developer Mode is active.
void plutoLoop ( void ) {
    setDesiredAngle ( AG_ROLL, 150 );       // 15 degrees roll
    setDesiredAngle ( AG_PITCH, -100 );     // -10 degrees pitch
    setDesiredPosition ( Z, 120 );          // hold 120 cm altitude
}

Clone this wiki locally