dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pid.h
Go to the documentation of this file.
1 
16 /*
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful, but
23  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25  * for more details.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, see <http://www.gnu.org/licenses/>
29  */
30 
31 #ifndef PID_H
32 #define PID_H
33 
34 struct pid_deadband {
35  float width; // Deadband width in degrees per second.
36  float slope; // Deadband slope (0..1).
37  float cubic_weight; // Cubic weight.
38  float integrated_response; // Response at deadband edge.
39 };
40 
42 struct pid {
43  float p;
44  float i;
45  float d;
46  float iLim;
47 
48  float dT;
49 
50  float iAccumulator;
51  float lastErr;
52  float lastDer;
53 };
54 
56 float pid_apply(struct pid *pid, const float err);
57 float pid_apply_antiwindup(struct pid *pid, const float err, float min_bound, float max_bound, float aw_bound);
58 float pid_apply_setpoint(struct pid *pid, struct pid_deadband *deadband, const float setpoint, const float measured);
60  struct pid_deadband *deadband, const float setpoint,
61  const float measured, float min_bound, float max_bound, float aw_bound);
62 void pid_zero(struct pid *pid);
63 void pid_configure(struct pid *pid, float p, float i, float d, float iLim, float dT);
64 void pid_configure_derivative(float cutoff, float gamma);
65 void pid_configure_deadband(struct pid_deadband *deadband, float width, float slope);
66 
67 
68 #endif /* PID_H */
69 
float pid_apply_setpoint_antiwindup(struct pid *pid, struct pid_deadband *deadband, const float setpoint, const float measured, float min_bound, float max_bound, float aw_bound)
Definition: pid.c:187
float p
Definition: pid.h:43
float iAccumulator
Definition: pid.h:50
float cubic_weight
Definition: pid.h:37
void pid_configure(struct pid *pid, float p, float i, float d, float iLim, float dT)
Definition: pid.c:280
void pid_configure_deadband(struct pid_deadband *deadband, float width, float slope)
Definition: pid.c:298
float i
Definition: pid.h:44
float width
Definition: pid.h:35
uint8_t i
Definition: msp_messages.h:97
float iLim
Definition: pid.h:46
uint8_t d
Definition: msp_messages.h:98
float d
Definition: pid.h:45
void pid_zero(struct pid *pid)
Definition: pid.c:252
float lastDer
Definition: pid.h:52
float pid_apply(struct pid *pid, const float err)
Methods to use the pid structures.
Definition: pid.c:48
float integrated_response
Definition: pid.h:38
float pid_apply_setpoint(struct pid *pid, struct pid_deadband *deadband, const float setpoint, const float measured)
Definition: pid.c:141
float pid_apply_antiwindup(struct pid *pid, const float err, float min_bound, float max_bound, float aw_bound)
Definition: pid.c:86
void pid_configure_derivative(float cutoff, float g)
Configure the common terms that alter ther derivative.
Definition: pid.c:267
uint8_t p
Definition: msp_messages.h:96
Definition: pid.h:42
float dT
Definition: pid.h:48
float lastErr
Definition: pid.h:51
float slope
Definition: pid.h:36