ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
Loading...
Searching...
No Matches
fc_core.h File Reference

Flight core: arming, modes, automatic actions, failsafes, motor test (HANDOVER_FW.md §6, §7, §10.7). More...

#include <stdint.h>
Include dependency graph for fc_core.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  fc_cmd_t
 
struct  fc_res_t
 
struct  fc_event_t
 
struct  fc_batt_sig_t
 battery signal (BattTask -> core): sent when the level or presence changes More...
 
struct  fc_config_t
 
struct  fc_state_t
 published state (AppTask builds FLIGHT / MOTORS from it) More...
 
struct  fc_vert_t
 vertical state from the estimator (flight-control context) More...
 
struct  fc_setpoint_t
 setpoints for the attitude / rate loops (phase 3) and the motor mixer More...
 

Macros

#define FC_RC_STALE_MS   250u
 stop using the last RC values

 
#define FC_FS_SHORT_MS   1000u
 fsAppShort

 
#define FC_FS_LONG_MS   3000u
 fsAppLong + EVENT 20

 
#define FC_LINK_BACK_MS   500u
 link considered back

 
#define FC_GROUND_DISARM_MS   3000u
 armed on the ground, app silent

 
#define FC_ARM_RC_FRESH_MS   500u
 throttle rule applies to RC this recent
 
#define FC_NO_TAKEOFF_MS   10000u
 auto-disarm if not taken off

 
#define FC_STICK_CANCEL   300
 30 % of the stick

 
#define FC_TAKEOFF_VZ   0.6f
 m/s, climb during TAKEOFF

 
#define FC_LIFTOFF_DH   0.15f
 m above the ground level = airborne

 
#define FC_LIFTOFF_TIMEOUT_MS   6000u
 no lift-off -> TAKEOFF aborted

 
#define FC_LAND_SLOW_VZ   0.3f
 m/s below 1 m with ToF

 
#define FC_TOUCH_VZ   0.12f
 |vz| below this ...

 
#define FC_TOUCH_MS   700u
 ... for this long (descent commanded)

 
#define FC_TOUCH_MS_NO_TOF   1000u
 
#define FC_FLOW_LOST_Q   30u
 flow quality below this ...

 
#define FC_FLOW_BACK_Q   40u
 
#define FC_FLOW_LOST_MS   500u
 
#define FC_FLOW_CHECK_H
 
#define FC_BATT_STALE_MS   1000u
 no BattTask heartbeat: battery unknown

 
#define FC_OP_MOTOR_STOP   0xF0u
 stop a running motor test

 

Functions

void fc_init (const fc_config_t *cfg)
 
void fc_set_sensors (uint16_t sensors)
 sensors detected at run time (a late expansion board): atomic store
 
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)
 
void fc_setpoint (fc_setpoint_t *out)
 last setpoints, same context
 
int fc_batt_signal (const fc_batt_sig_t *s)
 0 = queued, -1 = full

 
void fc_batt_heartbeat (uint32_t now_ms)
 every BattTask step

 
int fc_post (const fc_cmd_t *c)
 0 = queued, -1 = full

 
int fc_take_result (fc_res_t *r)
 1 if a result was taken
 
int fc_take_event (fc_event_t *e)
 
void fc_snapshot (fc_state_t *out)
 
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)
 
uint8_t fc_is_core_op (uint8_t op)
 ops executed by the core
 

Variables

volatile uint8_t g_fc_dbg_in_air
 

Detailed Description

Flight core: arming, modes, automatic actions, failsafes, motor test (HANDOVER_FW.md §6, §7, §10.7).

Runs ONLY in the flight-control context: fc_service() is called by the ImuTask, the loop that runs the estimator and the attitude controller (>= 50 Hz, about 250 Hz here). The flight state has a single owner and no lock: the AppTask talks to it through lock-free single-producer single-consumer queues AppTask -> core commands (fc_post) core -> AppTask ACK results (fc_take_result) core -> AppTask events (fc_take_event) core -> AppTask state (fc_snapshot, sequence counter) and reads the app link only through app_link.h (an atomic timestamp and the RC seqlock). Nothing here waits on BLE: if the BLE stack, the CPU2, the radio or the AppTask stall, the app-link silence grows and the failsafe fires on time.

Host-testable: no HAL, no RTOS (time is passed in, outputs via hooks).

Definition in file fc_core.h.

Macro Definition Documentation

◆ FC_RC_STALE_MS

#define FC_RC_STALE_MS   250u

stop using the last RC values

Definition at line 28 of file fc_core.h.

◆ FC_FS_SHORT_MS

#define FC_FS_SHORT_MS   1000u

fsAppShort

Definition at line 29 of file fc_core.h.

◆ FC_FS_LONG_MS

#define FC_FS_LONG_MS   3000u

fsAppLong + EVENT 20

Definition at line 30 of file fc_core.h.

◆ FC_LINK_BACK_MS

#define FC_LINK_BACK_MS   500u

link considered back

Definition at line 31 of file fc_core.h.

◆ FC_GROUND_DISARM_MS

#define FC_GROUND_DISARM_MS   3000u

armed on the ground, app silent

Definition at line 32 of file fc_core.h.

◆ FC_ARM_RC_FRESH_MS

#define FC_ARM_RC_FRESH_MS   500u

throttle rule applies to RC this recent

Definition at line 33 of file fc_core.h.

◆ FC_NO_TAKEOFF_MS

#define FC_NO_TAKEOFF_MS   10000u

auto-disarm if not taken off

Definition at line 34 of file fc_core.h.

◆ FC_STICK_CANCEL

#define FC_STICK_CANCEL   300

30 % of the stick

Definition at line 35 of file fc_core.h.

◆ FC_TAKEOFF_VZ

#define FC_TAKEOFF_VZ   0.6f

m/s, climb during TAKEOFF

Definition at line 37 of file fc_core.h.

◆ FC_LIFTOFF_DH

#define FC_LIFTOFF_DH   0.15f

m above the ground level = airborne

Definition at line 38 of file fc_core.h.

◆ FC_LIFTOFF_TIMEOUT_MS

#define FC_LIFTOFF_TIMEOUT_MS   6000u

no lift-off -> TAKEOFF aborted

Definition at line 39 of file fc_core.h.

◆ FC_LAND_SLOW_VZ

#define FC_LAND_SLOW_VZ   0.3f

m/s below 1 m with ToF

Definition at line 40 of file fc_core.h.

◆ FC_TOUCH_VZ

#define FC_TOUCH_VZ   0.12f

|vz| below this ...

Definition at line 41 of file fc_core.h.

◆ FC_TOUCH_MS

#define FC_TOUCH_MS   700u

... for this long (descent commanded)

Definition at line 42 of file fc_core.h.

◆ FC_TOUCH_MS_NO_TOF

#define FC_TOUCH_MS_NO_TOF   1000u

Definition at line 43 of file fc_core.h.

◆ FC_FLOW_LOST_Q

#define FC_FLOW_LOST_Q   30u

flow quality below this ...

Definition at line 44 of file fc_core.h.

◆ FC_FLOW_BACK_Q

#define FC_FLOW_BACK_Q   40u

Definition at line 45 of file fc_core.h.

◆ FC_FLOW_LOST_MS

#define FC_FLOW_LOST_MS   500u

Definition at line 46 of file fc_core.h.

◆ FC_FLOW_CHECK_H

#define FC_FLOW_CHECK_H
Value:
0.15f /* m: FLOW_LOST is judged only above this height,
never on the ground, in TAKEOFF or LAND */

Definition at line 47 of file fc_core.h.

◆ FC_BATT_STALE_MS

#define FC_BATT_STALE_MS   1000u

no BattTask heartbeat: battery unknown

Definition at line 50 of file fc_core.h.

◆ FC_OP_MOTOR_STOP

#define FC_OP_MOTOR_STOP   0xF0u

stop a running motor test

Definition at line 53 of file fc_core.h.

Function Documentation

◆ fc_init()

void fc_init ( const fc_config_t *  cfg)

Definition at line 71 of file fc_core.c.

References alt_ctrl_init(), fc_config_t::batt_monitor, g_fc_dbg_in_air, fc_config_t::n_motors, PV2_BATT_OK, PV2_MODE_ANGLE, s_ac, s_armed, s_auto, s_batt_fail, s_batt_have_hb, s_batt_hb_set, s_batt_level, s_batt_lock, s_batt_present, s_batt_stale, s_calibrating, s_cfg, s_checks_ready, s_dbg_forced, s_failsafe, s_flight_ms, s_flow_bad_ms, s_fs_long, s_fs_short_hold, s_geofence, s_geofence_ev, s_have_last, s_have_rc, s_have_v, s_in_air, s_landed, s_mode, s_sensors, s_sp, s_test_motor, s_took_off, s_touch_ms, fc_config_t::sensors, and spsc_reset().

Referenced by app_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fc_set_sensors()

void fc_set_sensors ( uint16_t  sensors)

sensors detected at run time (a late expansion board): atomic store

Definition at line 97 of file fc_core.c.

References s_sensors.

Referenced by app_init(), and app_step().

Here is the caller graph for this function:

◆ fc_service()

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 at line 699 of file fc_core.c.

References air_ground(), app_link_failsafe(), battery(), disarm(), exec(), FC_FS_SHORT_MS, FC_LINK_BACK_MS, FC_NO_TAKEOFF_MS, FC_STICK_CANCEL, flow_failsafe(), fc_vert_t::flow_q, P_AUTO_DISARM, P_RTH_STICK_CANCEL, PARAM, appl_rc_t::pitch, publish(), PV2_AUTO_HOLD, PV2_AUTO_NONE, PV2_AUTO_RTH, PV2_FS_APP_LINK, appl_rc_t::roll, s_arm_ms, s_armed, s_auto, s_failsafe, s_flight_ms, s_have_last, s_have_v, s_in_air, s_landed_ms, s_last_ms, s_rc, s_rc_stale, s_silence, s_test_motor, s_test_until, s_took_off, s_v, setpoints(), spsc_pop(), stick_moved(), test_stop(), update_sticks(), and fc_vert_t::valid.

Referenced by flight_service(), and ImuTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fc_setpoint()

void fc_setpoint ( fc_setpoint_t *  out)

last setpoints, same context

Definition at line 98 of file fc_core.c.

References s_sp.

Referenced by flight_service().

Here is the caller graph for this function:

◆ fc_batt_signal()

int fc_batt_signal ( const fc_batt_sig_t *  s)

0 = queued, -1 = full

Definition at line 94 of file fc_core.c.

References b, and spsc_push().

Referenced by batt_task_step().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fc_batt_heartbeat()

void fc_batt_heartbeat ( uint32_t  now_ms)

every BattTask step

Definition at line 95 of file fc_core.c.

References s_batt_hb_ms, s_batt_hb_set, and SPSC_BARRIER.

Referenced by batt_task_step().

Here is the caller graph for this function:

◆ fc_post()

int fc_post ( const fc_cmd_t *  c)

0 = queued, -1 = full

Definition at line 112 of file fc_core.c.

References spsc_push().

Referenced by commands().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fc_take_result()

int fc_take_result ( fc_res_t *  r)

1 if a result was taken

Definition at line 113 of file fc_core.c.

References spsc_pop().

Referenced by commands().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fc_take_event()

int fc_take_event ( fc_event_t *  e)

Definition at line 114 of file fc_core.c.

References spsc_pop().

Referenced by events().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fc_snapshot()

void fc_snapshot ( fc_state_t *  out)

Definition at line 121 of file fc_core.c.

References s_snap, s_snap_seq, and SPSC_BARRIER.

Referenced by armed_now(), batt_task_step(), build_checks(), log_records(), log_task_step(), send_flight(), and send_motors().

Here is the caller graph for this function:

◆ fc_set_ground_info()

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 at line 116 of file fc_core.c.

References s_batt_fail, s_calibrating, and s_checks_ready.

Referenced by app_step().

Here is the caller graph for this function:

◆ fc_is_core_op()

uint8_t fc_is_core_op ( uint8_t  op)

ops executed by the core

Definition at line 100 of file fc_core.c.

References FC_OP_MOTOR_STOP, PV2_OP_ARM, PV2_OP_DISARM, PV2_OP_HOLD, PV2_OP_KILL, PV2_OP_LAND, PV2_OP_MOTOR_TEST, PV2_OP_RTH, PV2_OP_SET_MODE, and PV2_OP_TAKEOFF.

Referenced by commands().

Here is the caller graph for this function:

Variable Documentation

◆ g_fc_dbg_in_air

volatile uint8_t g_fc_dbg_in_air
extern

Definition at line 17 of file fc_core.c.

Referenced by air_ground(), and fc_init().