blob: 80e7a5b6b166d22aeea3d78825bb5beb79784f08 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#ifndef PID_H_
#define PID_H_
#include "fixpt.h"
struct pid_k_set {
fixpt_t kp;
fixpt_t ki;
fixpt_t kd;
fixpt_t d_decay_div;
};
struct pid {
struct pid_k_set k;
fixpt_t setpoint;
fixpt_t i_neglim;
fixpt_t i_poslim;
fixpt_t y_neglim;
fixpt_t y_poslim;
fixpt_t prev_e;
fixpt_t integr;
#if CONF_DEBUG
const char __flash *name;
fixpt_t debug_old_e;
fixpt_t debug_old_p;
fixpt_t debug_old_i;
fixpt_t debug_old_d;
fixpt_t debug_old_pe;
#endif
};
void pid_reset(struct pid *pid);
void pid_set_factors(struct pid *pid, const struct pid_k_set *k);
void pid_init(struct pid *pid,
#if CONF_DEBUG
const char __flash *name,
#endif
const struct pid_k_set *k,
fixpt_t i_neglim, fixpt_t i_poslim,
fixpt_t y_neglim, fixpt_t y_poslim);
static inline void pid_set_setpoint(struct pid *pid, fixpt_t setpoint)
{
pid->setpoint = setpoint;
}
static inline fixpt_t pid_get_setpoint(struct pid *pid)
{
return pid->setpoint;
}
fixpt_t pid_run(struct pid *pid, fixpt_t dt, fixpt_t r);
#endif /* PID_H_ */
|