rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
servo_move.c File Reference

One servo move judged from its current. See servo_move.h for the rules. More...

#include "servo_move.h"
#include <math.h>
#include <string.h>

Functions

float servo_move_noise_a (uint32_t n, float sum, float sum_sq)
 The standard deviation of n samples given as their sum and the sum of their squares; 0 for none.
float servo_move_threshold_a (float noise_a)
 The threshold for a noise at rest of noise_a.
uint32_t servo_move_window_ms (uint32_t lag_ms)
 SERVO_MOVE_TIMEOUT_MS plus a meter's lag of lag_ms.
void servo_move_begin (servo_move_t *m, const servo_move_cfg_t *cfg)
 A move begins: commanded at cfg->cmd_t, from cfg->rise_a towards cfg->ref_a. settle_n below 2 is taken as 2; filter_n is held to 1 to SERVO_MOVE_FILTER_MAX.
static bool under_way (const servo_move_t *m)
 Tell whether the move is still under way.
static bool expired (servo_move_t *m, uint32_t now)
 A move under way whose window has run out at now is over: late with movement, unseen without, ended at now. A now before the command decides nothing. Whether it ran out.
static void filter_push (servo_move_t *m, float a, servo_move_clip_t clip)
 A sample into the filter's window of the newest filter_n.
void servo_move_prime (servo_move_t *m, float a, servo_move_clip_t clip)
 A sample taken before the move began, into the filter only, as the newest so far: a caller that held samples before it knew the command's time hands them over oldest first. Decides nothing; nothing with filter_n 1 or once the move is over.
static bool filtered (servo_move_t *m, float a, servo_move_clip_t clip, float *out, servo_move_clip_t *out_clip)
 The filtered sample, from the newest filter_n samples: false when the window holds clips at both ends and so no bound.
static uint8_t run_with (const servo_move_t *m, float i, float *lo, float *hi)
 The samples in a row near the level with i added: their count, or 1 when i spreads them wider than the band and starts a new run.
servo_move_state_t servo_move_sample (servo_move_t *m, uint32_t at, float a, servo_move_clip_t clip)
 A sample taken at at: a amps, or for a clip the end of the range it is at or past.
servo_move_state_t servo_move_tick (servo_move_t *m, uint32_t now)
 The time is now: a move still under way at window_t after its command is over, late or unseen, with end_t at now. A now before the command decides nothing.
bool servo_move_over (const servo_move_t *m)
 Whether the move is over: arrived, settled, late or unseen.
bool servo_move_arrived (const servo_move_t *m)
 Whether the move arrived: ARRIVED or SETTLED.
bool servo_move_moved (const servo_move_t *m)
 Whether movement was seen.

Detailed Description

One servo move judged from its current. See servo_move.h for the rules.

SPDX-License-Identifier: MIT

Function Documentation

◆ expired()

bool expired ( servo_move_t * m,
uint32_t now )
static

A move under way whose window has run out at now is over: late with movement, unseen without, ended at now. A now before the command decides nothing. Whether it ran out.

Parameters
mMove state. Updated when the window has run out.
nowCurrent time, in the caller time unit.
Returns
true when the window has run out and the move is ended.

◆ filter_push()

void filter_push ( servo_move_t * m,
float a,
servo_move_clip_t clip )
static

A sample into the filter's window of the newest filter_n.

Parameters
mMove state. Updates the filter ring.
aSample, A.
clipClip state of the sample.

◆ filtered()

bool filtered ( servo_move_t * m,
float a,
servo_move_clip_t clip,
float * out,
servo_move_clip_t * out_clip )
static

The filtered sample, from the newest filter_n samples: false when the window holds clips at both ends and so no bound.

Parameters
mMove state. Pushes the sample into the filter.
aSample, A.
clipClip state of the sample.
outOut: mean of the filter window, A.
out_clipOut: clip state of the window.
Returns
true when the window has a bound; false when it holds clips at both ends.

◆ run_with()

uint8_t run_with ( const servo_move_t * m,
float i,
float * lo,
float * hi )
static

The samples in a row near the level with i added: their count, or 1 when i spreads them wider than the band and starts a new run.

Parameters
mMove state holding the current run.
iSample to add, A.
loOut: lowest value of the run, A.
hiOut: highest value of the run, A.
Returns
run length, 1 to UINT8_MAX.

◆ servo_move_arrived()

bool servo_move_arrived ( const servo_move_t * m)

Whether the move arrived: ARRIVED or SETTLED.

Parameters
mMove state.
Returns
true when the state is ARRIVED or SETTLED.

◆ servo_move_begin()

void servo_move_begin ( servo_move_t * m,
const servo_move_cfg_t * cfg )

A move begins: commanded at cfg->cmd_t, from cfg->rise_a towards cfg->ref_a. settle_n below 2 is taken as 2; filter_n is held to 1 to SERVO_MOVE_FILTER_MAX.

Parameters
mMove state to initialise.
cfgConfiguration of the move.

◆ servo_move_moved()

bool servo_move_moved ( const servo_move_t * m)

Whether movement was seen.

Parameters
mMove state.
Returns
true when the state is MOVING, LATE, ARRIVED or SETTLED.

◆ servo_move_noise_a()

float servo_move_noise_a ( uint32_t n,
float sum,
float sum_sq )

The standard deviation of n samples given as their sum and the sum of their squares; 0 for none.

Parameters
nNumber of samples.
sumSum of the samples, A.
sum_sqSum of the squares of the samples, A^2.
Returns
standard deviation, A; 0 when n is 0 or the variance is not positive.

◆ servo_move_over()

bool servo_move_over ( const servo_move_t * m)

Whether the move is over: arrived, settled, late or unseen.

Parameters
mMove state.
Returns
true when the state is not IDLE and the move is not WAITING or MOVING.

◆ servo_move_prime()

void servo_move_prime ( servo_move_t * m,
float a,
servo_move_clip_t clip )

A sample taken before the move began, into the filter only, as the newest so far: a caller that held samples before it knew the command's time hands them over oldest first. Decides nothing; nothing with filter_n 1 or once the move is over.

Parameters
mMove state.
aSample, A.
clipClip state of the sample.

◆ servo_move_sample()

servo_move_state_t servo_move_sample ( servo_move_t * m,
uint32_t at,
float a,
servo_move_clip_t clip )

A sample taken at at: a amps, or for a clip the end of the range it is at or past.

A sample taken before the command only fills the filter; one at or past window_t after the command ends the move late or unseen, as servo_move_tick() would, and is not judged. Returns the state after it; ARRIVED and SETTLED leave end_t at the arrival. Nothing once the move is over.

Parameters
mMove state.
atTime of the sample, in the caller time unit.
aSample, A.
clipSERVO_MOVE_CLIP_NONE for a sample; SERVO_MOVE_CLIP_LOW or SERVO_MOVE_CLIP_HIGH when the reading is at the end of its range.
Returns
state after the sample.

◆ servo_move_threshold_a()

float servo_move_threshold_a ( float noise_a)

The threshold for a noise at rest of noise_a.

Parameters
noise_aNoise at rest, A.
Returns
threshold, A: the larger of SERVO_MOVE_MIN_A and SERVO_MOVE_NOISE_K times noise_a.

◆ servo_move_tick()

servo_move_state_t servo_move_tick ( servo_move_t * m,
uint32_t now )

The time is now: a move still under way at window_t after its command is over, late or unseen, with end_t at now. A now before the command decides nothing.

Parameters
mMove state.
nowCurrent time, in the caller time unit.
Returns
state after the tick.

◆ servo_move_window_ms()

uint32_t servo_move_window_ms ( uint32_t lag_ms)

SERVO_MOVE_TIMEOUT_MS plus a meter's lag of lag_ms.

Parameters
lag_msLag of the meter readings, ms.
Returns
window length, ms: SERVO_MOVE_TIMEOUT_MS plus lag_ms.

◆ under_way()

bool under_way ( const servo_move_t * m)
static

Tell whether the move is still under way.

Parameters
mMove state.
Returns
true in the WAITING and MOVING states.