rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
supply.h
Go to the documentation of this file.
1
16
17#ifndef RCBENCH_SUPPLY_H
18#define RCBENCH_SUPPLY_H
19
20#include <stdbool.h>
21#include <stdint.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
32typedef struct {
33 float v_min,
36 float i_min,
40
50#define SUPPLY_CAPS_PPS_DEFAULT { 3.3f, 21.0f, 0.02f, 0.5f, 5.0f, 0.05f }
51
61
63#define SUPPLY_OK_VOLTAGE 0x01u
64#define SUPPLY_OK_CURRENT 0x02u
65
69typedef struct {
70 float set_v;
71 float set_i;
72 float v;
73 float i;
74 float p;
76 bool output;
77 bool online;
78 bool modelled;
79 uint8_t ok;
84 uint8_t trip;
92 uint16_t samples;
100 uint32_t taken_ms;
101 bool stamped;
102
103 /* The run's extremes, from the output's switch-on: how far the voltage
104 * sagged, and the most current and power it gave. */
105 float v_min;
106 float i_max;
107 float p_max;
109
110 /* What the run delivered, counted by the panel (supply_count_totals). */
111 float charge_mah;
112 float energy_wh;
113 uint8_t counted;
115
122typedef struct {
123 float v_max;
124 float i_max;
125 float trip_i;
126 float trip_v;
127 float trip_s;
129
140 const supply_limits_t *lim);
141
145typedef enum {
146 SUPPLY_TRIP_NONE = 0,
147 SUPPLY_TRIP_CURRENT,
148 SUPPLY_TRIP_VOLTAGE,
150
155typedef struct {
156 float over_i_s;
157 float over_v_s;
158 bool i_over;
159 bool v_over;
160 float i_at;
161 float v_at;
163
170
189 const supply_limits_t *lim,
190 const supply_state_t *s, float dt_s);
191
204float supply_snap(float value, float min, float max, float step);
205
216
223
230
240void supply_count_totals(supply_state_t *s, float dt_s);
241
242/* ---------------------------------------------------------------- model */
243
255#define SUPPLY_SIM_LOAD_OHMS 6.0f
256#define SUPPLY_SIM_PERIOD_S 3.0f
257#define SUPPLY_SIM_BURST_S 0.6f
258#define SUPPLY_SIM_BURST_A 1.4f
259#define SUPPLY_SIM_SOURCE_OHMS 0.05f
260
264typedef struct {
265 supply_caps_t caps;
266 float t;
267 float set_v,
269 bool output;
271
285void supply_sim_set(supply_sim_t *m, float v, float i);
292void supply_sim_output(supply_sim_t *m, bool on);
302void supply_sim_step(supply_sim_t *m, float dt_s, supply_state_t *out);
303
304#ifdef __cplusplus
305}
306#endif
307
308#endif /* RCBENCH_SUPPLY_H */
#define s
Short name for esc_stick_s inside the five stick-class files.
Definition esc_stick_panel_int.h:295
What a supply can be set to.
Definition supply.h:32
float v_step
Definition supply.h:35
float v_min
Definition supply.h:33
float i_min
Definition supply.h:36
float i_step
Definition supply.h:38
float i_max
Definition supply.h:37
float v_max
Definition supply.h:34
What the operator allows, on top of what the supply can do: caps on the set points,...
Definition supply.h:122
float i_max
Definition supply.h:124
float v_max
Definition supply.h:123
float trip_i
Definition supply.h:125
float trip_v
Definition supply.h:126
float trip_s
Definition supply.h:127
The state of the supply model.
Definition supply.h:264
float t
Definition supply.h:266
float set_i
Definition supply.h:268
float set_v
Definition supply.h:267
bool output
Definition supply.h:269
A supply's readings, set points, mode and trip state.
Definition supply.h:69
supply_mode_t mode
Definition supply.h:75
float set_v
Definition supply.h:70
uint16_t samples
Readings the supply has taken, modulo 65536: a new count is a new reading, and the same count read ag...
Definition supply.h:92
bool online
Definition supply.h:77
uint8_t counted
Definition supply.h:113
float v
Definition supply.h:72
float i
Definition supply.h:73
uint32_t taken_ms
When the panel had this reading, on its millisecond clock: the page read that brought it,...
Definition supply.h:100
bool sag_seeded
Definition supply.h:108
uint8_t ok
Definition supply.h:79
bool output
Definition supply.h:76
float set_i
Definition supply.h:71
bool stamped
Definition supply.h:101
uint8_t trip
The trip that switched the output off last, as supply_trip_kind_t; kept until the output is switched ...
Definition supply.h:84
bool modelled
Definition supply.h:78
float p
Definition supply.h:74
How long each reading has been over its threshold, counted from the first reading seen over it,...
Definition supply.h:155
float v_at
Definition supply.h:161
bool v_over
Definition supply.h:159
bool i_over
Definition supply.h:158
float i_at
Definition supply.h:160
void supply_track_peaks(supply_state_t *s)
Take this sample into the run's extremes, only what arrived.
Definition supply.c:53
supply_caps_t supply_caps_limited(const supply_caps_t *caps, const supply_limits_t *lim)
The supply's caps narrowed by lim: the set points a screen offers.
Definition supply.c:107
void supply_reset_totals(supply_state_t *s)
The run begins: nothing delivered, nothing counted.
Definition supply.c:73
void supply_count_totals(supply_state_t *s, float dt_s)
Add dt_s of the readings to the run's charge and energy while the output is on, only what arrived; dt...
Definition supply.c:83
supply_mode_t
The output mode of a supply: off, constant voltage or constant current.
Definition supply.h:56
@ SUPPLY_MODE_CV
Definition supply.h:58
@ SUPPLY_MODE_OFF
Definition supply.h:57
@ SUPPLY_MODE_CC
Definition supply.h:59
supply_trip_kind_t
The trips: none, current and voltage.
Definition supply.h:145
void supply_sim_set(supply_sim_t *m, float v, float i)
Set points are snapped to the caps; the output's state is kept.
Definition supply.c:239
void supply_trip_reset(supply_trip_t *t)
Clears the trip state.
Definition supply.c:129
void supply_sim_output(supply_sim_t *m, bool on)
Switches the model's output on or off.
Definition supply.c:248
float supply_snap(float value, float min, float max, float step)
value clamped to min .. max and rounded to a multiple of step above min.
Definition supply.c:17
supply_trip_kind_t supply_trip_step(supply_trip_t *t, const supply_limits_t *lim, const supply_state_t *s, float dt_s)
Take dt_s of the readings in s into the trips.
Definition supply.c:192
void supply_sim_init(supply_sim_t *m)
Sets up the supply model.
Definition supply.c:224
void supply_reset_peaks(supply_state_t *s)
The run's extremes start again from what is shown, and only from readings that arrived; a maximum wit...
Definition supply.c:38
void supply_sim_step(supply_sim_t *m, float dt_s, supply_state_t *out)
Advance dt_s and write the readings, mode and set points into out, counting one more sample; peaks,...
Definition supply.c:259