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

Simulated ESC in its throttle-stick menu, with its supply current. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "esc_profile.h"

Go to the source code of this file.

Data Structures

struct  esc_sim_cfg_t
 Timing and fault settings of the simulated ESC. More...
struct  esc_sim_t
 Full state of one simulated ESC. More...

Macros

#define ESC_SIM_LOOP_MAX   64u
 Most group numbers in the loop being sounded.
#define ESC_SIM_PULSE_MAX   16u
 Most pulses in one group's beep sequence.

Enumerations

enum  esc_sim_mode_t {
  ESC_SIM_OFF = 0 , ESC_SIM_IDLE , ESC_SIM_ENTRY , ESC_SIM_WAIT_LISTEN ,
  ESC_SIM_ITEMS , ESC_SIM_VALUES , ESC_SIM_PENDING , ESC_SIM_DONE
}
 Mode of the simulated ESC's menu. More...

Functions

void esc_sim_defaults (esc_sim_cfg_t *c)
 Fill a simulator config with its default settings.
void esc_sim_init (esc_sim_t *s, const esc_profile_t *p, const esc_sim_cfg_t *c)
 Start a simulated ESC on a profile.
int32_t esc_sim_step (esc_sim_t *s, uint32_t now_ms, bool powered, float throttle_pct)
 Advance the simulated ESC to a time and return its supply current.
void esc_sim_hand (esc_sim_t *s, uint32_t now_ms)
 Record the person's action at the ESC.
unsigned esc_sim_store_moves (const esc_profile_t *p, uint8_t item, uint8_t value, esc_throttle_t *out, size_t cap)
 List the moves that store a selected value.
uint8_t esc_sim_stored (const esc_sim_t *s, uint8_t item)
 Value stored for an item.

Detailed Description

Simulated ESC in its throttle-stick menu, with its supply current.

A simulated ESC (electronic speed controller) in its throttle-stick menu, as the supply current shows it: an idle current, and a pulse on top for every beep.

It follows a profile the way the stick programmer reads one: power on at the entry position, or at a position a value is programmed from (its entry_throttle), enters the menu; the groups loop, a move to the select position after a group selects it, and in a two-stage menu a move to the value_select position after a value group stores the value. Where the profile names a store move, or the value moves after its selection (after_select), the selection waits for each in order and is lost if the power goes first. An item keyed exit leaves the menu when it is selected, and one keyed reset clears what was stored. A value stored from a power-up at another position than its own is counted as misplaced: the ESC would teach that position. What it stores is kept across power cycles, as an ESC keeps it.

The timing is made up, as the stick programmer's defaults are: no ESC has been recorded. The host suite runs the engine against it end to end, and the panel runs it as the ESC on its modelled supply.

SPDX-License-Identifier: MIT

Enumeration Type Documentation

◆ esc_sim_mode_t

Mode of the simulated ESC's menu.

Enumerator
ESC_SIM_IDLE 

powered, not in the menu

ESC_SIM_WAIT_LISTEN 

the menu waits for the stick at its rest

ESC_SIM_PENDING 

selected, waiting for the store move

ESC_SIM_DONE 

stored; one change per power-up

Function Documentation

◆ esc_sim_defaults()

void esc_sim_defaults ( esc_sim_cfg_t * c)

Fill a simulator config with its default settings.

Parameters
cReceives the defaults.

◆ esc_sim_hand()

void esc_sim_hand ( esc_sim_t * s,
uint32_t now_ms )

Record the person's action at the ESC.

The person's action at the ESC – the jumper pulled, the button pressed – at now_ms. With wait_hand, a menu waiting for it starts; one done before the entry ends lets the menu start when it does.

Parameters
sThe simulator.
now_msTime of the action, ms.

◆ esc_sim_init()

void esc_sim_init ( esc_sim_t * s,
const esc_profile_t * p,
const esc_sim_cfg_t * c )

Start a simulated ESC on a profile.

Parameters
sThe simulator to set up.
pThe profile the simulated ESC follows.
cThe timing and fault settings.

◆ esc_sim_step()

int32_t esc_sim_step ( esc_sim_t * s,
uint32_t now_ms,
bool powered,
float throttle_pct )

Advance the simulated ESC to a time and return its supply current.

Advance to now_ms with the supply powered and the signal at throttle_pct, negative for no signal. Returns the current it draws, mA. Call it often enough for its pulses: in the host suite every few milliseconds, on the panel at the supply's 50ms.

Parameters
sThe simulator.
now_msTime of this step, ms.
poweredWhether the supply is on.
throttle_pctThrottle signal, percent; negative for no signal.
Returns
The current drawn, mA.

◆ esc_sim_store_moves()

unsigned esc_sim_store_moves ( const esc_profile_t * p,
uint8_t item,
uint8_t value,
esc_throttle_t * out,
size_t cap )

List the moves that store a selected value.

The moves that store value value of the item numbered item once it is selected, into out: the profile's store move, then the value's own after_select, of the first item and value of those numbers – items that apply to different models may share both. At most cap are written; returns how many.

Parameters
pThe profile.
itemItem number.
valueValue number.
outReceives the moves.
capCapacity of out, in moves.
Returns
The number of moves written.

◆ esc_sim_stored()

uint8_t esc_sim_stored ( const esc_sim_t * s,
uint8_t item )

Value stored for an item.

The value stored for the item numbered item, 0 when none was.

Parameters
sThe simulator.
itemItem number.
Returns
The stored value, or 0 when none was stored.