34#define BATT_CELL_DETECT_V 4.35f
35#define BATT_PRESENT_V 2.5f
36#define BATT_ABSENT_V 1.5f
37#define BATT_LEVEL_MS 2000u
38#define BATT_RECOVER_MS 2000u
39#define BATT_RECOVER_HYST 0.05f
40#define BATT_RESERVE_SOC 0.20f
41#define BATT_R_CELL_DEFAULT 0.040f
void batt_init(const batt_cfg_t *cfg)
void batt_set_scales(float scale_v, float scale_i)
float batt_soc_from_ocv(float cell_v)
LiPo open-circuit voltage → state of charge 0…1 (exposed for the tests)
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)
void batt_read(batt_state_t *out)
seqlock snapshot for other tasks; keeps *out on a race
const batt_state_t * batt_state(void)
state as computed by the last step (same context)
void batt_get_cfg(batt_cfg_t *out)
float sens_v_per_a
current sensor gain, V/A
uint8_t has_current
a current sensor is wired
float scale_i
current multiplier (1 = nominal sensor)
float scale_v
×10 divider ratio (110 = ×11)
thresholds and settings (from the parameters)
float capacity_mah
0 = unknown
uint8_t level
PV2_BATT_OK / LOW / CRITICAL / EMERGENCY
uint8_t cells
0 = not known
uint8_t present
a battery is connected
float remain_s
s of flight left, < 0 = n/a
float vbat_raw
V, last sample, unfiltered (calibration)
float current
A, filtered (τ 0.05 s); 0 without a sensor
float vbat
V, pack, filtered (τ 0.1 s)
float r_cell
Ω per cell, estimate
float used_mah
since power-on
float cell_v
V, sagged, filtered (τ 0.5 s): failsafes, CHECKS.
float cell_rest_v
V, sag compensated: state of charge