rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
esc_stick.h
Go to the documentation of this file.
1
26
27#ifndef RCBENCH_ESC_STICK_H
28#define RCBENCH_ESC_STICK_H
29
30#include <stdbool.h>
31#include <stddef.h>
32#include <stdint.h>
33
34#include "esc_profile.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
43#define ESC_STICK_MAX_CHANGES 16u
44
49#define ESC_STICK_SIGNAL_MS 1000u
54#define ESC_STICK_ARM_WAIT_MS 3000u
56#define ESC_STICK_POWER_WAIT_MS 3000u
60#define ESC_STICK_STALE_MS 1000u
65#define ESC_STICK_SETTLE_MS 500u
70#define ESC_STICK_LATE_RUN 3u
77#define ESC_STICK_HAND_WAIT_MS 60000u
82#define ESC_STICK_HAND_MIN_MS 1000u
89#define ESC_STICK_OFF_MA 20
91#define ESC_STICK_OFF_SETTLE_MS 200u
92
96#define ESC_STICK_PCT_MIN 0.0f
98#define ESC_STICK_PCT_MID 50.0f
100#define ESC_STICK_PCT_MAX 100.0f
101
108typedef struct {
109 uint32_t beep_min_ms;
110 uint32_t gap_min_ms;
111 uint32_t long_ms;
112 uint32_t long_max_ms;
113 uint32_t group_gap_ms;
114 uint32_t entry_ms;
115 uint32_t store_ms;
116 uint32_t off_ms;
117 uint32_t silence_ms;
118 uint32_t timeout_ms;
119 uint32_t threshold_ma;
120 uint32_t hysteresis_ma;
122
129
139
140/* ------------------------------------------------------- what can run */
141
151
166esc_stick_kind_t esc_stick_kind(const esc_profile_t *p, const char **why);
167
176
184
195uint32_t esc_stick_profile_mv(const esc_profile_t *p);
196
206uint32_t esc_stick_model_mv(const esc_profile_t *p, int model);
207
219uint32_t esc_stick_model_v_max(const esc_profile_t *p, int model);
220
231uint32_t esc_stick_model_ma_max(const esc_profile_t *p, int model);
232
242uint32_t esc_stick_model_v_min(const esc_profile_t *p, int model);
243
253
273 uint32_t mv, uint32_t ma, bool by_hand);
274
289bool esc_stick_rating_unknown(const esc_profile_t *p, int model, uint32_t mv,
290 bool by_hand);
291
301bool esc_stick_is_action(const esc_item_t *it);
302
312const char *esc_stick_not_offered(const esc_item_t *it);
313
317typedef struct {
318 uint8_t item;
319 uint8_t value;
321
334 const esc_stick_change_t *c);
335
350bool esc_stick_check(const esc_profile_t *p, const esc_stick_change_t *ch,
351 size_t n, const esc_stick_timing_t *t, const char **why);
352
353/* ---------------------------------------------------------- the beeps */
354
358typedef enum {
359 ESC_DET_NONE = 0,
364
380typedef struct {
383
384 bool counting;
385 bool seeded;
386 int32_t floor_x16;
388 uint32_t prev_ms;
389 uint32_t iv_max_ms;
390
391 bool high;
392 uint32_t rise_ms, last_high_ms, before_rise_ms;
393 uint32_t n_high;
394 bool stuck_told;
397 uint32_t quiet_from;
398 bool busy;
399 uint32_t busy_from;
400 bool fell;
401 uint32_t fall_ms;
402 uint32_t n_low;
403
404 bool group_open, group_bad;
405 uint8_t shorts, longs;
406
407 /* The last group that ended. */
408 uint8_t count;
409 bool valid;
410} esc_det_t;
411
421 uint8_t long_equals_short);
422
428void esc_det_count(esc_det_t *d);
429
440esc_det_event_t esc_det_reading(esc_det_t *d, uint32_t t_ms, int32_t ma,
441 bool late);
442
449int32_t esc_det_floor_ma(const esc_det_t *d);
450
451/* ------------------------------------------------------------ the run */
452
477
502
510
521esc_stick_reason_t esc_stick_stop_reason(uint32_t stops, uint32_t pressed);
522
535
543
547typedef struct {
548 uint32_t now_ms;
549 bool armed;
550 uint32_t stops;
551 bool link_up;
552 uint32_t pressed;
555
564typedef struct {
565 uint32_t seq;
566 uint32_t at_ms;
567 int32_t ma;
569 bool output;
572 bool online;
574
578typedef struct {
579 bool arm;
582 uint32_t supply_mv;
583 uint32_t supply_ma;
585
587typedef struct {
588 const esc_profile_t *p;
589 esc_stick_kind_t kind;
592 uint8_t n;
593 bool done[ESC_STICK_MAX_CHANGES];
594 uint8_t active;
595
596 esc_stick_phase_t phase;
597 esc_stick_reason_t reason;
598 uint32_t phase_ms;
599 uint32_t now_ms;
600
601 uint32_t stops0;
602 uint32_t pressed0;
603 bool link0;
605 bool off_seen;
608 uint32_t off_asked_ms;
609 uint32_t off_seq;
610 uint32_t off_since_ms;
612 uint8_t store_step;
620
621 esc_stick_out_t out;
622
623 /* The supply as the newest sample had it. */
624 bool have_sample;
625 uint32_t seq;
626 uint32_t read_ms;
628 bool output;
629 bool online;
630 bool current_ok;
631 int32_t ma;
632 uint32_t on_ms;
633 uint32_t late_run;
634 uint32_t iv_ms;
635
636 esc_det_t det;
637 uint32_t heard_ms;
639 /* The groups of this phase, for the sequence check. */
640 uint8_t prev;
642 uint8_t run;
643 uint8_t lo, hi;
644 uint32_t groups;
645 uint8_t last_count;
646 bool last_valid;
651 uint8_t entries;
653 uint32_t entry_wait;
656 uint8_t hand;
663 uint32_t hand_ms;
664 bool end_open;
670 uint32_t pulses;
673
692 const esc_stick_change_t *ch, size_t n,
693 const esc_stick_timing_t *t, uint32_t mv, uint32_t ma,
694 const esc_stick_bench_t *b, const char **why);
695
703
711
722
729bool esc_stick_running(const esc_stick_t *e);
730
738
780
793 const esc_stick_change_t *c,
794 const esc_stick_timing_t *t);
795
803uint32_t esc_stick_entry_ms(const esc_stick_t *e);
804
817bool esc_stick_cut_short(const esc_stick_t *e);
818
827bool esc_stick_end_locks(const esc_stick_t *e);
828
836bool esc_stick_lock_risk(const esc_stick_t *e);
837
845bool esc_stick_hand_ready(const esc_stick_t *e);
846
853uint32_t esc_stick_hand_left_ms(const esc_stick_t *e);
854
866
880
887unsigned esc_stick_done_count(const esc_stick_t *e);
888
898bool esc_stick_unsure(const esc_stick_t *e, unsigned i);
899
907unsigned esc_stick_made_count(const esc_stick_t *e);
908
915unsigned esc_stick_beeps(const esc_stick_t *e);
916
922#define ESC_STICK_BEEP_LIGHT_MS 150u
923
935typedef struct {
936 uint32_t pulses;
937 uint32_t from_ms;
938 bool held;
940
948
958 uint32_t now_ms);
959
960#ifdef __cplusplus
961}
962#endif
963
964#endif /* RCBENCH_ESC_STICK_H */
esc_det_event_t esc_det_reading(esc_det_t *d, uint32_t t_ms, int32_t ma, bool late)
One reading, at t_ms, of ma; late marks it as having come too long after the one before.
Definition esc_det.c:116
int32_t esc_det_floor_ma(const esc_det_t *d)
The idle floor, mA.
Definition esc_det.c:61
void esc_det_count(esc_det_t *d)
Pulses and groups from the next reading on; the floor is kept.
Definition esc_det.c:47
void esc_det_init(esc_det_t *d, const esc_stick_timing_t *t, uint8_t long_equals_short)
Set up the beep detector.
Definition esc_det.c:16
ESC (electronic speed controller) programming profiles: how to enter an ESC's throttle-stick programm...
esc_throttle_t
Throttle stick position that a step uses.
Definition esc_profile.h:99
esc_throttle_t esc_stick_store_move(const esc_stick_t *e, unsigned k)
The k-th move after a selection, from 0, or ESC_THR_NONE past the last: the profile's store move,...
Definition esc_stick.c:515
const esc_manual_t * esc_stick_hand(const esc_stick_t *e)
The manual step the run waits for, or NULL when it waits for none.
Definition esc_stick.c:430
uint32_t esc_stick_change_entry_ms(const esc_profile_t *p, const esc_stick_change_t *c, const esc_stick_timing_t *t)
Power-on to the menu for change c, ms, as the run waits it: its value's entry_hold_ms where the manua...
Definition esc_stick.c:444
bool esc_stick_hand_ready(const esc_stick_t *e)
Whether DONE would count now: ESC_STICK_HAND_MIN_MS after the step was asked.
Definition esc_stick.c:480
bool esc_stick_cut_short(const esc_stick_t *e)
Whether the run ended between a selection and the DONE of the profile's before_power_off steps,...
Definition esc_stick.c:577
uint32_t esc_stick_entry_ms(const esc_stick_t *e)
Power-on to the menu at this power-up, ms: esc_stick_change_entry_ms() of the change it makes.
Definition esc_stick.c:466
void esc_stick_timing_defaults(esc_stick_timing_t *t)
The defaults the settings start from.
Definition esc_stick.c:43
uint32_t esc_stick_read_max_ms(const esc_stick_timing_t *t)
The longest interval between two readings the timing allows: the shorter of a beep and a gap,...
Definition esc_stick.c:62
void esc_stick_sample(esc_stick_t *e, const esc_stick_sample_t *s)
One supply sample, as it arrives.
Definition esc_stick.c:845
bool esc_stick_lock_risk(const esc_stick_t *e)
esc_stick_cut_short() and esc_stick_end_locks(): the ESC may have locked itself.
Definition esc_stick.c:598
bool esc_stick_start(esc_stick_t *e, const esc_profile_t *p, const esc_stick_change_t *ch, size_t n, const esc_stick_timing_t *t, uint32_t mv, uint32_t ma, const esc_stick_bench_t *b, const char **why)
Start a run. mv and ma are the supply's set points, already held to the caps by the caller.
Definition esc_stick.c:726
bool esc_stick_confirm(esc_stick_t *e)
DONE: the step asked is done.
Definition esc_stick.c:500
uint32_t esc_stick_hand_left_ms(const esc_stick_t *e)
The time left to confirm the step asked, ms; 0 when none is.
Definition esc_stick.c:486
void esc_stick_light_reset(esc_stick_light_t *l, const esc_stick_t *e)
Start watching e: pulses already counted do not light it.
Definition esc_stick.c:96
void esc_stick_step(esc_stick_t *e, const esc_stick_bench_t *b)
Advance to b->now_ms and judge the bench.
Definition esc_stick.c:940
bool esc_stick_end_locks(const esc_stick_t *e)
Whether a before_power_off step of the run's profile marks locks: a cut before every such step is con...
Definition esc_stick.c:582
bool esc_stick_light_green(esc_stick_light_t *l, const esc_stick_t *e, uint32_t now_ms)
Whether the green light is on at now_ms.
Definition esc_stick.c:106
void esc_stick_abort(esc_stick_t *e, esc_stick_reason_t why)
End the run now, for why: throttle to its rest, supply off, disarmed.
Definition esc_stick.c:160
esc_det_event_t
Event the beep detector reports for one reading.
Definition esc_stick.h:358
@ ESC_DET_STUCK
Definition esc_stick.h:362
@ ESC_DET_PULSE
Definition esc_stick.h:360
@ ESC_DET_GROUP
Definition esc_stick.h:361
esc_stick_kind_t
Menu kind the engine runs for a profile.
Definition esc_stick.h:145
@ ESC_STICK_KIND_TWO_STAGE
Definition esc_stick.h:147
@ ESC_STICK_KIND_NONE
Definition esc_stick.h:146
@ ESC_STICK_KIND_ONE_STAGE
Definition esc_stick.h:149
esc_stick_phase_t
Phase of a stick programming run.
Definition esc_stick.h:456
@ ESC_STICK_STORE
Definition esc_stick.h:464
@ ESC_STICK_VALUES
Definition esc_stick.h:463
@ ESC_STICK_CYCLE
Definition esc_stick.h:465
@ ESC_STICK_ITEMS
Definition esc_stick.h:462
@ ESC_STICK_HAND_OFF
Definition esc_stick.h:466
@ ESC_STICK_ENTRY
Definition esc_stick.h:461
@ ESC_STICK_POWER
Definition esc_stick.h:460
@ ESC_STICK_ARMING
Definition esc_stick.h:458
@ ESC_STICK_HAND_END
Definition esc_stick.h:470
@ ESC_STICK_OFF
Definition esc_stick.h:473
@ ESC_STICK_SIGNAL
Definition esc_stick.h:459
@ ESC_STICK_HAND_ON
Definition esc_stick.h:468
esc_stick_reason_t
Reason a run ended.
Definition esc_stick.h:479
@ ESC_STICK_R_SUPPLY_OFF
Definition esc_stick.h:487
@ ESC_STICK_R_STOP
Definition esc_stick.h:481
@ ESC_STICK_R_STALE
Definition esc_stick.h:489
@ ESC_STICK_R_NOT_ARMED
Definition esc_stick.h:491
@ ESC_STICK_R_SUPPLY_ON
Definition esc_stick.h:493
@ ESC_STICK_R_LINK
Definition esc_stick.h:486
@ ESC_STICK_R_DISARMED
Definition esc_stick.h:485
@ ESC_STICK_R_NO_POWER
Definition esc_stick.h:492
@ ESC_STICK_R_RATE
Definition esc_stick.h:490
@ ESC_STICK_R_HAND
Definition esc_stick.h:497
@ ESC_STICK_R_BENCH_STOP
Definition esc_stick.h:482
@ ESC_STICK_R_HIGH
Definition esc_stick.h:495
@ ESC_STICK_R_SUPPLY_LOST
Definition esc_stick.h:488
@ ESC_STICK_R_TOUCH
Definition esc_stick.h:498
@ ESC_STICK_R_LEFT
Definition esc_stick.h:500
@ ESC_STICK_R_USER
Definition esc_stick.h:499
@ ESC_STICK_R_TIMEOUT
Definition esc_stick.h:496
@ ESC_STICK_R_NO_BEEPS
Definition esc_stick.h:494
#define ESC_STICK_MAX_CHANGES
The most selections one run makes.
Definition esc_stick.h:43
esc_stick_rating_t
What a supply's set points break of the ESC's ratings.
Definition esc_stick.h:247
@ ESC_STICK_RATING_I_OVER
Definition esc_stick.h:251
@ ESC_STICK_RATING_V_OVER
Definition esc_stick.h:249
@ ESC_STICK_RATING_V_UNDER
Definition esc_stick.h:250
#define s
Short name for esc_stick_s inside the five stick-class files.
Definition esc_stick_panel_int.h:295
unsigned esc_stick_done_count(const esc_stick_t *e)
How many selections have been made.
Definition esc_stick_read.c:109
unsigned esc_stick_made_count(const esc_stick_t *e)
The selections made for certain: esc_stick_done_count() less the one esc_stick_unsure() names.
Definition esc_stick_read.c:124
bool esc_stick_unsure(const esc_stick_t *e, unsigned i)
Whether change i was selected, but the run was cut short before the ESC stored or confirmed it (esc_s...
Definition esc_stick_read.c:118
bool esc_stick_reason_is_fault(esc_stick_reason_t r)
Whether a run that ended for r ended because something was not as expected: a reading,...
Definition esc_stick_read.c:48
bool esc_stick_running(const esc_stick_t *e)
Whether the run is under way: started and neither done nor aborted.
Definition esc_stick_read.c:98
const char * esc_stick_reason_text(esc_stick_reason_t r)
A word or two for the screen.
Definition esc_stick_read.c:13
const esc_stick_out_t * esc_stick_out(const esc_stick_t *e)
What the bench is to do now.
Definition esc_stick_read.c:104
const char * esc_stick_phase_text(esc_stick_phase_t ph)
Short text for a run phase.
Definition esc_stick_read.c:76
esc_stick_reason_t esc_stick_stop_reason(uint32_t stops, uint32_t pressed)
The end stops stops give, pressed of them pressed by an operator, both counted over the same span: ST...
Definition esc_stick_read.c:39
unsigned esc_stick_beeps(const esc_stick_t *e)
The beeps of the group under way.
Definition esc_stick_read.c:133
uint32_t esc_stick_model_ma_max(const esc_profile_t *p, int model)
The continuous current model model of p is rated for, mA: its current_a.
Definition esc_stick_rules.c:293
esc_stick_kind_t esc_stick_kind(const esc_profile_t *p, const char **why)
Which menu the engine runs for p, or ESC_STICK_KIND_NONE with the reason in why (a static string; may...
Definition esc_stick_rules.c:144
uint32_t esc_stick_model_v_min(const esc_profile_t *p, int model)
The lowest input model model of p takes, mV: its v_min_mv.
Definition esc_stick_rules.c:312
bool esc_stick_check(const esc_profile_t *p, const esc_stick_change_t *ch, size_t n, const esc_stick_timing_t *t, const char **why)
Whether a run of n changes under t can start on p; the reason in why when not.
Definition esc_stick_rules.c:502
bool esc_stick_is_action(const esc_item_t *it)
Whether it is an action rather than a setting: keyed reset or exit.
Definition esc_stick_rules.c:363
float esc_stick_pct(esc_throttle_t pos)
A throttle position as the output's percentage.
Definition esc_stick_rules.c:26
uint32_t esc_stick_profile_mv(const esc_profile_t *p)
The supply voltage a profile asks for, mV: the lowest stated cell count among its models at 3800mV a ...
Definition esc_stick_rules.c:244
uint32_t esc_stick_model_mv(const esc_profile_t *p, int model)
The supply voltage for model model of p, mV: its own lowest cell count at the rates above,...
Definition esc_stick_rules.c:263
bool esc_stick_rating_unknown(const esc_profile_t *p, int model, uint32_t mv, bool by_hand)
Whether the data cannot vouch for mv on model model: the rated voltage is not stated,...
Definition esc_stick_rules.c:348
uint32_t esc_stick_model_v_max(const esc_profile_t *p, int model)
The highest supply voltage model model of p is rated for, mV: its v_max_mv.
Definition esc_stick_rules.c:273
esc_throttle_t esc_stick_change_entry(const esc_profile_t *p, const esc_stick_change_t *c)
The stick position change c is powered up from: its value's entry_throttle where the manual names one...
Definition esc_stick_rules.c:383
const char * esc_stick_not_offered(const esc_item_t *it)
Why it is not offered as a change, or NULL when it is: an action, or an item with a single value,...
Definition esc_stick_rules.c:369
esc_stick_rating_t esc_stick_rating(const esc_profile_t *p, int model, uint32_t mv, uint32_t ma, bool by_hand)
Whether mv and ma suit model model of p (-1: every model of the family).
Definition esc_stick_rules.c:329
esc_throttle_t esc_stick_listen(const esc_profile_t *p)
Where the stick rests while the menu sounds: the profile's listen move, else where the entry left it.
Definition esc_stick_rules.c:17
#define k
Short name for kst_panel_k inside the overlay's seven files.
Definition kst_panel_int.h:238
The beep detector: hysteresis on the current above its idle floor, pulse and gap lengths judged in re...
Definition esc_stick.h:380
uint32_t n_low
Definition esc_stick.h:402
uint32_t fall_ms
Definition esc_stick.h:401
uint32_t quiet_from
Definition esc_stick.h:397
uint32_t busy_from
Definition esc_stick.h:399
bool have_prev
Definition esc_stick.h:387
bool seeded
Definition esc_stick.h:385
bool fell
Definition esc_stick.h:400
uint32_t prev_ms
Definition esc_stick.h:388
bool busy
Definition esc_stick.h:398
int32_t floor_x16
Definition esc_stick.h:386
bool counting
Definition esc_stick.h:384
uint32_t iv_max_ms
Definition esc_stick.h:389
bool wait_quiet
Definition esc_stick.h:395
uint8_t long_equals_short
Definition esc_stick.h:382
bool quiet_known
Definition esc_stick.h:396
One menu item: its name, sounded number and values.
Definition esc_profile.h:156
A step a person does at the ESC besides the throttle and the power: fit or pull a jumper,...
Definition esc_profile.h:206
One ESC programming profile: its family, menu and steps.
Definition esc_profile.h:233
What the bench is doing, each step.
Definition esc_stick.h:547
uint32_t pressed
Definition esc_stick.h:552
bool link_up
Definition esc_stick.h:551
uint32_t stops
Definition esc_stick.h:550
uint32_t now_ms
Definition esc_stick.h:548
bool armed
Definition esc_stick.h:549
One selection: the profile's item and value, as indices.
Definition esc_stick.h:317
uint8_t value
Definition esc_stick.h:319
uint8_t item
Definition esc_stick.h:318
The green light: on while the detector holds a pulse, from the reading that rose above the threshold ...
Definition esc_stick.h:935
uint32_t from_ms
Definition esc_stick.h:937
uint32_t pulses
Definition esc_stick.h:936
bool held
Definition esc_stick.h:938
What the bench is to do, after a step.
Definition esc_stick.h:578
uint32_t supply_ma
Definition esc_stick.h:583
float throttle_pct
Definition esc_stick.h:580
bool supply_on
Definition esc_stick.h:581
bool arm
Definition esc_stick.h:579
uint32_t supply_mv
Definition esc_stick.h:582
One supply sample. seq is the supply's count of its own readings, modulo 65536 (supply_state_t's samp...
Definition esc_stick.h:564
uint32_t at_ms
Definition esc_stick.h:566
bool output
Definition esc_stick.h:569
bool current_ok
Definition esc_stick.h:568
int32_t ma
Definition esc_stick.h:567
bool reported_on
Definition esc_stick.h:570
bool online
Definition esc_stick.h:572
State of one stick programming run.
Definition esc_stick.h:587
bool cycle_moved
Definition esc_stick.h:615
bool link_seen
Definition esc_stick.h:604
uint32_t heard_ms
Definition esc_stick.h:637
bool reported_on
Definition esc_stick.h:607
bool sig_moved
Definition esc_stick.h:616
bool hand_done
Definition esc_stick.h:658
uint32_t hand_ms
Definition esc_stick.h:663
bool last_in_order
Definition esc_stick.h:647
uint8_t active
Definition esc_stick.h:594
uint8_t store_step
Definition esc_stick.h:612
uint32_t entry_wait
Definition esc_stick.h:653
uint32_t off_since_ms
Definition esc_stick.h:610
bool prev_trusted
Definition esc_stick.h:641
bool armed_seen
Definition esc_stick.h:619
uint8_t prev
Definition esc_stick.h:640
uint32_t groups
Definition esc_stick.h:644
uint8_t entries
Definition esc_stick.h:651
bool off_since_known
Definition esc_stick.h:611
bool have_reading
Definition esc_stick.h:627
uint32_t off_asked_ms
Definition esc_stick.h:608
uint32_t off_seq
Definition esc_stick.h:609
bool off_seen
Definition esc_stick.h:605
uint32_t read_ms
Definition esc_stick.h:626
uint32_t now_ms
Definition esc_stick.h:599
bool last_trusted
Definition esc_stick.h:649
uint32_t pulses
Definition esc_stick.h:670
uint8_t run
Definition esc_stick.h:642
uint8_t hi
Definition esc_stick.h:643
uint32_t iv_ms
Definition esc_stick.h:634
esc_throttle_t entry
Definition esc_stick.h:652
bool end_open
Definition esc_stick.h:664
bool hand_menu
Definition esc_stick.h:660
uint8_t hand
Definition esc_stick.h:656
uint32_t on_ms
Definition esc_stick.h:632
uint32_t phase_ms
Definition esc_stick.h:598
How the beeps are timed and told apart from the ESC's idle current.
Definition esc_stick.h:108
uint32_t gap_min_ms
Definition esc_stick.h:110
uint32_t long_ms
Definition esc_stick.h:111
uint32_t group_gap_ms
Definition esc_stick.h:113
uint32_t off_ms
Definition esc_stick.h:116
uint32_t entry_ms
Definition esc_stick.h:114
uint32_t beep_min_ms
Definition esc_stick.h:109
uint32_t store_ms
Definition esc_stick.h:115
uint32_t long_max_ms
Definition esc_stick.h:112
uint32_t threshold_ma
Definition esc_stick.h:119
uint32_t silence_ms
Definition esc_stick.h:117
uint32_t hysteresis_ma
Definition esc_stick.h:120
uint32_t timeout_ms
Definition esc_stick.h:118