-
Notifications
You must be signed in to change notification settings - Fork 7
FC Control
Flight control system for managing flight status, flight modes, and high-level commands (arm, take-off, land, flip).
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;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;Used by Command_Flip().
typedef enum {
BACK_FLIP // Back flip direction
} flip_direction_e;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 );
}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();
}
}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" );
}
}Sets the active flight mode. Set it once on entry in onLoopStart().
void onLoopStart ( void ) {
FlightMode_Set ( ANGLE ); // stabilized flight
}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
}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 );
}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;
}
}Arms the system if arming conditions are met. Returns true if armed.
void onLoopStart ( void ) {
if ( Command_Arm() ) {
Monitor_Println ( "Armed" );
}
}Disarms the system. Returns true if disarmed. Good fit for onLoopFinish().
void onLoopFinish ( void ) {
Command_DisArm();
}Sets the reference heading for head-free mode. Set it once in onLoopStart().
void onLoopStart ( void ) {
setheadFreeModeHeading ( 0 ); // lock current forward as reference
}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();
}MagisV2 © 2026 Drona Aviation | Licensed under GPL-3.0 | Report Issues