![]() |
ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
|
Battery monitor (see battery.h). More...
Go to the source code of this file.
Macros | |
| #define | DETECT_MS 500u /* battery present and stable before counting cells */ |
| #define | R_WIN_MS 100u /* window of the internal resistance estimate */ |
| #define | R_MIN_DI 0.5f /* A: load step needed for an estimate */ |
| #define | REST_I 0.3f /* A: below this the pack is "resting" */ |
| #define | SOC_REST_TAU 2.0f /* s */ |
| #define | SOC_V_TAU 10.0f /* s: voltage-only state of charge */ |
| #define | SOC_CORR_TAU 600.0f /* s: pull of the voltage on the coulomb counter */ |
| #define | I_SLOW_TAU 10.0f /* s: current used for the time left */ |
Functions | |
| float | batt_soc_from_ocv (float v) |
| LiPo open-circuit voltage → state of charge 0…1 (exposed for the tests) | |
| static float | lpf (float y, float x, float dt, float tau) |
| static float | clamp01 (float v) |
| void | batt_init (const batt_cfg_t *cfg) |
| void | batt_set_scales (float sv, float si) |
| void | batt_get_cfg (batt_cfg_t *out) |
| const batt_state_t * | batt_state (void) |
| state as computed by the last step (same context) | |
| void | batt_read (batt_state_t *out) |
| seqlock snapshot for other tasks; keeps *out on a race | |
| static void | publish (void) |
| static void | lost_battery (void) |
| static void | r_estimate (float v, float i, uint32_t dt) |
| static uint8_t | level_of (float cv, const batt_limits_t *L, float hyst) |
| void | batt_step (float pin_v, float cur_pin_v, uint32_t dt_ms, uint8_t armed, const batt_limits_t *L) |
| one sample: pin voltages, time step, armed flag (flight-control context) | |
Variables | |
| static batt_cfg_t | s_cfg |
| static batt_state_t | s |
| static uint32_t | s_present_ms |
| static uint32_t | s_absent_ms |
| static uint32_t | s_below_ms [4] |
| static uint32_t | s_recover_ms |
| static uint8_t | s_have_anchor |
| static uint8_t | s_have_f |
| static float | s_soc_anchor |
| static float | s_used_anchor |
| static float | s_i_slow |
| static float | s_wv |
| static float | s_wi |
| static uint32_t | s_wn |
| static uint32_t | s_wms |
| static float | s_pv |
| static float | s_pi |
| static uint8_t | s_have_pw |
| static volatile uint32_t | s_seq |
| static batt_state_t | s_pub |
| static const float | k_ocv [21] |
| #define DETECT_MS 500u /* battery present and stable before counting cells */ |
| #define R_WIN_MS 100u /* window of the internal resistance estimate */ |
| #define R_MIN_DI 0.5f /* A: load step needed for an estimate */ |
| #define REST_I 0.3f /* A: below this the pack is "resting" */ |
| #define SOC_V_TAU 10.0f /* s: voltage-only state of charge */ |
| #define SOC_CORR_TAU 600.0f /* s: pull of the voltage on the coulomb counter */ |
| float batt_soc_from_ocv | ( | float | v | ) |
LiPo open-circuit voltage → state of charge 0…1 (exposed for the tests)
Definition at line 41 of file battery.c.
References k_ocv.
Referenced by batt_step().
|
static |
Definition at line 54 of file battery.c.
Referenced by batt_step().
|
static |
Definition at line 55 of file battery.c.
Referenced by batt_step().
| void batt_init | ( | const batt_cfg_t * | cfg | ) |
Definition at line 57 of file battery.c.
References BATT_R_CELL_DEFAULT, batt_state_t::r_cell, batt_state_t::remain_s, s, s_absent_ms, s_below_ms, s_cfg, s_have_anchor, s_have_f, s_have_pw, s_i_slow, s_present_ms, s_pub, s_recover_ms, s_seq, s_soc_anchor, s_used_anchor, s_wi, s_wms, s_wn, s_wv, batt_cfg_t::scale_i, batt_cfg_t::scale_v, and batt_cfg_t::sens_v_per_a.
Referenced by batt_task_init().
| void batt_set_scales | ( | float | sv, |
| float | si | ||
| ) |
Definition at line 75 of file battery.c.
References s_cfg, batt_cfg_t::scale_i, and batt_cfg_t::scale_v.
Referenced by batt_task_step().
| void batt_get_cfg | ( | batt_cfg_t * | out | ) |
Definition at line 81 of file battery.c.
References s_cfg.
Referenced by batt_task_step().
| const batt_state_t * batt_state | ( | void | ) |
state as computed by the last step (same context)
Definition at line 82 of file battery.c.
References s.
Referenced by batt_task_step().
| void batt_read | ( | batt_state_t * | out | ) |
seqlock snapshot for other tasks; keeps *out on a race
Definition at line 84 of file battery.c.
References s_pub, s_seq, and SPSC_BARRIER.
Referenced by batt_now().
|
static |
Definition at line 96 of file battery.c.
References s, s_pub, s_seq, and SPSC_BARRIER.
Referenced by batt_step().
|
static |
Definition at line 105 of file battery.c.
References batt_state_t::cell_rest_v, batt_state_t::cell_v, batt_state_t::cells, batt_state_t::level, batt_state_t::pct, batt_state_t::present, PV2_BATT_OK, batt_state_t::remain_s, s, s_below_ms, s_have_anchor, s_have_pw, s_present_ms, s_recover_ms, and batt_state_t::soc.
Referenced by batt_step().
|
static |
Definition at line 121 of file battery.c.
References batt_state_t::cells, batt_state_t::r_cell, R_MIN_DI, R_WIN_MS, s, s_have_pw, s_pi, s_pv, s_wi, s_wms, s_wn, and s_wv.
Referenced by batt_step().
|
static |
Definition at line 137 of file battery.c.
References PV2_BATT_CRITICAL, PV2_BATT_EMERGENCY, PV2_BATT_LOW, and PV2_BATT_OK.
Referenced by batt_step().
| void batt_step | ( | float | pin_v, |
| float | cur_pin_v, | ||
| uint32_t | dt_ms, | ||
| uint8_t | armed, | ||
| const batt_limits_t * | L | ||
| ) |
one sample: pin voltages, time step, armed flag (flight-control context)
Definition at line 145 of file battery.c.
References BATT_ABSENT_V, BATT_CELL_DETECT_V, BATT_LEVEL_MS, BATT_PRESENT_V, BATT_RECOVER_HYST, BATT_RECOVER_MS, BATT_RESERVE_SOC, batt_soc_from_ocv(), batt_state_t::cell_rest_v, batt_state_t::cell_v, batt_state_t::cells, clamp01(), batt_state_t::current, DETECT_MS, batt_cfg_t::has_current, I_SLOW_TAU, L, batt_state_t::level, level_of(), lost_battery(), lpf(), n, batt_state_t::pct, batt_state_t::present, publish(), PV2_BATT_OK, batt_state_t::r_cell, r_estimate(), batt_state_t::remain_s, REST_I, s, s_absent_ms, s_below_ms, s_cfg, s_have_anchor, s_have_f, s_i_slow, s_present_ms, s_recover_ms, s_soc_anchor, s_used_anchor, batt_cfg_t::scale_i, batt_cfg_t::scale_v, batt_cfg_t::sens_v_per_a, batt_state_t::soc, SOC_CORR_TAU, SOC_REST_TAU, SOC_V_TAU, batt_state_t::used_mah, batt_state_t::vbat, and batt_state_t::vbat_raw.
Referenced by batt_task_step().
|
static |
Definition at line 20 of file battery.c.
Referenced by batt_get_cfg(), batt_init(), batt_set_scales(), and batt_step().
|
static |
Definition at line 21 of file battery.c.
Referenced by alt_est_predict(), alt_est_tof(), appl_silence_ms(), batt_init(), batt_state(), batt_step(), batt_task_post_scales(), cal_from_v1(), calib_finish(), config_desc(), dev_desc(), events(), ext_step(), ext_take(), fsh_cal_pop(), fsh_cal_push(), fsh_est_write(), iekf_init(), imu_fifo_level(), is_used(), itf_desc(), lang_desc(), log_erase_all(), log_mount(), log_used_pct(), logf_flight(), lost_battery(), map_status(), mfr_desc(), next(), prod_desc(), publish(), put(), r_estimate(), read_hdr(), send_system(), serial_desc(), set_used(), and vl53_poll().
|
static |
Definition at line 22 of file battery.c.
Referenced by batt_init(), batt_step(), and lost_battery().
|
static |
Definition at line 22 of file battery.c.
Referenced by batt_init(), and batt_step().
|
static |
Definition at line 23 of file battery.c.
Referenced by batt_init(), batt_step(), and lost_battery().
|
static |
Definition at line 23 of file battery.c.
Referenced by batt_init(), batt_step(), and lost_battery().
|
static |
Definition at line 24 of file battery.c.
Referenced by batt_init(), batt_step(), and lost_battery().
|
static |
Definition at line 24 of file battery.c.
Referenced by batt_init(), and batt_step().
|
static |
Definition at line 25 of file battery.c.
Referenced by batt_init(), and batt_step().
|
static |
Definition at line 25 of file battery.c.
Referenced by batt_init(), and batt_step().
|
static |
Definition at line 25 of file battery.c.
Referenced by batt_init(), and batt_step().
|
static |
Definition at line 27 of file battery.c.
Referenced by batt_init(), and r_estimate().
|
static |
Definition at line 27 of file battery.c.
Referenced by batt_init(), and r_estimate().
|
static |
Definition at line 28 of file battery.c.
Referenced by batt_init(), and r_estimate().
|
static |
Definition at line 28 of file battery.c.
Referenced by batt_init(), and r_estimate().
|
static |
Definition at line 29 of file battery.c.
Referenced by r_estimate().
|
static |
Definition at line 29 of file battery.c.
Referenced by r_estimate().
|
static |
Definition at line 30 of file battery.c.
Referenced by batt_init(), lost_battery(), and r_estimate().
|
static |
Definition at line 32 of file battery.c.
Referenced by batt_init(), batt_read(), and publish().
|
static |
Definition at line 33 of file battery.c.
Referenced by batt_init(), batt_read(), and publish().
|
static |
Definition at line 36 of file battery.c.
Referenced by batt_soc_from_ocv().