PER Firmware
Loading...
Searching...
No Matches
bangbang.h
Go to the documentation of this file.
1
#ifndef BANGBANG_H
2
#define BANGBANG_H
3
11
#include <stdint.h>
12
13
typedef
struct
{
14
float
upper_bound;
// the value above which the controller should turn on
15
float
lower_bound;
// the value below which the controller should turn off
16
17
void (*on_func)(void);
// function to call when the controller turns on (can be nullptr)
18
void (*off_func)(void);
// function to call when the controller turns off (can be nullptr)
19
20
uint32_t min_switch_interval;
// minimum time between state changes to prevent chattering
21
uint32_t last_switch_ms;
// timestamp of the last state change
22
23
bool
is_on;
// current state of the controller (true for on, false for off)
24
}
bangbang_t
;
25
26
#define INIT_BANG_BANG(name, upper, lower, on_callback, off_callback, min_interval) \
27
bangbang_t name = { \
28
.upper_bound = upper, \
29
.lower_bound = lower, \
30
.on_func = on_callback, \
31
.off_func = off_callback, \
32
.min_switch_interval = min_interval, \
33
.last_switch_ms = 0, \
34
.is_on = false \
35
}; \
36
static_assert(upper > lower, "Upper bound must be greater than lower bound for bang-bang controller");
37
38
void
bangbang_update
(
bangbang_t
*controller,
float
value, uint32_t current_time);
39
40
#endif
// BANGBANG_H
bangbang_update
void bangbang_update(bangbang_t *controller, float value, uint32_t current_time)
Update the state of the bang-bang controller based on the input value and current time....
Definition
bangbang.c:18
bangbang_t
Definition
bangbang.h:13
common
bangbang
bangbang.h
Generated by
1.12.0