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

Sensor calibrations of protocol v2 (HANDOVER_FW.md §10). More...

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

Go to the source code of this file.

Data Structures

struct  cal_accel_t
 
struct  cal_level_t
 
struct  cal_gyro_t
 
struct  cal_compass_t
 
struct  cal_motors_t
 
struct  cal_battery_t
 
struct  cal_set_t
 
struct  cal_sample_t
 
struct  cal_config_t
 

Typedefs

typedef void(* cal_apply_fn) (uint8_t type, const cal_set_t *set)
 apply hook: puts 'type' of 'set' in effect (RAM), in the estimator context
 
typedef void(* cal_batt_fn) (float *vbat, float *last_used_mah, float *last_scale_i)
 battery readings for the BATTERY calibration (AppTask context): vbat with the scale in effect, and the last flight's charge with the current scale it was counted with
 

Functions

void cal_set_defaults (cal_set_t *s, const float mag_hi_default[3])
 
void cal_copy_type (cal_set_t *dst, const cal_set_t *src, uint8_t type)
 copies the part of 'src' that belongs to 'type' into 'dst'
 
void cal_init (const cal_config_t *cfg, cal_set_t *active)
 active: the set in effect (RAM), owned by the caller.
 
void cal_set_sensors (uint16_t sensors)
 expansion board detected later
 
uint8_t cal_start (uint8_t type, uint8_t option, uint8_t armed, uint32_t now_ms, uint8_t *reason)
 
uint8_t cal_capture (uint32_t now_ms, uint8_t *reason)
 
uint8_t cal_abort (uint8_t *reason)
 
uint8_t cal_set_ref (uint8_t type, uint8_t index, float value, uint8_t *reason)
 
uint8_t cal_save_check (uint8_t *reason)
 CAL_SAVE validation: returns the ACK; on OK the caller writes the result (cal_result()) to flash and then calls cal_saved()
 
const cal_set_t * cal_result (void)
 
uint8_t cal_type (void)
 
void cal_saved (void)
 state SAVED (one frame), then IDLE
 
void cal_feed (const cal_sample_t *s, uint32_t now_ms)
 
void cal_tick (uint32_t now_ms)
 
uint8_t cal_active (void)
 a calibration exists (any state but IDLE)
 
uint8_t cal_running (void)
 active and not DONE: blocks arming / other starts
 
uint8_t cal_wants_samples (void)
 
uint8_t cal_take_changed (void)
 1 if the state/step changed since the last call (send a CALIB frame now)
 
uint8_t cal_take_failed (void)
 1 + type once when a calibration failed (EVENT 51), 0 otherwise
 
size_t cal_frame (uint8_t *out, size_t cap)
 CALIB frame for the current calibration; 0 if none.
 

Detailed Description

Sensor calibrations of protocol v2 (HANDOVER_FW.md §10).

Runs in the AppTask. The ImuTask streams raw samples (calibration removed) while a calibration is active; fits run here, never in the flight loop. Results go to RAM through the apply hook (the estimator takes them in the ImuTask context); CAL_SAVE makes the AppTask write them to flash and keep the previous set as the backup for CAL_RESTORE.

Available on the current hardware (LSM6DSV16X + LIS2MDL): 1 ACCEL six positions, 2 LEVEL trim, 3 GYRO bias, 4 COMPASS (FC compass). Not built (REJECTED / SENSOR_MISSING): 5 FLOW_TOF, 6 BATTERY, 8 STICKS, and 7 MOTORS while the motor outputs are disabled.

Host-testable: no HAL, no RTOS.

Definition in file calib_mgr.h.

Typedef Documentation

◆ cal_apply_fn

typedef void(* cal_apply_fn) (uint8_t type, const cal_set_t *set)

apply hook: puts 'type' of 'set' in effect (RAM), in the estimator context

Definition at line 57 of file calib_mgr.h.

◆ cal_batt_fn

typedef void(* cal_batt_fn) (float *vbat, float *last_used_mah, float *last_scale_i)

battery readings for the BATTERY calibration (AppTask context): vbat with the scale in effect, and the last flight's charge with the current scale it was counted with

Definition at line 62 of file calib_mgr.h.

Function Documentation

◆ cal_set_defaults()

void cal_set_defaults ( cal_set_t *  s,
const float  mag_hi_default[3] 
)

Definition at line 60 of file calib_mgr.c.

References s.

Referenced by app_task_boot(), and cal_from_v1().

Here is the caller graph for this function:

◆ cal_copy_type()

void cal_copy_type ( cal_set_t *  dst,
const cal_set_t *  src,
uint8_t  type 
)

copies the part of 'src' that belongs to 'type' into 'dst'

Definition at line 72 of file calib_mgr.c.

References cal_set_t::accel, cal_set_t::battery, bit(), cal_set_t::compass, cal_set_t::done_mask, cal_set_t::gyro, cal_set_t::level, cal_set_t::motors, PV2_CAL_ACCEL, PV2_CAL_BATTERY, PV2_CAL_COMPASS, PV2_CAL_GYRO, PV2_CAL_LEVEL, PV2_CAL_MOTORS, and s.

Referenced by apply(), ImuTask(), local_cmd(), and take_calibrations().

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

◆ cal_init()

void cal_init ( const cal_config_t *  cfg,
cal_set_t *  active 
)

active: the set in effect (RAM), owned by the caller.

DONE applies the new values to it (and to the estimator through the hook); ABORT, a failure or a lost app link put the previous values back.

Definition at line 89 of file calib_mgr.c.

References PV2_CS_IDLE, s_active, s_applied, s_cfg, s_changed, s_failed_type, s_state, and s_type.

Referenced by app_init().

Here is the caller graph for this function:

◆ cal_set_sensors()

void cal_set_sensors ( uint16_t  sensors)

expansion board detected later

Definition at line 87 of file calib_mgr.c.

References s_cfg, and cal_config_t::sensors.

Referenced by app_step().

Here is the caller graph for this function:

◆ cal_start()

uint8_t cal_start ( uint8_t  type,
uint8_t  option,
uint8_t  armed,
uint32_t  now_ms,
uint8_t *  reason 
)

Definition at line 150 of file calib_mgr.c.

References A, B, cal_config_t::batt, C, cal_running(), G, GYRO_MS, L, cal_set_t::level, LEVEL_MS, cal_config_t::motors_built, cal_level_t::pitch_deg, PV2_ACK_BUSY, PV2_ACK_INVALID, PV2_ACK_OK, PV2_ACK_REJECTED, PV2_ACK_UNSUPPORTED, PV2_CAL_ACCEL, PV2_CAL_BATTERY, PV2_CAL_COMPASS, PV2_CAL_FLOW_TOF, PV2_CAL_GYRO, PV2_CAL_LEVEL, PV2_CAL_MOTORS, PV2_CAL_STICKS, PV2_CS_DONE, PV2_CS_IDLE, PV2_CS_RUNNING, PV2_CS_WAITING_USER, PV2_R_ARMED, PV2_R_CALIBRATING, PV2_R_NONE, PV2_R_SENSOR_MISSING, PV2_S_CURRENT, PV2_S_ELRS, PV2_S_FLOW, PV2_S_MAG_FC, revert(), cal_level_t::roll_deg, s_active, s_applied, s_cfg, s_changed, s_now, s_prev, s_progress, s_quality, s_reason, s_res, s_state, s_step, s_t0, s_type, cal_config_t::sensors, and set_state().

Referenced by local_cmd().

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

◆ cal_capture()

uint8_t cal_capture ( uint32_t  now_ms,
uint8_t *  reason 
)

Definition at line 528 of file calib_mgr.c.

References A, accel_capture_pos(), accel_position(), cal_active(), pos, PV2_ACK_INVALID, PV2_ACK_OK, PV2_ACK_REJECTED, PV2_CAL_ACCEL, PV2_CAL_BATTERY, PV2_CS_DONE, PV2_CS_WAITING_USER, PV2_R_NONE, PV2_R_NOT_CALIBRATING, PV2_R_NOT_STILL, s_state, s_type, set_state(), and STILL_GYRO.

Referenced by local_cmd().

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

◆ cal_abort()

uint8_t cal_abort ( uint8_t *  reason)

Definition at line 221 of file calib_mgr.c.

References cal_active(), PV2_ACK_OK, PV2_ACK_REJECTED, PV2_CS_IDLE, PV2_R_NONE, PV2_R_NOT_CALIBRATING, revert(), s_state, and s_type.

Referenced by calibration(), and local_cmd().

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

◆ cal_set_ref()

uint8_t cal_set_ref ( uint8_t  type,
uint8_t  index,
float  value,
uint8_t *  reason 
)

Definition at line 547 of file calib_mgr.c.

References apply(), B, cal_set_t::battery, cal_active(), cal_set_t::level, cal_level_t::pitch_deg, PV2_ACK_INVALID, PV2_ACK_OK, PV2_ACK_REJECTED, PV2_CAL_BATTERY, PV2_CAL_LEVEL, PV2_CS_DONE, PV2_CS_WAITING_USER, PV2_R_NONE, PV2_R_NOT_CALIBRATING, PV2_R_OUT_OF_RANGE, PV2_R_SENSOR_MISSING, cal_level_t::roll_deg, s_applied, s_changed, s_res, s_state, s_type, cal_battery_t::scale_i, cal_battery_t::scale_v, and set_state().

Referenced by local_cmd().

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

◆ cal_save_check()

uint8_t cal_save_check ( uint8_t *  reason)

CAL_SAVE validation: returns the ACK; on OK the caller writes the result (cal_result()) to flash and then calls cal_saved()

Definition at line 230 of file calib_mgr.c.

References cal_active(), cal_set_t::done_mask, PV2_ACK_OK, PV2_ACK_REJECTED, PV2_CAL_MOTORS, PV2_CS_DONE, PV2_R_NONE, PV2_R_NOT_CALIBRATING, s_active, s_res, s_state, and s_type.

Referenced by local_cmd().

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

◆ cal_result()

const cal_set_t * cal_result ( void  )

Definition at line 134 of file calib_mgr.c.

References s_res.

Referenced by local_cmd().

Here is the caller graph for this function:

◆ cal_type()

uint8_t cal_type ( void  )

Definition at line 133 of file calib_mgr.c.

References s_type.

Referenced by local_cmd().

Here is the caller graph for this function:

◆ cal_saved()

void cal_saved ( void  )

state SAVED (one frame), then IDLE

Definition at line 242 of file calib_mgr.c.

References PV2_CS_SAVED, s_applied, s_step, and set_state().

Referenced by local_cmd().

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

◆ cal_feed()

void cal_feed ( const cal_sample_t *  s,
uint32_t  now_ms 
)

Definition at line 507 of file calib_mgr.c.

References accel_feed(), cal_wants_samples(), compass_feed(), gyro_feed(), level_feed(), PV2_CAL_ACCEL, PV2_CAL_COMPASS, PV2_CAL_GYRO, PV2_CAL_LEVEL, s, s_now, and s_type.

Referenced by calibration().

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

◆ cal_tick()

void cal_tick ( uint32_t  now_ms)

Definition at line 520 of file calib_mgr.c.

References B, cal_config_t::batt, PV2_CAL_BATTERY, PV2_CS_DONE, PV2_CS_WAITING_USER, s_cfg, s_now, s_state, and s_type.

Referenced by calibration().

Here is the caller graph for this function:

◆ cal_active()

uint8_t cal_active ( void  )

a calibration exists (any state but IDLE)

Definition at line 131 of file calib_mgr.c.

References PV2_CS_IDLE, and s_state.

Referenced by cal_abort(), cal_capture(), cal_frame(), cal_save_check(), cal_set_ref(), and calibration().

Here is the caller graph for this function:

◆ cal_running()

uint8_t cal_running ( void  )

active and not DONE: blocks arming / other starts

Definition at line 132 of file calib_mgr.c.

References PV2_CS_DONE, PV2_CS_IDLE, and s_state.

Referenced by app_step(), cal_start(), and local_cmd().

Here is the caller graph for this function:

◆ cal_wants_samples()

uint8_t cal_wants_samples ( void  )

Definition at line 136 of file calib_mgr.c.

References PV2_CS_RUNNING, PV2_CS_WAITING_USER, and s_state.

Referenced by cal_feed(), and calibration().

Here is the caller graph for this function:

◆ cal_take_changed()

uint8_t cal_take_changed ( void  )

1 if the state/step changed since the last call (send a CALIB frame now)

Definition at line 141 of file calib_mgr.c.

References s_changed.

Referenced by calibration().

Here is the caller graph for this function:

◆ cal_take_failed()

uint8_t cal_take_failed ( void  )

1 + type once when a calibration failed (EVENT 51), 0 otherwise

Definition at line 143 of file calib_mgr.c.

References s_failed_type.

Referenced by events().

Here is the caller graph for this function:

◆ cal_frame()

size_t cal_frame ( uint8_t *  out,
size_t  cap 
)

CALIB frame for the current calibration; 0 if none.

Definition at line 592 of file calib_mgr.c.

References A, cal_set_t::accel, B, b, cal_set_t::battery, C, cal_active(), cap, cl16(), clu16(), G, L, cal_set_t::level, n, cal_accel_t::off, cal_level_t::pitch_deg, PV2_CAL_ACCEL, PV2_CAL_BATTERY, PV2_CAL_COMPASS, PV2_CAL_GYRO, PV2_CAL_LEVEL, pv2_calib(), PV2_CS_DONE, PV2_CS_IDLE, PV2_CS_SAVED, R2D, cal_level_t::roll_deg, s_active, s_progress, s_quality, s_reason, s_res, s_state, s_step, s_type, cal_accel_t::scale, cal_battery_t::scale_i, and cal_battery_t::scale_v.

Referenced by send_calib().

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