Skip to content

FC Control

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

FC-Control.h

Flight control system for managing flight status, flight modes, and high-level commands (arm, take-off, land, flip).

Enumerations

flightstatus_e

Values returned by FlightStatus_Get() and checked with FlightStatus_Check().

typedef enum {
    FS_ACCEL_GYRO_CALIBRATION = 0,  // accel/gyro calibrating
    FS_MAG_CALIBARATION,            // magnetometer calibrating
    FS_LOW_BATTERY,                 // low battery
    FS_INFLIGHT_LOW_BATTERY,        // low battery while in flight
    FS_CRASHED,                     // crash detected
    FS_SIGNAL_LOSS,                 // control signal lost
    FS_NOT_OK_TO_ARM,               // arming not allowed
    FS_OK_TO_ARM,                   // safe to arm
    FS_ARMED                        // armed
} flightstatus_e;

flight_mode_e

Used by FlightMode_Check() and FlightMode_Set().

typedef enum {
    ANGLE,            // Angle mode: stabilized flight
    RATE,             // Rate mode: manual rate control
    MAGHOLD,          // Magnetic hold: maintain heading
    HEADFREE,         // Head-free mode: orientation-independent
    ATLTITUDEHOLD,    // Altitude hold: maintain altitude
    THROTTLE_MODE     // Throttle mode configuration
} flight_mode_e;

flip_direction_e

Used by Command_Flip().

typedef enum {
    BACK_FLIP    // Back flip direction
} flip_direction_e;

Functions

flightstatus_e FlightStatus_Get(void)

Returns the current flight status. Status changes continuously, so poll it in plutoLoop().

void plutoLoop ( void ) {
    flightstatus_e status = FlightStatus_Get();
    Monitor_Print ( "Status: ", status );
}

bool FlightStatus_Check(flightstatus_e status)

Returns true if the given status is currently active. Useful as an arming gate.

void onLoopStart ( void ) {
    if ( FlightStatus_Check ( FS_OK_TO_ARM ) ) {
        Command_Arm();
    }
}

bool FlightMode_Check(flight_mode_e MODE)

Returns true if the given flight mode is active. Poll it in plutoLoop().

void plutoLoop ( void ) {
    if ( FlightMode_Check ( ATLTITUDEHOLD ) ) {
        Monitor_Println ( "Altitude hold active" );
    }
}

void FlightMode_Set(flight_mode_e MODE)

Sets the active flight mode. Set it once on entry in onLoopStart().

void onLoopStart ( void ) {
    FlightMode_Set ( ANGLE );   // stabilized flight
}

void Command_TakeOff(uint16_t height = 150)

Commands a take-off to height (constrained to 100 - 250). A one-shot action, so trigger it in onLoopStart().

void onLoopStart ( void ) {
    Command_TakeOff ( 200 );   // take off to 200
}

void Command_Land(uint8_t landSpeed = 105)

Commands a landing at the given descent speed. Good fit for onLoopFinish() so the craft lands when Developer Mode is exited.

void onLoopFinish ( void ) {
    Command_Land ( 120 );
}

void Command_Flip(flip_direction_e direction)

Performs a flip maneuver. Trigger it once while armed (guard it so it does not re-fire every loop).

void plutoLoop ( void ) {
    static bool flipped = false;
    if ( !flipped && FlightStatus_Check ( FS_ARMED ) ) {
        Command_Flip ( BACK_FLIP );
        flipped = true;
    }
}

bool Command_Arm(void)

Arms the system if arming conditions are met. Returns true if armed.

void onLoopStart ( void ) {
    if ( Command_Arm() ) {
        Monitor_Println ( "Armed" );
    }
}

bool Command_DisArm(void)

Disarms the system. Returns true if disarmed. Good fit for onLoopFinish().

void onLoopFinish ( void ) {
    Command_DisArm();
}

void setheadFreeModeHeading(int16_t heading)

Sets the reference heading for head-free mode. Set it once in onLoopStart().

void onLoopStart ( void ) {
    setheadFreeModeHeading ( 0 );   // lock current forward as reference
}

Usage Example

A simple arm, take-off, monitor, then land-and-disarm sequence across the hooks.

#include "PlutoPilot.h"

// Dev button pressed: arm, set mode, and take off once.
void onLoopStart ( void ) {
    if ( FlightStatus_Check ( FS_OK_TO_ARM ) ) {
        Command_Arm();
        FlightMode_Set ( ANGLE );
        Command_TakeOff ( 200 );
    }
}

// While flying: monitor status.
void plutoLoop ( void ) {
    if ( FlightStatus_Check ( FS_ARMED ) ) {
        Monitor_Print ( "Status: ", FlightStatus_Get() );
    }
}

// Dev button released: land and disarm.
void onLoopFinish ( void ) {
    Command_Land ( 120 );
    Command_DisArm();
}

Clone this wiki locally