-
Notifications
You must be signed in to change notification settings - Fork 7
FC Config
Flight controller configuration: loop frequency, PID tuning, desired angle/rate/position setpoints, and failsafe control.
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;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;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;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) onlySets 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
}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 );
}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 );
}Resets every PID profile back to its default gains.
void plutoInit ( void ) {
setDefault_PIDProfile();
}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 );
}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
}Returns the current desired rotational rate for the given axis.
void plutoLoop ( void ) {
int32_t yawRate = getDesiredRate ( AG_YAW );
Monitor_Print ( "Yaw rate: ", yawRate );
}Commands a desired rotational rate for the given axis (used in ACRO/rate mode).
void plutoLoop ( void ) {
setDesiredRate ( AG_YAW, 200 ); // rotate about yaw
}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 );
}Sets an absolute desired position. Acts on Z (altitude) only; other axes are ignored.
void plutoLoop ( void ) {
setDesiredPosition ( Z, 100 ); // hold 100 cm altitude
}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
}Enables a failsafe (or ALL). A one-time enable, so do it in onLoopStart().
void onLoopStart ( void ) {
Failsafe_enable ( LOW_BATTERY );
Failsafe_enable ( CRASH );
}Disables a failsafe (or ALL).
void onLoopStart ( void ) {
Failsafe_disable ( CRASH ); // disable crash failsafe
}#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
}MagisV2 © 2026 Drona Aviation | Licensed under GPL-3.0 | Report Issues