ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
Loading...
Searching...
No Matches
fc_core.h
Go to the documentation of this file.
1
22#ifndef FC_CORE_H
23#define FC_CORE_H
24
25#include <stdint.h>
26
27/* ---- timing of the app-link supervision (§6) ---- */
28#define FC_RC_STALE_MS 250u
29#define FC_FS_SHORT_MS 1000u
30#define FC_FS_LONG_MS 3000u
31#define FC_LINK_BACK_MS 500u
32#define FC_GROUND_DISARM_MS 3000u
33#define FC_ARM_RC_FRESH_MS 500u
34#define FC_NO_TAKEOFF_MS 10000u
35#define FC_STICK_CANCEL 300
36/* ---- automatic flight (§7.2, §7.3) ---- */
37#define FC_TAKEOFF_VZ 0.6f
38#define FC_LIFTOFF_DH 0.15f
39#define FC_LIFTOFF_TIMEOUT_MS 6000u
40#define FC_LAND_SLOW_VZ 0.3f
41#define FC_TOUCH_VZ 0.12f
42#define FC_TOUCH_MS 700u
43#define FC_TOUCH_MS_NO_TOF 1000u
44#define FC_FLOW_LOST_Q 30u
45#define FC_FLOW_BACK_Q 40u
46#define FC_FLOW_LOST_MS 500u
47#define FC_FLOW_CHECK_H 0.15f /* m: FLOW_LOST is judged only above this height,
48 never on the ground, in TAKEOFF or LAND */
49
50/* ---- battery (§6): signals from the BattTask ---- */
51#define FC_BATT_STALE_MS 1000u
53/* internal opcodes (AppTask -> core), outside the v2 range */
54#define FC_OP_MOTOR_STOP 0xF0u
55typedef struct {
56 uint8_t op, seq, len;
57 uint8_t p[18];
58} fc_cmd_t;
60typedef struct { uint8_t op, seq, result, reason; } fc_res_t;
61typedef struct { uint8_t level; uint16_t code; int32_t arg; } fc_event_t;
62
64typedef struct {
65 uint8_t present;
66 uint8_t level;
67 uint16_t cell_mv;
70typedef struct {
71 uint16_t sensors;
72 uint8_t n_motors;
73 uint8_t motors_built;
75 void (*motors_arm)(uint8_t armed);
76 void (*motor_test)(uint8_t motor, float duty);
78 void (*on_event)(const fc_event_t *e);
79 uint8_t batt_monitor;
82 uint8_t (*usb_host)(void);
84
86typedef struct {
87 uint8_t armed, mode, autom, failsafe, input, in_air;
88 uint8_t rc_stale;
89 uint8_t fs_long;
90 uint16_t flight_time_s;
91 uint8_t motor_out_pct[8];
92 uint8_t test_motor;
93 uint8_t landed;
94 uint8_t geofence;
95 uint8_t batt_level;
96 uint8_t batt_stale;
97 int32_t alt_rel_cm;
98 int16_t vz_cms;
99 uint32_t silence_ms;
100 float stick[4];
101} fc_state_t;
102
104typedef struct {
105 uint8_t valid;
106 float h, vz;
107 uint8_t tof_valid, tof_ground;
108 float tof_h;
109 float cos_tilt;
110 uint8_t flow_q;
111 uint8_t flow_usable; /* flow valid: above the PMW3901 minimum
112 height (80 mm; landed it is ~11 mm) */
113} fc_vert_t;
114
116typedef struct {
117 uint8_t armed, mode, autom;
118 uint8_t alt_ctrl;
119 float thrust;
120 float roll, pitch;
121 float roll_rate, pitch_rate;
122 float yaw_rate;
123 float h_sp, vz_sp;
124 uint8_t pos_hold; /* hold the horizontal position (POS_HOLD or HOLD with
125 a usable position source); 0 near the floor, where
126 the flow is below its minimum height: level attitude */
128
129void fc_init(const fc_config_t *cfg);
131void fc_set_sensors(uint16_t sensors);
132
133/* ---- flight-control context ---- */
135void fc_service(uint32_t now_ms, uint8_t est_running, const fc_vert_t *v);
136void fc_setpoint(fc_setpoint_t *out);
138/* ---- BattTask ---- */
139int fc_batt_signal(const fc_batt_sig_t *s);
140void fc_batt_heartbeat(uint32_t now_ms);
142/* ---- AppTask ---- */
143int fc_post(const fc_cmd_t *c);
144int fc_take_result(fc_res_t *r);
146void fc_snapshot(fc_state_t *out);
148void fc_set_ground_info(uint8_t checks_ready, uint8_t battery_fail, uint8_t calibrating);
149uint8_t fc_is_core_op(uint8_t op);
151/* ---- bench test hooks (debugger Live Expressions) ----
152 * g_fc_dbg_in_air: 1 while armed forces "in the air" (props off!), so that
153 * the in-air failsafes can be tested on the bench without altitude sensors
154 * (HANDOVER §6 test, §16.12). Clearing it simulates the touchdown. With an
155 * altitude source, in air / on ground is detected from the vertical estimate
156 * and the board can be "flown" by hand (lift it: lift-off; put it down during
157 * LAND: touchdown). */
158extern volatile uint8_t g_fc_dbg_in_air;
159
160#endif /* FC_CORE_H */
static batt_state_t s
Definition battery.c:21
float roll
Definition calib_mgr.c:43
float pitch
Definition calib_mgr.c:43
static int valid(const cfg_image_t *im)
Definition cfg_store.c:54
static void result(const fc_cmd_t *c, uint8_t res, uint8_t why)
Definition fc_core.c:224
uint8_t fc_is_core_op(uint8_t op)
ops executed by the core
Definition fc_core.c:100
int fc_take_result(fc_res_t *r)
1 if a result was taken
Definition fc_core.c:113
int fc_batt_signal(const fc_batt_sig_t *s)
0 = queued, -1 = full
Definition fc_core.c:94
void fc_setpoint(fc_setpoint_t *out)
last setpoints, same context
Definition fc_core.c:98
void fc_set_ground_info(uint8_t checks_ready, uint8_t battery_fail, uint8_t calibrating)
ground information computed by the AppTask (atomic byte stores)
Definition fc_core.c:116
int fc_post(const fc_cmd_t *c)
0 = queued, -1 = full
Definition fc_core.c:112
void fc_init(const fc_config_t *cfg)
Definition fc_core.c:71
void fc_batt_heartbeat(uint32_t now_ms)
every BattTask step
Definition fc_core.c:95
void fc_set_sensors(uint16_t sensors)
sensors detected at run time (a late expansion board): atomic store
Definition fc_core.c:97
void fc_snapshot(fc_state_t *out)
Definition fc_core.c:121
int fc_take_event(fc_event_t *e)
Definition fc_core.c:114
volatile uint8_t g_fc_dbg_in_air
Definition fc_core.c:17
void fc_service(uint32_t now_ms, uint8_t est_running, const fc_vert_t *v)
v: NULL = no vertical estimate (in air only via g_fc_dbg_in_air)
Definition fc_core.c:699
uint8_t seq
Definition log_task.c:48
void motors_arm(uint8_t armed)
disarmed: duty forced to 0
Definition motors.c:24
battery signal (BattTask -> core): sent when the level or presence changes
Definition fc_core.h:63
setpoints for the attitude / rate loops (phase 3) and the motor mixer
Definition fc_core.h:115
published state (AppTask builds FLIGHT / MOTORS from it)
Definition fc_core.h:85
vertical state from the estimator (flight-control context)
Definition fc_core.h:103