-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpid.h
98 lines (68 loc) · 1.51 KB
/
pid.h
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Author: Wojciech Domski
* Email: [email protected]
* Webpage: www.Domski.pl
* Blog: www.blog.Domski.pl
*
* Copyright 2018 Wojciech Domski
*/
#ifndef PID_H_
#define PID_H_
#include <stdint.h>
#define PID_PROPORTIONAL_OFF 0.0f
#define PID_INTEGRAL_OFF 0.0f
#define PID_DERIVATIVE_OFF 0.0f
typedef struct {
int32_t p;
int32_t i;
int32_t d;
int32_t p_val;
int32_t i_val;
int32_t d_val;
int32_t p_max;
int32_t i_max;
int32_t d_max;
int32_t p_min;
int32_t i_min;
int32_t d_min;
uint8_t f;
uint32_t power;
int32_t dv;
int32_t mv;
int32_t e_last;
int32_t sum;
int32_t total_max;
int32_t total_min;
int32_t control;
int32_t dt_ms;
} pid_i32_t;
typedef struct {
float p;
float i;
float d;
float p_val;
float i_val;
float d_val;
float p_max;
float i_max;
float d_max;
float p_min;
float i_min;
float d_min;
float dv;
float mv;
float e_last;
float sum;
float total_max;
float total_min;
float control;
float dt_s;
} pid_f32_t;
int pid_i32_init(pid_i32_t * pid, float p, float i, float d, uint8_t f, int32_t dt_ms);
int32_t pid_i32_calc(pid_i32_t * pid, int32_t mv, int32_t dv);
int32_t pid_i32_scale(pid_i32_t * pid, float v);
int pid_i32_reset_int(pid_i32_t * pid);
int pid_f32_init(pid_f32_t * pid, float p, float i, float d, float dt_s);
float pid_f32_calc(pid_f32_t * pid, float mv, float dv);
int pid_f32_reset_int(pid_f32_t * pid);
#endif /* PID_H_ */