-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpid_s16.h
188 lines (148 loc) · 6.83 KB
/
pid_s16.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/**********************************************************************************
** ENVIROMENT VARIABILE
**********************************************************************************/
#ifndef PID_S16_H_
#define PID_S16_H_
/**********************************************************************************
** GLOBAL INCLUDES
**********************************************************************************/
/**********************************************************************************
** DEFINES
**********************************************************************************/
//Floating point position of the PID
#define PID_GAIN_FP 8
/**********************************************************************************
** MACROS
**********************************************************************************/
/**********************************************************************************
** NAMESPACE
**********************************************************************************/
//! @namespace OrangeBot
namespace OrangeBot
{
/**********************************************************************************
** TYPEDEFS
**********************************************************************************/
/**********************************************************************************
** PROTOTYPE: STRUCTURES
**********************************************************************************/
/**********************************************************************************
** PROTOTYPE: GLOBAL VARIABILES
**********************************************************************************/
/**********************************************************************************
** PROTOTYPE: CLASS
**********************************************************************************/
/************************************************************************************/
//! @class Dummy
/************************************************************************************/
//! @author Orso Eric
//! @version 0.1 alpha
//! @date 2019-11-08
//! @brief PID
//! @details
//! Advanced PID Library \n
//! FEATURES: \n
//! Command Saturation \n
//! Detect when command is saturated \n
//! This inibiths the integrator from growing, improving response time \n
//! This allow a detection of PID unlock when the command is saturated for too long, meaning the PID can't keep up \n
//! @pre No prerequisites
//! @bug None
//! @warning No warnings
//! @copyright License ?
//! @todo todo list
/************************************************************************************/
class Pid_s16
{
//Visible to all
public:
//--------------------------------------------------------------------------
// CONSTRUCTORS
//--------------------------------------------------------------------------
//! Default constructor
Pid_s16( void );
//--------------------------------------------------------------------------
// DESTRUCTORS
//--------------------------------------------------------------------------
//!Default destructor
~Pid_s16( void );
//--------------------------------------------------------------------------
// OPERATORS
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// SETTERS
//--------------------------------------------------------------------------
//Set command saturation error and error handler
bool register_error_handler( uint16_t sat_th, void *handler );
//--------------------------------------------------------------------------
// GETTERS
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// REFERENCES
//--------------------------------------------------------------------------
//PID limits
int16_t &limit_cmd_max( void );
int16_t &limit_cmd_min( void );
uint16_t &limit_sat_th( void );
//Set PID gain parameters
int16_t &gain_kp( void );
int16_t &gain_kd( void );
int16_t &gain_ki( void );
//--------------------------------------------------------------------------
// TESTERS
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// PUBLIC METHODS
//--------------------------------------------------------------------------
//Execute a step of the PID controller
int16_t exe( int16_t reference, int16_t feedback );
//Execute a step of the PID controller. Give directly error.
int16_t exe( int16_t err );
//--------------------------------------------------------------------------
// PUBLIC STATIC METHODS
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// PUBLIC VARS
//--------------------------------------------------------------------------
//Visible to derived classes
protected:
//--------------------------------------------------------------------------
// PROTECTED METHODS
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// PROTECTED VARS
//--------------------------------------------------------------------------
//Visible only inside the class
private:
//--------------------------------------------------------------------------
// PRIVATE METHODS
//--------------------------------------------------------------------------
//! dummy method for easy copy
bool dummy( void );
//--------------------------------------------------------------------------
// PRIVATE VARS
//--------------------------------------------------------------------------
//!Error handler
void *g_err_handler;
//!Parameters
//PID core gain parameters
int16_t g_kp, g_kd, g_ki;
//Command Saturation limits. Maximum command allowed
int16_t g_cmd_max, g_cmd_min;
//If command is saturated a number of cycle bigger than this number, a PID unlock error is issued. Zero means that the detection is inactive
uint16_t g_sat_th;
//!Memories
//PID integral accumulator
int16_t g_acc;
//PID derivative memory buffer
int16_t g_old_err;
//Counter that stores the number of consecutive execution in which command is saturated
uint16_t g_sat_cnt;
}; //End Class: Pid_s16
/**********************************************************************************
** NAMESPACE
**********************************************************************************/
} //End Namespace
#else
#warning "Multiple inclusion of hader file"
#endif