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

A servo on a control surface, modelled for the limit search. More...

#include <stdbool.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  servo_sim_cfg_t
struct  servo_sim_t
struct  servo_pair_cfg_t
 A pair, coupled through the surface they both drive. More...
struct  servo_pair_t

Functions

void servo_sim_defaults (servo_sim_cfg_t *cfg)
 A standard servo on a well-set-up surface, binding at 1150 and 1880 us.
void servo_sim_init (servo_sim_t *s, const servo_sim_cfg_t *cfg)
 Start the single-servo model at the middle of its stops.
float servo_sim_step (servo_sim_t *s, uint16_t cmd_us, uint32_t now_ms)
 Advance the model to now_ms with the servo commanded to cmd_us, and return the current its sensor would report.
void servo_pair_defaults (servo_pair_cfg_t *cfg, uint16_t centre_us)
 Defaults for two servos on one surface.
void servo_pair_init (servo_pair_t *p, const servo_pair_cfg_t *cfg)
 Start the two-servo model with both servos at the centre.
float servo_pair_step (servo_pair_t *p, uint16_t cmd_a_us, uint16_t cmd_b_us, uint32_t now_ms)
 Advance both servos to now_ms with the commands given, and return the total current the pair draws.
float servo_pair_disagreement (const servo_pair_t *p, uint16_t cmd_a_us, uint16_t cmd_b_us)
 How far apart the two hold the surface, in microseconds. Hardware cannot report this; the search is blind to it and a test may read it.

Detailed Description

A servo on a control surface, modelled for the limit search.

Not a general servo model. What the limit finder needs is the shape of current against commanded position as the linkage goes from free to bound. The rest exists so the search cannot succeed for the wrong reason: travel takes time, readings are noisy, and a preloaded surface does not draw zero at rest.

As with telemetry_sim: a bench with no hardware fitted runs its procedures end to end, and everything the model produces is marked as simulated. Nothing here decides anything on real hardware.

SPDX-License-Identifier: MIT

Function Documentation

◆ servo_pair_defaults()

void servo_pair_defaults ( servo_pair_cfg_t * cfg,
uint16_t centre_us )

Defaults for two servos on one surface.

Parameters
cfgConfiguration to fill.
centre_usCentre pulse width, us.

◆ servo_pair_disagreement()

float servo_pair_disagreement ( const servo_pair_t * p,
uint16_t cmd_a_us,
uint16_t cmd_b_us )

How far apart the two hold the surface, in microseconds. Hardware cannot report this; the search is blind to it and a test may read it.

Parameters
pModel state.
cmd_a_usCommanded pulse width of servo A, us.
cmd_b_usCommanded pulse width of servo B, us.
Returns
distance between the two servos on the surface, us; 0 when p is NULL.

◆ servo_pair_init()

void servo_pair_init ( servo_pair_t * p,
const servo_pair_cfg_t * cfg )

Start the two-servo model with both servos at the centre.

Parameters
pModel state to initialise.
cfgConfiguration to copy.

◆ servo_pair_step()

float servo_pair_step ( servo_pair_t * p,
uint16_t cmd_a_us,
uint16_t cmd_b_us,
uint32_t now_ms )

Advance both servos to now_ms with the commands given, and return the total current the pair draws.

Both servos take time to arrive, which is why this takes a clock: a reading taken before they have arrived is a reading of two servos in transit, not of two servos disagreeing. The settle time separates the two.

Parameters
pModel state.
cmd_a_usCommanded pulse width of servo A, us.
cmd_b_usCommanded pulse width of servo B, us.
now_msCurrent time, ms.
Returns
total current the pair draws, A; 0 when p is NULL.

◆ servo_sim_defaults()

void servo_sim_defaults ( servo_sim_cfg_t * cfg)

A standard servo on a well-set-up surface, binding at 1150 and 1880 us.

Parameters
cfgConfiguration to fill. Does nothing when NULL.

◆ servo_sim_init()

void servo_sim_init ( servo_sim_t * s,
const servo_sim_cfg_t * cfg )

Start the single-servo model at the middle of its stops.

Parameters
sModel state to initialise. Does nothing when NULL.
cfgConfiguration to copy. Does nothing when NULL.

◆ servo_sim_step()

float servo_sim_step ( servo_sim_t * s,
uint16_t cmd_us,
uint32_t now_ms )

Advance the model to now_ms with the servo commanded to cmd_us, and return the current its sensor would report.

Parameters
sModel state.
cmd_usCommanded pulse width, us.
now_msCurrent time, ms.
Returns
current the sensor reports, A; 0 when s is NULL.