![]() |
ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
|
Battery monitor: voltage, current, consumed charge, cell count, state of charge, flight time left and the warning level used by the battery failsafes (HANDOVER_FW.md §4 POWER, §6, §9 item 1, §10.6). More...
#include <stdint.h>Go to the source code of this file.
Data Structures | |
| struct | batt_cfg_t |
| struct | batt_state_t |
| published state More... | |
| struct | batt_limits_t |
| thresholds and settings (from the parameters) More... | |
Macros | |
| #define | BATT_CELL_DETECT_V 4.35f |
| max cell voltage used to count cells | |
| #define | BATT_PRESENT_V 2.5f |
| pack above this = battery connected | |
| #define | BATT_ABSENT_V 1.5f |
| #define | BATT_LEVEL_MS 2000u |
| below a threshold this long -> level | |
| #define | BATT_RECOVER_MS 2000u |
| disarmed, above threshold + hyst | |
| #define | BATT_RECOVER_HYST 0.05f |
| V/cell | |
| #define | BATT_RESERVE_SOC 0.20f |
| charge kept for landing (remain) | |
| #define | BATT_R_CELL_DEFAULT 0.040f |
| Ω per cell before any estimate | |
Functions | |
| void | batt_init (const batt_cfg_t *cfg) |
| void | batt_set_scales (float scale_v, float scale_i) |
| void | batt_get_cfg (batt_cfg_t *out) |
| void | batt_step (float pin_v, float cur_pin_v, uint32_t dt_ms, uint8_t armed, const batt_limits_t *lim) |
| one sample: pin voltages, time step, armed flag (flight-control context) | |
| 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 | |
| float | batt_soc_from_ocv (float cell_v) |
| LiPo open-circuit voltage → state of charge 0…1 (exposed for the tests) | |
Battery monitor: voltage, current, consumed charge, cell count, state of charge, flight time left and the warning level used by the battery failsafes (HANDOVER_FW.md §4 POWER, §6, §9 item 1, §10.6).
Inputs are the voltages at the two ADC pins (the board binding converts the counts with VREFINT). The module runs in the flight-control context (ImuTask, 50 Hz) and publishes a snapshot that any task can read.
vbat = pin × scaleV / 10 (scaleV 110 = the 100k/10k divider of the ACwing FC). BATTERY calibration corrects scaleV.I = pin / sens × scaleI, sens 0.1 V/A on the ACwing ESC 1S (TSC213 + 2 mΩ). BATTERY calibration corrects scaleI from the charge the charger put back.ceil(vbat / 4.35 V), 1…6.V + I·R (R estimated on line from the load steps) through a LiPo OCV curve, anchored while the battery rests, then coulomb counting when the capacity (battCapacity) is known.Host-testable: no HAL, no RTOS.
Definition in file battery.h.
| #define BATT_CELL_DETECT_V 4.35f |
| #define BATT_PRESENT_V 2.5f |
| #define BATT_LEVEL_MS 2000u |
| #define BATT_RECOVER_MS 2000u |
| #define BATT_RESERVE_SOC 0.20f |
| #define BATT_R_CELL_DEFAULT 0.040f |
| 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 | scale_v, |
| float | scale_i | ||
| ) |
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().
| void batt_step | ( | float | pin_v, |
| float | cur_pin_v, | ||
| uint32_t | dt_ms, | ||
| uint8_t | armed, | ||
| const batt_limits_t * | lim | ||
| ) |
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().
| 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().
| float batt_soc_from_ocv | ( | float | cell_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().