|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
The decoding, peaks and totals of the bench readings, see bench_state.h. More...
Macros | |
| #define | CV_PER_V 100.0f |
| #define | CA_PER_A 100.0f |
| #define | DC_PER_C 10.0f |
| #define | DWH_PER_WH 10.0f |
Functions | |
| static float | from_u16 (uint16_t v, float per_unit) |
| Decodes an unsigned register value into units. | |
| static uint16_t | to_u16 (float v, float per_unit) |
| Encodes a non-negative value into an unsigned register. | |
| static float | from_i16 (uint16_t v, float per_unit) |
| Decodes a signed register value into units. | |
| static uint16_t | to_i16 (float v, float per_unit) |
| Encodes a signed value into a register, rounded and clamped to int16_t. | |
| 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_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_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. | |
| static bool | sensed (const bench_state_t *b) |
| True when the readings come from the INA228 (LINK_BN_SENSED). | |
| static bool | esc_figure (const bench_state_t *b, uint8_t esc_bit, float esc, uint16_t bench_bit, float bench, float *out) |
| One of the ESC's figures: from SENSE while the INA228 is the source, from BENCH's own register and flag otherwise. | |
| 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(). | |
| static bool | ina_figure (const bench_state_t *b, uint16_t bit, float v, float *out) |
| One INA228 figure, valid only while the INA228 is the source and bit is set. | |
| 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_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 decoding, peaks and totals of the bench readings, see bench_state.h.
SPDX-License-Identifier: MIT
| #define CA_PER_A 100.0f |
10mA steps
| #define CV_PER_V 100.0f |
10mV steps
| #define DC_PER_C 10.0f |
0.1C steps
| #define DWH_PER_WH 10.0f |
0.1Wh steps
| 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().
| b | The state to read. |
| out | Receives the current in A; untouched when false. |
| 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.
| b | The state to read. |
| out | Receives the voltage in V; untouched when false. |
| 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.
| b | The state whose totals are set. |
| charge_cmah | The INA228 charge in 0.01mAh. |
| energy_cwh | The INA228 energy in 0.01Wh. |
| 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.
A short read fills what arrived and leaves the rest alone, so a host that polls the first four registers at 20Hz and the whole page once a second gets a coherent state either way.
| b | The state the registers are decoded into. |
| regs | The page registers, count entries from offset. |
| offset | The page register that regs[0] holds. |
| count | The number of entries in regs. |
| 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.
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.
| b | The state that is written. |
| t | The telemetry sample that is read. |
| bool bench_state_ina_current | ( | const bench_state_t * | b, |
| float * | out ) |
The INA228's own current: BENCH's while it is the source.
| b | The state to read. |
| out | Receives the current in A; untouched when false. |
| 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.
False otherwise.
| b | The state to read. |
| out | Receives the voltage in V; untouched when false. |
| 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.
With whole the sample as it is. Without, the INA3221's window alone – servo_new, the servo_ fields and chw – and every other field 0 with no flag set, which the log writes as empty cells: the row of a window that closed before the newest one of its pass.
| b | The state to take the row from. |
| whole | true for the whole sample, false for the INA3221 window alone. |
| out | Where the row is written. |
| void bench_state_reset_peaks | ( | bench_state_t * | b | ) |
Clear the peaks without disturbing the live readings.
| b | The state whose peaks are cleared. |
| 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.
For the IOmcu, on the edge into driving: it rebuilds the page at its 50Hz sample, and until the next one a panel reading the page would see the last run's totals marked as this run's. Either pointer may be NULL.
| b | The state to update, or NULL. |
| regs | The page to update, or NULL. |
| 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.
All clear while it is not the source.
| b | The state to write. |
| v_ok | true when volts is valid. |
| volts | The ESC voltage in V. |
| i_ok | true when amps is valid. |
| amps | The ESC current in A. |
| clipped | true when the INA228 reads clipped. |
| 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.
| b | The state to encode. |
| regs | The page to fill, LINK_BN_COUNT registers. |
| void bench_state_track_peaks | ( | bench_state_t * | b | ) |
Take the live readings into the peaks.
Only what the flags mark valid: an empty field is not a measurement of zero, and a sag floor or a current peak taken from one would stand for the rest of the run. The floor is seeded by the first valid voltage rather than by the reset, because a reset can happen before any voltage has arrived.
| b | The state whose peaks are updated. |
| 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.
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.
| 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. |
| void bench_totals_reset | ( | bench_totals_t * | t | ) |
A run begins: nothing counted.
| t | The totals to clear. |
| void bench_totals_show | ( | const bench_totals_t * | t, |
| bench_state_t * | b ) |
Write the totals into b, over whatever its source put there.
| t | The totals to show. |
| b | The state that receives them. |
|
static |
One of the ESC's figures: from SENSE while the INA228 is the source, from BENCH's own register and flag otherwise.
| b | The state to read. |
| esc_bit | The valid bit in esc_ok. |
| esc | The SENSE value. |
| bench_bit | The valid bit in flags. |
| bench | The BENCH value. |
| out | Receives the value; untouched when false. |
|
static |
Decodes a signed register value into units.
| v | The raw register value, two's complement. |
| per_unit | Register steps per unit. |
|
static |
Decodes an unsigned register value into units.
| v | The raw register value. |
| per_unit | Register steps per unit. |
|
static |
One INA228 figure, valid only while the INA228 is the source and bit is set.
| b | The state to read. |
| bit | The valid bit in flags. |
| v | The value. |
| out | Receives the value; untouched when false. |
|
static |
True when the readings come from the INA228 (LINK_BN_SENSED).
| b | The state to test. |
|
static |
Encodes a signed value into a register, rounded and clamped to int16_t.
| v | The value in units. |
| per_unit | Register steps per unit. |
|
static |
Encodes a non-negative value into an unsigned register.
| v | The value in units. |
| per_unit | Register steps per unit. |