|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
Search for a servo mechanical limit by current: the state machine. More...
Macros | |
| #define | BASELINE_STEPS 3u |
Functions | |
| static bool | elapsed (uint32_t now, uint32_t then, uint32_t ms) |
| Tell whether a millisecond span has elapsed. | |
| static uint16_t | clamp_travel (const servo_limit_cfg_t *cfg, int32_t us) |
| Clamp a pulse width to the search travel and the pulse range. | |
| void | servo_limit_defaults (servo_limit_cfg_t *cfg, uint16_t centre_us, bool positive) |
| Defaults for a hobby servo on a control surface. | |
| void | servo_limit_init (servo_limit_t *lf, const servo_limit_cfg_t *cfg) |
| Start a limit search. | |
| static void | finish (servo_limit_t *lf, servo_limit_state_t state, servo_limit_fault_t fault) |
| Finish the search with the surface returned to centre. | |
| static bool | advance (servo_limit_t *lf) |
| Move one step further out. | |
| static void | judge (servo_limit_t *lf, float avg_a) |
| One position's averaged current has arrived; decide what it means. | |
| uint16_t | servo_limit_step (servo_limit_t *lf, float current_a, uint32_t now_ms) |
| Advance the search with one current reading, and return the pulse width the servo should be commanded to. | |
| float | servo_limit_progress (const servo_limit_t *lf) |
| How far the search has gone, 0..1, for a progress bar. | |
Search for a servo mechanical limit by current: the state machine.
SPDX-License-Identifier: MIT
|
static |
Move one step further out.
A step that would pass the end of the permitted travel stops at that end, so the end itself is measured. With the end measured free, the surface is free over the whole range asked about, and that is reported as NO_LIMIT rather than as a mechanical limit.
Returns false if the search ended here.
| lf | Search state to advance. |
|
static |
Clamp a pulse width to the search travel and the pulse range.
| cfg | Configuration whose centre_us and max_travel_us bound the travel. |
| us | Pulse width to clamp, us. |
|
inlinestatic |
Tell whether a millisecond span has elapsed.
| now | Current time, ms. |
| then | Start of the span, ms. |
| ms | Span length, ms. |
|
static |
Finish the search with the surface returned to centre.
| lf | Search state to update. |
| state | Final state to store. |
| fault | Fault code to store. |
|
static |
One position's averaged current has arrived; decide what it means.
| lf | Search state to update. |
| avg_a | Current averaged over the measure phase at this position, A. |
| void servo_limit_defaults | ( | servo_limit_cfg_t * | cfg, |
| uint16_t | centre_us, | ||
| bool | positive ) |
Defaults for a hobby servo on a control surface.
| cfg | Configuration to fill. Does nothing when NULL. |
| centre_us | Centre pulse width, us. |
| positive | true to step toward longer pulse widths, false toward shorter ones; the step is 10us either way. |
| void servo_limit_init | ( | servo_limit_t * | lf, |
| const servo_limit_cfg_t * | cfg ) |
Start a limit search.
| lf | Search state to initialise. Does nothing when NULL. |
| cfg | Configuration to copy. Does nothing when NULL. |
| float servo_limit_progress | ( | const servo_limit_t * | lf | ) |
How far the search has gone, 0..1, for a progress bar.
| lf | Search state. |
| uint16_t servo_limit_step | ( | servo_limit_t * | lf, |
| float | current_a, | ||
| uint32_t | now_ms ) |
Advance the search with one current reading, and return the pulse width the servo should be commanded to.
Call it at the sampling rate of the current sensor. Calling after the search has finished is safe; the returned width then holds the servo at centre, so a finished search leaves no surface deflected.
| lf | Search state. A NULL lf gives 0. |
| current_a | Current reading, A. At or above hard_limit_a, or NaN, aborts the search. |
| now_ms | Time of the reading, ms. |