aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/pid.h
blob: 907d244be97d63db29a37cad866c1db6b6cd75e3 (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
#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;
};

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,
	      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_ */
bues.ch cgit interface