rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
servo_limit.h
Go to the documentation of this file.
1
31
32#pragma once
33
34#include <stdbool.h>
35#include <stdint.h>
36
37typedef enum {
38 SERVO_LIMIT_RUNNING = 0,
39 SERVO_LIMIT_FOUND,
40 SERVO_LIMIT_FAULT,
41} servo_limit_state_t;
42
62
64#define SERVO_LIMIT_MIN_US 500u
65#define SERVO_LIMIT_MAX_US 2500u
66
67typedef struct {
68 uint16_t centre_us;
69 int16_t step_us;
70 uint16_t max_travel_us;
71
72 uint16_t settle_ms;
73 uint16_t measure_ms;
74
85 float knee_margin_a;
86
88
102 uint16_t stall_ms;
103 uint16_t backoff_us;
105
114void servo_limit_defaults(servo_limit_cfg_t *cfg, uint16_t centre_us,
115 bool positive);
116
117typedef struct {
119 servo_limit_state_t state;
121
122 uint16_t cmd_us;
123 uint16_t last_free_us;
124 uint16_t limit_us;
125
127 float knee_a;
128
129 /* Internals: the settle/measure cycle at each position. */
130 uint32_t phase_start_ms;
131 bool measuring;
132 double sum_a;
133 uint32_t samples;
134 uint32_t baseline_steps;
135 double baseline_sum;
136 uint32_t elevated_since_ms;
137 bool elevated;
138 bool started;
140
148
163uint16_t servo_limit_step(servo_limit_t *lf, float current_a, uint32_t now_ms);
164
172float servo_limit_progress(const servo_limit_t *lf);
float servo_limit_progress(const servo_limit_t *lf)
How far the search has gone, 0..1, for a progress bar.
Definition servo_limit.c:297
servo_limit_fault_t
Definition servo_limit.h:43
@ SERVO_LIMIT_FAULT_NO_LIMIT
The whole permitted travel was covered without binding.
Definition servo_limit.h:56
@ SERVO_LIMIT_FAULT_OVERCURRENT
Current crossed the hard ceiling.
Definition servo_limit.h:48
@ SERVO_LIMIT_FAULT_STALL
Current stayed above the knee for longer than the stall timeout.
Definition servo_limit.h:51
@ SERVO_LIMIT_FAULT_BAD_CONFIG
step_us is 0: no step can reach a stop.
Definition servo_limit.h:60
void servo_limit_init(servo_limit_t *lf, const servo_limit_cfg_t *cfg)
Start a limit search.
Definition servo_limit.c:90
uint16_t servo_limit_step(servo_limit_t *lf, float current_a, uint32_t now_ms)
Advance the search with one current reading, and return the pulse width the servo should be commanded...
Definition servo_limit.c:227
void servo_limit_defaults(servo_limit_cfg_t *cfg, uint16_t centre_us, bool positive)
Defaults for a hobby servo on a control surface.
Definition servo_limit.c:64
Definition servo_limit.h:67
float stall_above_a
Working hard: above this the servo is doing real work, and it may not do so for longer than stall_ms.
Definition servo_limit.h:101
int16_t step_us
Definition servo_limit.h:69
uint16_t measure_ms
Definition servo_limit.h:73
uint16_t settle_ms
Definition servo_limit.h:72
float hard_limit_a
Definition servo_limit.h:87
uint16_t max_travel_us
Definition servo_limit.h:70
uint16_t stall_ms
Definition servo_limit.h:102
float knee_ratio
The knee. Current must exceed the free-running baseline by both a ratio and an absolute margin before...
Definition servo_limit.h:84
uint16_t centre_us
Definition servo_limit.h:68
uint16_t backoff_us
Definition servo_limit.h:103
Definition servo_limit.h:117
uint16_t cmd_us
Definition servo_limit.h:122
uint16_t limit_us
Definition servo_limit.h:124
float baseline_a
Definition servo_limit.h:126
uint16_t last_free_us
Definition servo_limit.h:123
uint32_t baseline_steps
Definition servo_limit.h:134
float knee_a
Definition servo_limit.h:127