summaryrefslogtreecommitdiffstats
path: root/firmware/pid.h
blob: 4494f8f7ee9a318fca97be38e01942178a99ebe2 (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
#ifndef PID_H_
#define PID_H_

#include "fixpt.h"


struct pid {
	fixpt_t kp;
	fixpt_t ki;
	fixpt_t kd;
	fixpt_t d_decay_div;

	fixpt_t setpoint;
	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,
		     fixpt_t kp, fixpt_t ki, fixpt_t kd);

static inline void pid_set_d_decay_div(struct pid *pid, fixpt_t decay_div)
{
	pid->d_decay_div = decay_div;
}

void pid_init(struct pid *pid,
	      fixpt_t kp, fixpt_t ki, fixpt_t kd,
	      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