rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
servo_limrun.h
Go to the documentation of this file.
1
143
144#pragma once
145
146#include <stdbool.h>
147#include <stddef.h>
148#include <stdint.h>
149
150#include "servo_limit.h"
151#include "servo_test.h"
152
153#ifdef __cplusplus
154extern "C" {
155#endif
156
157/* ---------------------------------------------------------- the method */
158
163#define SERVO_LIMRUN_WRITES_MAX 8u
167#define SERVO_LIMRUN_OVERSET_PCT 3u
169#define SERVO_LIMRUN_STD_LOWER_DUS 10000u
170#define SERVO_LIMRUN_STD_UPPER_DUS 20000u
172#define SERVO_LIMRUN_MOVED_US 20u
176#define SERVO_LIMRUN_SEARCH_MS 40000u
182#define SERVO_LIMRUN_RETURN_MS 1000u
185#define SERVO_LIMRUN_PROG_MS 150000u
188#define SERVO_LIMRUN_BENCH_MS 3000u
190#define SERVO_LIMRUN_HARD_MA 3000
191#define SERVO_LIMRUN_STALL_MA 1000
192#define SERVO_LIMRUN_STALL_MS 400u
194#define SERVO_LIMRUN_WIN_STALE_MS SERVO_TEST_WIN_STALE_MS
197#define SERVO_LIMRUN_RAIL_DV_MV 1000
205#define SERVO_LIMRUN_RAIL_MIN_MV 3000
206
207/* ------------------------------------------------------ what it is told */
208
210enum { SERVO_LIMRUN_LO = 0, SERVO_LIMRUN_HI = 1 };
212enum { SERVO_LIMRUN_LEFT = 0, SERVO_LIMRUN_RIGHT = 1 };
214enum {
215 SERVO_LIMRUN_P_NEUTRAL = 0,
216 SERVO_LIMRUN_P_LOWER = 1,
217 SERVO_LIMRUN_P_UPPER = 2,
218};
219
220typedef struct {
221 uint16_t centre_us, min_us, max_us;
225 bool read;
226 bool program;
230
231 /* For the report only. */
232 char dut[24];
233 char type[20];
234 uint16_t frame_hz;
235 char output[28];
236 uint16_t shunt_dmohm;
237 char meter[20];
239 bool enc_on;
240 char firmware[16];
243 const char *const *text;
245
247typedef struct {
248 bool ok;
249 uint16_t angle[2];
250 uint16_t lo_raw;
251 uint16_t hi_raw;
253 unsigned type;
255 uint16_t pulse_dus[3];
258 char backup[16];
260
262typedef struct {
263 bool live;
264 bool safe;
266 float enc_deg;
268
270typedef struct {
271 bool command;
272 uint16_t cmd_us;
273 bool release;
274 bool off;
275 bool disarm;
276 bool arm;
277 bool connect;
278 bool write;
279 uint16_t angle[2];
280 bool pulses;
282 uint16_t pulse_dus[2];
283 bool leave;
285
286/* ------------------------------------------------------ what it reports */
287
288typedef enum {
289 SERVO_LIMRUN_IDLE = 0,
290 SERVO_LIMRUN_RUNNING,
291 SERVO_LIMRUN_DONE,
292} servo_limrun_state_t;
293
294typedef enum {
295 SERVO_LIMRUN_PH_NONE = 0,
299 SERVO_LIMRUN_PH_CONNECT,
300 SERVO_LIMRUN_PH_WRITE,
301 SERVO_LIMRUN_PH_LEAVE,
308
309typedef enum {
313 SERVO_LIMRUN_FAIL,
314 SERVO_LIMRUN_ABORTED,
316
347
349typedef struct {
350 bool done;
351 bool bound;
352 uint16_t limit_us;
353 uint16_t bind_us;
354 uint16_t free_us;
357 bool enc;
359 float enc_deg;
361
362#define SERVO_LIMRUN_OUTBOX 2u
363
364typedef struct {
366 servo_limrun_state_t state;
370 servo_test_abort_t test_why;
371 uint32_t start_ms, end_ms, phase_ms;
373
374 /* The search under way: from ctr_us out to end_us of its side. */
375 uint16_t ctr_us;
376 uint16_t end_us[2];
377 servo_limit_t lf;
378 uint8_t side;
379 uint32_t search_ms;
381 uint16_t cmd_us;
382 bool cmd_due;
383 bool enc_valid;
384 float enc_deg;
385
389
390 /* The programming. */
391 bool read_once;
392 bool dry;
394 uint16_t cur[2];
395 uint16_t pulse_now[3];
396 bool pulse_op;
397 bool searched;
398 uint16_t want[2];
399 int8_t reg_side[2];
400 bool need[2];
401 bool mapped;
402 uint8_t map_side;
403 uint8_t map_reg;
404 uint8_t map_tries;
405 /* By side. */
406 uint8_t stage[2];
407 uint16_t v0[2];
408 uint16_t v1[2];
409 uint16_t v2[2];
410 int32_t d0_dus[2];
411 int32_t db_dus[2];
412 int32_t d1_dus[2];
413 int8_t probe_side;
414 unsigned writes;
415 unsigned write_ops;
416 unsigned sessions;
420
421 /* The meter. */
422 bool have_win;
423 uint32_t last_win_ms;
424 uint32_t windows;
425 bool have_rail;
426 uint16_t rail_mv;
427 bool elevated;
428 uint32_t elevated_ms;
429
430 /* The supply as at its first reading, when one answered. */
431 bool sup_watch;
433 bool sup_out;
434
435 float sup_v, sup_i;
436
437 /* The outbox: OPEN_TXT, the report's lines, END. */
438 unsigned out_line;
439 bool out_open, out_end, out_done;
440 char scratch[SERVO_TEST_LINE_MAX];
441
444
451
464 uint32_t now_ms);
465
473
489 uint32_t now_ms);
490
501 uint32_t now_ms);
511void servo_limrun_written(servo_limrun_t *r, bool ok, const uint16_t *angle,
512 uint32_t now_ms);
522void servo_limrun_pulsed(servo_limrun_t *r, bool ok,
523 const uint16_t *pulse_dus, uint32_t now_ms);
531void servo_limrun_left(servo_limrun_t *r, bool ok, uint32_t now_ms);
532
545void servo_limrun_supply_refused(servo_limrun_t *r, bool output_on,
546 uint32_t now_ms);
547
556void servo_limrun_backup(servo_limrun_t *r, const char *name);
557
565void servo_limrun_refused(servo_limrun_t *r, uint32_t now_ms);
566
579void servo_limrun_no_servo(servo_limrun_t *r, uint32_t now_ms);
580
590void servo_limrun_step(servo_limrun_t *r, uint32_t now_ms,
591 const servo_limrun_in_t *in, servo_limrun_do_t *out);
592
601 uint32_t now_ms);
602
652bool servo_limrun_original(const servo_limrun_t *r, uint16_t *left,
653 uint16_t *right);
654
677
688bool servo_limrun_report_line(const servo_limrun_t *r, unsigned idx,
689 char *buf, size_t n);
690
714
724int32_t servo_limrun_dist(const servo_limrun_servo_t *sv, uint8_t side,
725 uint16_t p_us);
733int32_t servo_limrun_span(const servo_limrun_servo_t *sv, uint8_t side);
745uint16_t servo_limrun_overset(uint16_t v0, int32_t d, int32_t span,
746 uint16_t lo_raw);
758uint16_t servo_limrun_scaled(uint16_t v, int32_t d, int32_t span,
759 uint16_t lo_raw);
760
761#ifdef __cplusplus
762}
763#endif
#define s
Short name for esc_stick_s inside the five stick-class files.
Definition esc_stick_panel_int.h:295
Finding a servo's installed mechanical limit by current.
int32_t servo_limrun_span(const servo_limrun_servo_t *sv, uint8_t side)
Span of one side, as servo_limrun_span() reports it.
Definition servo_limrun.c:92
void servo_limrun_supply(servo_limrun_t *r, const servo_test_reading_t *s, uint32_t now_ms)
The supply's reading.
Definition servo_limrun.c:824
servo_limrun_phase_t
Definition servo_limrun.h:294
@ SERVO_LIMRUN_PH_CHECK
Definition servo_limrun.h:306
@ SERVO_LIMRUN_PH_PROBE
Definition servo_limrun.h:303
@ SERVO_LIMRUN_PH_ARM
Definition servo_limrun.h:302
@ SERVO_LIMRUN_PH_SAFE
Definition servo_limrun.h:297
@ SERVO_LIMRUN_PH_SEARCH
Definition servo_limrun.h:296
bool servo_limrun_restore(const servo_limrun_t *r)
The run ended as FAIL or ABORTED with the servo's values changed: RESTORE gives back the ones before ...
Definition servo_limrun.c:64
int32_t servo_limrun_dist(const servo_limrun_servo_t *sv, uint8_t side, uint16_t p_us)
The share of travel, 0.1us of pulse: p_us's distance from NEUTRAL on side, positive outward,...
Definition servo_limrun.c:84
void servo_limrun_left(servo_limrun_t *r, bool ok, uint32_t now_ms)
Feed the answer to LEAVE: the port is given back.
Definition servo_limrun.c:1124
bool servo_limrun_programming(const servo_limrun_t *r)
The run holds the programmer: CONNECT to LEAVE.
Definition servo_limrun.c:51
void servo_limrun_step(servo_limrun_t *r, uint32_t now_ms, const servo_limrun_in_t *in, servo_limrun_do_t *out)
Advance to now_ms: what to do comes back in out.
Definition servo_limrun.c:1163
void servo_limrun_pulsed(servo_limrun_t *r, bool ok, const uint16_t *pulse_dus, uint32_t now_ms)
Feed the end of the pulse write: the pulses the servo holds.
Definition servo_limrun.c:1096
void servo_limrun_abort(servo_limrun_t *r, servo_test_abort_t why, uint32_t now_ms)
The caller's reasons.
Definition servo_limrun.c:216
servo_str_t servo_limrun_verdict_str(servo_limrun_verdict_t v)
The table entries the screen and the report name these by.
Definition servo_limrun_report.c:491
void servo_limrun_pop(servo_limrun_t *r)
Take the outbox entry last returned by servo_limrun_peek().
Definition servo_limrun_report.c:41
bool servo_limrun_original(const servo_limrun_t *r, uint16_t *left, uint16_t *right)
The values the servo held before the run, valid once read.
Definition servo_limrun.c:69
void servo_limrun_written(servo_limrun_t *r, bool ok, const uint16_t *angle, uint32_t now_ms)
Feed the end of a write: the values the servo holds.
Definition servo_limrun.c:1061
bool servo_limrun_report_line(const servo_limrun_t *r, unsigned idx, char *buf, size_t n)
Line idx of the report into buf; false past the last.
Definition servo_limrun_report.c:478
void servo_limrun_supply_refused(servo_limrun_t *r, bool output_on, uint32_t now_ms)
The caller will not hand the programmer's CONNECT a PD mini that the run did not start with,...
Definition servo_limrun.c:872
servo_test_out_t servo_limrun_peek(servo_limrun_t *r, const char **text)
The report's lines, in order, then END; OPEN_TXT first.
Definition servo_limrun_report.c:17
void servo_limrun_connected(servo_limrun_t *r, const servo_limrun_servo_t *sv, uint32_t now_ms)
The programmer's answers: the servo read after CONNECT, a write's end with the values the servo holds...
Definition servo_limrun.c:985
bool servo_limrun_switching(const servo_limrun_t *r)
The run asked the bench to SAFE or to ARMED and waits for it, or holds the programmer: a disarm then ...
Definition servo_limrun.c:41
bool servo_limrun_wrote(const servo_limrun_t *r)
A value was written and the servo may not hold its own any more.
Definition servo_limrun.c:59
bool servo_limrun_running(const servo_limrun_t *r)
Tell whether the run is RUNNING.
Definition servo_limrun.c:36
void servo_limrun_window(servo_limrun_t *r, const servo_test_win_t *w)
One INA3221 window, as the automatic test takes it.
Definition servo_limrun.c:733
bool servo_limrun_start(servo_limrun_t *r, const servo_limrun_cfg_t *cfg, uint32_t now_ms)
Start at now_ms. False, and nothing started, for a configuration whose centre is not between its MIN ...
Definition servo_limrun.c:695
bool servo_limrun_drained(const servo_limrun_t *r)
Tell whether the run has nothing left to hand over.
Definition servo_limrun_report.c:55
servo_limrun_verdict_t
Definition servo_limrun.h:309
@ SERVO_LIMRUN_FOUND
Definition servo_limrun.h:310
@ SERVO_LIMRUN_PASS
Definition servo_limrun.h:312
@ SERVO_LIMRUN_FREE
Definition servo_limrun.h:311
void servo_limrun_init(servo_limrun_t *r)
Clear a run state to idle.
Definition servo_limrun.c:29
servo_limrun_why_t
Why a run failed or was aborted.
Definition servo_limrun.h:318
@ SERVO_LIMRUN_WHY_TEST
Definition servo_limrun.h:320
@ SERVO_LIMRUN_WHY_BEFORE_NEUTRAL
Definition servo_limrun.h:340
@ SERVO_LIMRUN_WHY_HARD
Definition servo_limrun.h:322
@ SERVO_LIMRUN_WHY_CLIPPED
Definition servo_limrun.h:323
@ SERVO_LIMRUN_WHY_PROG
Definition servo_limrun.h:329
@ SERVO_LIMRUN_WHY_RANGE
Definition servo_limrun.h:343
@ SERVO_LIMRUN_WHY_MAPPING
Definition servo_limrun.h:332
@ SERVO_LIMRUN_WHY_SMALLEST
Definition servo_limrun.h:334
@ SERVO_LIMRUN_WHY_NO_VOLTAGE
Definition servo_limrun.h:337
@ SERVO_LIMRUN_WHY_WRITE
Definition servo_limrun.h:330
@ SERVO_LIMRUN_WHY_NO_STOP
Definition servo_limrun.h:339
@ SERVO_LIMRUN_WHY_STILL_BINDS
Definition servo_limrun.h:336
@ SERVO_LIMRUN_WHY_WRITE_CAP
Definition servo_limrun.h:335
@ SERVO_LIMRUN_WHY_STALL
Definition servo_limrun.h:324
@ SERVO_LIMRUN_WHY_BENCH
Definition servo_limrun.h:327
@ SERVO_LIMRUN_WHY_NEUTRAL
Definition servo_limrun.h:341
@ SERVO_LIMRUN_WHY_OTHER_VALUES
Definition servo_limrun.h:331
@ SERVO_LIMRUN_WHY_SEARCH_LONG
Definition servo_limrun.h:325
@ SERVO_LIMRUN_WHY_SUPPLY_CHANGED
Definition servo_limrun.h:326
@ SERVO_LIMRUN_WHY_NOT_KST
Definition servo_limrun.h:328
void servo_limrun_backup(servo_limrun_t *r, const char *name)
The file the servo's values before the run were saved in, once the programmer names it: its first wri...
Definition servo_limrun.c:887
uint16_t servo_limrun_scaled(uint16_t v, int32_t d, int32_t span, uint16_t lo_raw)
The final value for value v and share d / span: floor(v x share), within lo_raw to v.
Definition servo_limrun.c:142
uint16_t servo_limrun_overset(uint16_t v0, int32_t d, int32_t span, uint16_t lo_raw)
The overset for value v0 and share d / span: ceil(v0 x share x (100 + SERVO_LIMRUN_OVERSET_PCT) / 100...
Definition servo_limrun.c:130
void servo_limrun_refused(servo_limrun_t *r, uint32_t now_ms)
The programmer refused the CONNECT, write or LEAVE asked: it never started.
Definition servo_limrun.c:1138
servo_str_t servo_limrun_phase_str(servo_limrun_phase_t ph)
Table entry for a phase of the limit run.
Definition servo_limrun_report.c:532
servo_str_t servo_limrun_why_str(const servo_limrun_t *r)
Name table entry for the reason of a run.
Definition servo_limrun_report.c:502
void servo_limrun_no_servo(servo_limrun_t *r, uint32_t now_ms)
The programmer's CONNECT ended with no servo answering (KST_SES_ERR_NO_SERVO).
Definition servo_limrun.c:1151
servo_str_t
Definition servo_str.h:24
The automatic servo test: a servo stepped through supply voltages, its current measured at rest,...
servo_test_abort_t
Definition servo_test.h:442
#define SERVO_TEST_LINE_MAX
The longest line a log row or a report line takes, terminator included: the CSV's header with the enc...
Definition servo_test_io.h:134
servo_test_out_t
Definition servo_test_io.h:136
Definition servo_limit.h:117
Definition servo_limrun.h:220
bool enc_on
Definition servo_limrun.h:239
bool program
Definition servo_limrun.h:226
char meter[20]
Definition servo_limrun.h:237
bool set_pulses
Definition servo_limrun.h:228
const char *const * text
The report's language: SERVO_STR_COUNT entries, NULL for English.
Definition servo_limrun.h:243
uint16_t max_us
Definition servo_limrun.h:221
bool read
A KST or Chaservo servo on the programming port: read first, and searched from its NEUTRAL out to its...
Definition servo_limrun.h:225
uint16_t shunt_dmohm
Definition servo_limrun.h:236
char output[28]
Definition servo_limrun.h:235
What the run wants done.
Definition servo_limrun.h:270
bool connect
Definition servo_limrun.h:277
bool pulses
Definition servo_limrun.h:280
bool off
Definition servo_limrun.h:274
bool command
Definition servo_limrun.h:271
uint16_t pulse_dus[2]
Definition servo_limrun.h:282
bool release
Definition servo_limrun.h:273
uint16_t cmd_us
Definition servo_limrun.h:272
bool leave
Definition servo_limrun.h:283
uint16_t angle[2]
Definition servo_limrun.h:279
bool disarm
Definition servo_limrun.h:275
bool arm
Definition servo_limrun.h:276
bool write
Definition servo_limrun.h:278
What the caller knows each step.
Definition servo_limrun.h:262
bool enc_valid
Definition servo_limrun.h:265
float enc_deg
Definition servo_limrun.h:266
bool safe
Definition servo_limrun.h:264
bool live
Definition servo_limrun.h:263
The servo the programmer read.
Definition servo_limrun.h:247
uint16_t angle[2]
Definition servo_limrun.h:249
char backup[16]
The file the values before the run are backed up in; "" for the panel's memory only.
Definition servo_limrun.h:258
uint16_t lo_raw
Definition servo_limrun.h:250
uint16_t hi_raw
Definition servo_limrun.h:251
bool ok
Definition servo_limrun.h:248
bool reversion
Definition servo_limrun.h:252
unsigned type
Definition servo_limrun.h:253
uint16_t pulse_dus[3]
NEUTRAL, PULSE LOWER and PULSE UPPER, 0.1us.
Definition servo_limrun.h:255
What one search of one side found.
Definition servo_limrun.h:349
uint16_t bind_us
Definition servo_limrun.h:353
bool enc
Definition servo_limrun.h:357
uint16_t free_us
Definition servo_limrun.h:354
bool bound
Definition servo_limrun.h:351
float knee_a
Definition servo_limrun.h:356
uint16_t limit_us
Definition servo_limrun.h:352
float baseline_a
Definition servo_limrun.h:355
float enc_deg
The angle at the last free position, from ENC CENTRE.
Definition servo_limrun.h:359
Definition servo_limrun.h:364
servo_limrun_side_t after[2]
Definition servo_limrun.h:387
uint8_t side
Definition servo_limrun.h:378
uint8_t map_reg
Definition servo_limrun.h:403
int32_t d0_dus[2]
Definition servo_limrun.h:410
unsigned writes
Definition servo_limrun.h:414
uint16_t v1[2]
Definition servo_limrun.h:408
bool pulses_landed
Definition servo_limrun.h:417
bool sup_out
Definition servo_limrun.h:433
bool safe_asked
Definition servo_limrun.h:372
uint16_t v2[2]
Definition servo_limrun.h:409
uint16_t want[2]
Definition servo_limrun.h:398
uint16_t cur[2]
Definition servo_limrun.h:394
bool sup_online
Definition servo_limrun.h:432
bool pulse_op
Definition servo_limrun.h:396
bool dry
Definition servo_limrun.h:392
uint8_t map_side
Definition servo_limrun.h:402
int32_t db_dus[2]
Definition servo_limrun.h:411
uint8_t map_tries
Definition servo_limrun.h:404
int8_t probe_side
Definition servo_limrun.h:413
bool programmed
Definition servo_limrun.h:418
servo_limrun_servo_t servo
Definition servo_limrun.h:393
unsigned out_line
Definition servo_limrun.h:438
bool need[2]
Definition servo_limrun.h:400
uint16_t cmd_us
Definition servo_limrun.h:381
servo_limrun_side_t probe
Definition servo_limrun.h:388
int32_t d1_dus[2]
Definition servo_limrun.h:412
uint32_t search_ms
Definition servo_limrun.h:379
uint16_t pulse_now[3]
Definition servo_limrun.h:395
servo_limrun_side_t first[2]
Definition servo_limrun.h:386
unsigned write_ops
Definition servo_limrun.h:415
uint16_t v0[2]
Definition servo_limrun.h:407
uint8_t stage[2]
Definition servo_limrun.h:406
bool searched
Definition servo_limrun.h:397
int8_t reg_side[2]
Definition servo_limrun.h:399
One reading of the supply, as SUPPLY has it (supply_state_t).
Definition servo_test_io.h:25
One 50ms window of INA3221 CH1, as the window ring carries it (sense_link_win_t).
Definition servo_test_io.h:43