ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
Loading...
Searching...
No Matches
est_config.c
Go to the documentation of this file.
1
5#include "est_config.h"
6#include "app_config.h"
7#include <math.h>
8#include <string.h>
9
11{
12 memset(ec, 0, sizeof *ec);
13 ec->gyro_per_step = (APP_IMU_ODR == IMU_ODR_1920HZ) ? 2u : 1u;
27 ec->ekf.infl_decay = expf(-((float)APP_STEPS_PER_ACC / (float)APP_STEP_HZ) / IEKF_INFL_TAU_S);
30 {
31 const float hacc = (float)APP_STEPS_PER_ACC / (float)APP_STEP_HZ; /* s between acc updates */
33 ec->ekf.lockout_updates = (uint16_t)(IEKF_LOCKOUT_S / hacc + 0.5f);
35 ec->ekf.grace_updates = (uint16_t)(IEKF_GRACE_S / hacc + 0.5f);
36 ec->ekf.persist_decay = expf(-hacc / IEKF_PERSIST_TAU_S);
39 }
45 {
46 const float tsh = 1.0f / IMU_SH_HZ(APP_MAG_FAST);
47 ec->mag_latency_s = 0.5f * tsh;
48 ec->mag_latency_std_s = tsh * 0.288675f; /* 1/sqrt(12) */
49 }
50#if APP_COMPARE_ORIGINAL
51 ec->ekf.acc_nis_gate = 0.0f; ec->ekf.mag_nis_gate = 0.0f;
52 ec->ekf.dip_tol = 0.0f; ec->ekf.decouple = 0;
53 ec->ekf.reset_jacobian = 0; ec->still_time_s = 0.0f;
54 ec->ekf.lockout_updates = 0;
55 ec->ekf.tangent_innov = 0; /* the original iekfAttitude.m uses y - yhat */
56 ec->mag_latency_std_s = 0.0f; /* the MEAN-latency compensation stays: it is an input */
57#endif
58}
Phase-1 configuration: P-NUCLEO-WB55 (NUCLEO-WB55RG) + X-NUCLEO-IKS4A1 in Mode 3 (LSM6DSV16X is the s...
#define APP_CALIB_SAMPLES
mag samples at ~50 Hz -> ~2 s standing still
Definition app_config.h:26
#define IEKF_PERSIST_MIN
Definition app_config.h:77
#define APP_STILL_ACC_TOL
Definition app_config.h:91
#define IEKF_LOCKOUT_S
Definition app_config.h:72
#define IEKF_TANGENT_INNOV
Definition app_config.h:70
#define IEKF_GRACE_S
Definition app_config.h:74
#define APP_MAG_FAST
LIS2MDL 100 Hz, hub 120 Hz: halves the age of mag data.
Definition app_config.h:21
#define APP_CALIB_GYRO_STILL
Definition app_config.h:27
#define IEKF_ESTIMATE_BIAS
Definition app_config.h:45
#define IEKF_SIGMA_GYRO
Definition app_config.h:38
#define IEKF_PERSIST_TAU_S
Definition app_config.h:75
#define IEKF_P0_BIAS
Definition app_config.h:44
#define IEKF_PERSIST_RATIO
Definition app_config.h:76
#define IEKF_DIP_TOL
Definition app_config.h:60
#define IEKF_LOCKOUT_BUMP
Definition app_config.h:73
#define IEKF_MAG_NIS_GATE
not recommended, see iekf.h
Definition app_config.h:58
#define IEKF_INFL_TAU_S
Definition app_config.h:59
#define IEKF_DECOUPLE
tried: does not help, see 03 - Docs/theory/iekf-embedded.md
Definition app_config.h:61
#define APP_IMU_ODR
Definition app_config.h:16
#define IEKF_SIGMA_VEC_MIN
Definition app_config.h:40
#define IEKF_ACC_NIS_GATE
Definition app_config.h:57
#define APP_STILL_TIME_S
Definition app_config.h:93
#define IEKF_MAG_TOL
Definition app_config.h:42
#define APP_STILL_GYRO_THR
Definition app_config.h:92
#define IEKF_RESET_JACOBIAN
Definition app_config.h:66
#define IEKF_SIGMA_BIAS
Definition app_config.h:39
#define IEKF_INFL_MAX
Definition app_config.h:71
#define IEKF_P0_ATT
Definition app_config.h:43
#define IEKF_TILT_COMP_MAG
Definition app_config.h:47
#define IEKF_ACC_TOL
Definition app_config.h:41
#define APP_STEPS_PER_ACC
-> 240 Hz acc update + attitude loop
Definition app_config.h:24
#define IEKF_ADAPTIVE
Definition app_config.h:46
#define APP_STEP_HZ
propagation + rate loop
Definition app_config.h:23
void app_est_config(est_config_t *ec)
Fills every field from app_config.h, including APP_COMPARE_ORIGINAL.
Definition est_config.c:10
The production configuration of the attitude estimator, built from app_config.h in one place,...
void iekf_default_config(iekf_config_t *c)
Definition iekf.c:45
#define IMU_SH_HZ(fast)
@ IMU_ODR_1920HZ
float mag_latency_s
Age of the mag sample on arrival: the LIS2MDL converts at f_lis, the sensor hub re-reads it at f_sh >...
float mag_latency_std_s
float calib_gyro_still
rad/s
float still_acc_tol
Stillness detector: if |a| ~ nominal and |omega| small for still_time_s, an external acceleration is ...
uint8_t gyro_per_step
2 with ODR 1920 Hz, 1 with 960 Hz
float sigma_vec_min
float still_gyro_thr
rad/s, e.g.
iekf_config_t ekf
sigma_acc/sigma_mag overwritten by calib
uint16_t calib_samples
mag samples while standing still
uint8_t steps_per_acc
4 -> acc update at 240 Hz
float still_time_s
e.g.
float mag_tol
Definition iekf.h:38
uint8_t adaptive
Definition iekf.h:42
uint8_t decouple
1: acc corrects only roll/pitch, mag only yaw
Definition iekf.h:56
float infl_max
— protection against "lockout" of the NIS inflation — If the estimate is truly wrong,...
Definition iekf.h:77
uint8_t reset_jacobian
1: transport P after the retraction (default)
Definition iekf.h:57
float sigma_bias
rad/s^2, bias random walk
Definition iekf.h:34
float p0_att
initial attitude variance [rad^2]
Definition iekf.h:39
uint16_t grace_updates
e.g.
Definition iekf.h:80
float acc_nis_gate
— robustness to external accelerations / magnetic disturbances —
Definition iekf.h:45
float dip_tol
Definition iekf.h:50
float persist_ratio
|mean|^2 / mean(|e|^2) above which it is persistent, e.g.
Definition iekf.h:82
uint8_t tilt_comp_mag
Definition iekf.h:43
float p0_bias
initial bias variance [(rad/s)^2]
Definition iekf.h:40
float sigma_gyro
rad/s, gyro white noise
Definition iekf.h:33
float persist_decay
moving mean of the innovation: exp(-dt/tau), tau ~ 1 s
Definition iekf.h:81
uint16_t lockout_updates
e.g.
Definition iekf.h:78
uint8_t estimate_bias
Definition iekf.h:41
uint8_t tangent_innov
Definition iekf.h:58
float acc_tol
relative tolerance on the magnitude (gating)
Definition iekf.h:37
float mag_nis_gate
Definition iekf.h:47
float lockout_p_bump
rad^2, e.g.
Definition iekf.h:79
float infl_decay
Definition iekf.h:54
float persist_min
minimum |mean| (sine of the error), e.g.
Definition iekf.h:83