MAV'RIC
pid_controller.h
1 /*******************************************************************************
2  * Copyright (c) 2009-2014, MAV'RIC Development Team
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  ******************************************************************************/
31 
32 /*******************************************************************************
33  * \file pid_control.h
34  *
35  * \author MAV'RIC Team
36  * \author Felix Schill
37  *
38  * \brief PID controller
39  *
40  ******************************************************************************/
41 
42 
43 #ifndef PID_CONTROL_H_
44 #define PID_CONTROL_H_
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 #include <stdint.h>
51 #include <math.h>
52 
53 
57 typedef struct
58 {
59  float pregain;
60  float postgain;
61  float accumulator;
62  float clip;
63 } integrator_t;
64 
65 
69 typedef struct
70 {
71  float gain;
72  float previous;
73  float LPF;
74  float clip;
76 
77 
81 typedef struct
82 {
83  float p_gain;
84  float clip_min;
85  float clip_max;
90 
91 
95 typedef struct
96 {
97  float p_gain;
98  float clip_min;
99  float clip_max;
102  float output;
103  float error;
104  uint32_t last_update;
105  float dt;
108 
109 
116 void pid_controller_init(pid_controller_t* controller, const pid_controller_conf_t* config);
117 
118 
124 void pid_controller_init_pass_through(pid_controller_t* controller);
125 
126 
132 void pid_controller_reset_integrator(pid_controller_t* controller);
133 
134 
143 float pid_controller_update(pid_controller_t* controller, float error);
144 
145 
155 float pid_controller_update_dt(pid_controller_t* controller, float error, float dt);
156 
157 
158 #ifdef __cplusplus
159 }
160 #endif
161 
162 #endif /* PID_CONTROL_H_ */
float p_gain
Proportional gain.
Definition: pid_controller.h:97
float clip_min
Min clipping values.
Definition: pid_controller.h:84
Integrator part of PID.
Definition: pid_controller.h:57
float accumulator
Accumulator.
Definition: pid_controller.h:61
integrator_t integrator
Integrator parameters.
Definition: pid_controller.h:86
float clip_max
Max clipping values.
Definition: pid_controller.h:85
Configuration for PID controller.
Definition: pid_controller.h:81
float clip_max
Max clipping values.
Definition: pid_controller.h:99
float LPF
Low pass filter.
Definition: pid_controller.h:73
float previous
Previous input to the differentiator.
Definition: pid_controller.h:72
float dt
Time step.
Definition: pid_controller.h:105
Derivative part of PID.
Definition: pid_controller.h:69
float clip
Clipping value.
Definition: pid_controller.h:62
float pregain
Pregain.
Definition: pid_controller.h:59
float clip
Clipping value.
Definition: pid_controller.h:74
PID controller.
Definition: pid_controller.h:95
float soft_zone_width
Approximate width of a "soft zone" on the error input, i.e. a region of low gain around the target po...
Definition: pid_controller.h:88
float output
Output.
Definition: pid_controller.h:102
float clip_min
Min clipping values.
Definition: pid_controller.h:98
float gain
Gain.
Definition: pid_controller.h:71
float postgain
Postgain.
Definition: pid_controller.h:60
differentiator_t differentiator
Differentiator parameters.
Definition: pid_controller.h:101
integrator_t integrator
Integrator parameters.
Definition: pid_controller.h:100
float error
Error.
Definition: pid_controller.h:103
uint32_t last_update
Last update time in timer tick.
Definition: pid_controller.h:104
float soft_zone_width
Approximate width of a "soft zone" on the error input, i.e. a region of low gain around the target po...
Definition: pid_controller.h:106
differentiator_t differentiator
Differentiator parameters.
Definition: pid_controller.h:87