The bench readings, in the units a person reads: V, A, W, rpm (revolutions per minute), degrees Celsius, mAh and Wh.
More...
|
|
#define | BENCH_CHW_CHANNELS 12u |
| | The INA3221 channels SENSE_WIN_A and SENSE_WIN_B carry (4.25).
|
|
#define | BENCH_FINE_MAH_TOL 2.0f |
| | How far the SENSE page's totals may lie from BENCH's and be the same count: half a register step of rounding, and what a few milliseconds between the two reads adds at full current.
|
|
#define | BENCH_FINE_WH_TOL 0.2f |
|
#define | BENCH_CHARGE_MAH_MAX 65535.0f |
| | The most BENCH's charge (1mAh) and energy (0.1Wh) registers carry: a run past them reads the ceiling there, and only SENSE's 32-bit totals go on.
|
|
#define | BENCH_ENERGY_WH_MAX 6553.5f |
|
#define | BENCH_COUNTED_CHARGE 0x01u |
| | bench_state_t.counted: the run's charge has counted a measured current.
|
|
#define | BENCH_COUNTED_ENERGY 0x02u |
| | bench_state_t.counted: the run's energy has counted voltage and current.
|
|
#define | BENCH_TOTALS_MAX_STEP_S 1.0f |
| | The longest step bench_totals_count() counts, in seconds.
|
| #define | BENCH_TOTALS_SETTLE_S 0.1f |
| | How long into a run the INA228's totals are not taken, in seconds.
|
|
#define | BENCH_RPM_STALE_MS 200u |
|
#define | BENCH_EDT_STALE_MS 2000u |
|
| static bool | bench_state_simulated (const bench_state_t *b) |
| | True when the numbers are modelled rather than measured.
|
| void | bench_state_from_regs (bench_state_t *b, const uint16_t *regs, uint8_t offset, uint8_t count) |
| | Decode a BENCH page into b.
|
| void | bench_state_to_regs (const bench_state_t *b, uint16_t *regs) |
| | Encode into a BENCH page, for the IOmcu and for round-trip tests.
|
| void | bench_state_run_starts (bench_state_t *b, uint16_t *regs) |
| | A run starts: the totals of the last one go, in b and in the BENCH page regs built from it – charge and energy 0 and LINK_BN_TOTALS_OK clear – and every other register stays.
|
| void | bench_state_log_row (const bench_state_t *b, bool whole, bench_state_t *out) |
| | One row of the bench log from b, into out.
|
| void | bench_state_reset_peaks (bench_state_t *b) |
| | Clear the peaks without disturbing the live readings.
|
| void | bench_state_set_esc (bench_state_t *b, bool v_ok, float volts, bool i_ok, float amps, bool clipped) |
| | The ESC's own figures while the INA228 is the source: from the SENSE page's ESC registers, v_ok and i_ok their valid bits, and whether the INA228 reads clipped.
|
| bool | bench_state_esc_voltage (const bench_state_t *b, float *out) |
| | The ESC's own voltage and current, whichever page carries them: the SENSE page's while the INA228 is BENCH's source, BENCH's own otherwise.
|
| bool | bench_state_esc_current (const bench_state_t *b, float *out) |
| | The ESC's own current, from the same source as bench_state_esc_voltage().
|
| bool | bench_state_ina_voltage (const bench_state_t *b, float *out) |
| | The INA228's own voltage and current: BENCH's while it is the source.
|
| bool | bench_state_ina_current (const bench_state_t *b, float *out) |
| | The INA228's own current: BENCH's while it is the source.
|
| void | bench_state_fine_totals (bench_state_t *b, int32_t charge_cmah, uint32_t energy_cwh) |
| | With LINK_BN_TOTALS_OK, the INA228's totals in the SENSE page's finer steps – charge_cmah in 0.01mAh, energy_cwh in 0.01Wh, read in the same poll – over BENCH's 1mAh and 0.1Wh, each where it agrees with BENCH's within the tolerance above, or where BENCH reads its ceiling and the finer figure is at or above it.
|
| void | bench_totals_reset (bench_totals_t *t) |
| | A run begins: nothing counted.
|
| void | bench_totals_count (bench_totals_t *t, const bench_state_t *b, float dt_s, bool driving) |
| | Add dt_s of b's readings, while driving, and only what its flags mark measured: charge from a current, energy from a power with both halves.
|
| void | bench_totals_show (const bench_totals_t *t, bench_state_t *b) |
| | Write the totals into b, over whatever its source put there.
|
| void | bench_state_track_peaks (bench_state_t *b) |
| | Take the live readings into the peaks.
|
| void | bench_state_from_telem (bench_state_t *b, const bench_telem_t *t) |
| | The live readings of b and their valid bits from t, for the IOmcu's sample.
|
The bench readings, in the units a person reads: V, A, W, rpm (revolutions per minute), degrees Celsius, mAh and Wh.
Screens read this struct and never a register. Filled from the link's BENCH page the numbers are measured; filled from the simulator they are modelled; the screen does not distinguish the two.
Floats here, fixed-point on the wire: 16 bits with a documented scale is the contract between the two firmwares. The scales are in link_pages.h.
SPDX-License-Identifier: MIT
| bool bench_state_esc_voltage |
( |
const bench_state_t * | b, |
|
|
float * | out ) |
The ESC's own voltage and current, whichever page carries them: the SENSE page's while the INA228 is BENCH's source, BENCH's own otherwise.
False, and out untouched, when the ESC reported none – and for modelled numbers (LINK_BN_SIMULATED), which no ESC reported.
- Parameters
-
| b | The state to read. |
| out | Receives the voltage in V; untouched when false. |
- Returns
- true when an ESC voltage is available.
| void bench_state_fine_totals |
( |
bench_state_t * | b, |
|
|
int32_t | charge_cmah, |
|
|
uint32_t | energy_cwh ) |
With LINK_BN_TOTALS_OK, the INA228's totals in the SENSE page's finer steps – charge_cmah in 0.01mAh, energy_cwh in 0.01Wh, read in the same poll – over BENCH's 1mAh and 0.1Wh, each where it agrees with BENCH's within the tolerance above, or where BENCH reads its ceiling and the finer figure is at or above it.
Nothing changes without TOTALS_OK.
- Parameters
-
| b | The state whose totals are set. |
| charge_cmah | The INA228 charge in 0.01mAh. |
| energy_cwh | The INA228 energy in 0.01Wh. |
The live readings of b and their valid bits from t, for the IOmcu's sample.
voltage, current, power, rpm, temp_esc, temp_motor and flags are rebuilt; the peaks and every other field stay.
rpm with LINK_BN_RPM_OK from a speed no older than BENCH_RPM_STALE_MS and poles not 0; voltage, current and temp_esc with LINK_BN_VOLTAGE_OK, LINK_BN_CURRENT_OK and LINK_BN_TEMP_OK from readings no older than BENCH_EDT_STALE_MS, in the units of dshot_edt_*(); power, the product, only with both halves. LINK_BN_TEMP_MOT_OK is never set.
- Parameters
-
| b | The state that is written. |
| t | The telemetry sample that is read. |
Add dt_s of b's readings, while driving, and only what its flags mark measured: charge from a current, energy from a power with both halves.
dt_s is the time since the last call, clamped to 0 .. BENCH_TOTALS_MAX_STEP_S, so a loop that stalled counts at most one second of its last reading. With LINK_BN_TOTALS_OK in b's flags and BENCH_TOTALS_SETTLE_S of the run counted, the count is b's own charge and energy instead, both counted.
- Parameters
-
| t | The running totals. |
| b | The readings of this sample. |
| dt_s | The time since the last call in s, clamped to 0 .. BENCH_TOTALS_MAX_STEP_S. |
| driving | true while the bench is driving. |