rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
servo_move.h
Go to the documentation of this file.
1
60
61#pragma once
62
63#include <stdbool.h>
64#include <stdint.h>
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
75#define SERVO_MOVE_MIN_A 0.020f
77#define SERVO_MOVE_NOISE_K 3.0f
80#define SERVO_MOVE_BAND_A 0.05f
83#define SERVO_MOVE_TIMEOUT_MS 3000u
85#define SERVO_MOVE_FILTER_MAX 8u
86
98
100typedef enum {
102 SERVO_MOVE_CLIP_NONE = 0,
105
106typedef struct {
107 uint32_t cmd_t;
108 uint32_t window_t;
109 float rise_a;
110 float ref_a;
111 float move_a;
112 float band_a;
113 uint8_t settle_n;
114 uint8_t filter_n;
117
118typedef struct {
120 servo_move_state_t state;
121 bool left;
123 /* The samples in a row near ref_a, after movement. */
124 uint8_t run_n;
125 float run_lo, run_hi;
126 uint32_t run_t;
127 /* The filter. */
128 float fbuf[SERVO_MOVE_FILTER_MAX];
129 int8_t fclip[SERVO_MOVE_FILTER_MAX];
130 uint8_t f_n, f_head;
131 /* What it measured. */
132 uint32_t moved_t;
133 uint32_t end_t;
134 float sum;
138 uint32_t n;
139 float peak;
140 bool clipped;
143
153float servo_move_noise_a(uint32_t n, float sum, float sum_sq);
154
162float servo_move_threshold_a(float noise_a);
163
170uint32_t servo_move_window_ms(uint32_t lag_ms);
171
181
192void servo_move_prime(servo_move_t *m, float a, servo_move_clip_t clip);
193
210servo_move_state_t servo_move_sample(servo_move_t *m, uint32_t at, float a,
211 servo_move_clip_t clip);
212
223
231bool servo_move_over(const servo_move_t *m);
232
239bool servo_move_arrived(const servo_move_t *m);
240
247bool servo_move_moved(const servo_move_t *m);
248
249#ifdef __cplusplus
250}
251#endif
servo_move_state_t
Where a move stands.
Definition servo_move.h:88
@ SERVO_MOVE_SETTLED
Definition servo_move.h:93
@ SERVO_MOVE_IDLE
Definition servo_move.h:89
@ SERVO_MOVE_MOVING
Definition servo_move.h:91
@ SERVO_MOVE_UNSEEN
Definition servo_move.h:96
@ SERVO_MOVE_WAITING
Definition servo_move.h:90
@ SERVO_MOVE_ARRIVED
Definition servo_move.h:92
@ SERVO_MOVE_LATE
Definition servo_move.h:95
uint32_t servo_move_window_ms(uint32_t lag_ms)
SERVO_MOVE_TIMEOUT_MS plus a meter's lag of lag_ms.
Definition servo_move.c:37
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.
Definition servo_move.c:174
bool servo_move_moved(const servo_move_t *m)
Whether movement was seen.
Definition servo_move.c:310
float servo_move_threshold_a(float noise_a)
The threshold for a noise at rest of noise_a.
Definition servo_move.c:24
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 ...
Definition servo_move.c:107
#define SERVO_MOVE_FILTER_MAX
The longest filter.
Definition servo_move.h:85
bool servo_move_arrived(const servo_move_t *m)
Whether the move arrived: ARRIVED or SETTLED.
Definition servo_move.c:305
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 take...
Definition servo_move.c:42
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.
Definition servo_move.c:14
bool servo_move_over(const servo_move_t *m)
Whether the move is over: arrived, settled, late or unseen.
Definition servo_move.c:300
servo_move_clip_t
A sample at the end of the meter's range.
Definition servo_move.h:100
@ SERVO_MOVE_CLIP_LOW
Definition servo_move.h:101
@ SERVO_MOVE_CLIP_HIGH
Definition servo_move.h:103
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,...
Definition servo_move.c:292
Definition servo_move.h:106
uint32_t window_t
Definition servo_move.h:108
float rise_a
Definition servo_move.h:109
float band_a
Definition servo_move.h:112
uint32_t cmd_t
Definition servo_move.h:107
float move_a
Definition servo_move.h:111
uint8_t settle_n
Definition servo_move.h:113
float ref_a
Definition servo_move.h:110
uint8_t filter_n
Definition servo_move.h:114
Definition servo_move.h:118
uint32_t moved_t
Definition servo_move.h:132
float sum
Definition servo_move.h:134
uint32_t end_t
Definition servo_move.h:133
uint32_t run_t
Definition servo_move.h:126
float peak
Definition servo_move.h:139
bool clipped
Definition servo_move.h:140
bool left
Definition servo_move.h:121