EEEN21000
GROUP 30 Line Following Buggy
Loading...
Searching...
No Matches
PID.h
Go to the documentation of this file.
1// /**
2// * @author Aaron Berk
3// *
4// * @section LICENSE
5// *
6// * Copyright (c) 2010 ARM Limited
7// *
8// * Permission is hereby granted, free of charge, to any person obtaining a copy
9// * of this software and associated documentation files (the "Software"), to deal
10// * in the Software without restriction, including without limitation the rights
11// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12// * copies of the Software, and to permit persons to whom the Software is
13// * furnished to do so, subject to the following conditions:
14// *
15// * The above copyright notice and this permission notice shall be included in
16// * all copies or substantial portions of the Software.
17// *
18// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24// * THE SOFTWARE.
25// *
26// * @section DESCRIPTION
27// *
28// * A PID controller is a widely used feedback controller commonly found in
29// * industry.
30// *
31// * This library is a port of Brett Beauregard's Arduino PID library:
32// *
33// * http://www.arduino.cc/playground/Code/PIDLibrary
34// *
35// * The wikipedia article on PID controllers is a good place to start on
36// * understanding how they work:
37// *
38// * http://en.wikipedia.org/wiki/PID_controller
39// *
40// * For a clear and elegant explanation of how to implement and tune a
41// * controller, the controlguru website by Douglas J. Cooper (who also happened
42// * to be Brett's controls professor) is an excellent reference:
43// *
44// * http://www.controlguru.com/
45// */
46
47#ifndef _PID_H_
48#define _PID_H_
49
50#include "debug1.h"
51#include "helper.h"
52#include "mbed.h"
53
57class PID {
58 public:
68 PID(float Kc, float tauI, float tauD, float interval);
69
76 void setInputLimits(float inMin, float inMax);
77
84 void setOutputLimits(float outMin, float outMax);
85
95 void setTunings(float Kc, float tauI, float tauD);
96
100 void reset();
101
107 void setSetPoint(float sp);
108
113 float getSetPoint();
114
120 void setProcessValue(float pv);
121
127 void setBias(float bias);
128
134 float compute(void);
135
136 protected:
138
139 // Actual tuning parameters used in PID calculation.
140 float _Kc;
141 float _tauR;
142 float _tauD;
143
144 // Raw tuning parameters.
145 float _pParam;
146 float _iParam;
147 float _dParam;
148
149 // The point we want to reach.
151 // The thing we measure.
155 // The output that affects the process variable.
158
159 // We work in % for calculations so these will scale from
160 // real world values to 0-100% and back again.
161 float _inMin;
162 float _inMax;
163 float _inSpan;
164 float _outMin;
165 float _outMax;
166 float _outSpan;
167
168 // The accumulated error, i.e. integral.
170 // The controller output bias.
171 float _bias;
172
173 // The exponential filter alpha
174 float _a;
175
176 // The interval between samples.
177 float _tSample;
178
179};
180
181#endif // _PID_H_
Proportional-integral-derivative controller.
Definition: PID.h:57
float _prevControllerOutput
Definition: PID.h:157
float _controllerOutput
Definition: PID.h:156
float _prevError
Definition: PID.h:154
void setProcessValue(float pv)
Set the process value.
float _inSpan
Definition: PID.h:163
float _outSpan
Definition: PID.h:166
float _iParam
Definition: PID.h:146
float _bias
Definition: PID.h:171
float _outMax
Definition: PID.h:165
float _processVariable
Definition: PID.h:152
float _dParam
Definition: PID.h:147
PID(float Kc, float tauI, float tauD, float interval)
Contructor.
void setInputLimits(float inMin, float inMax)
Scale from inputs to 0-100%.
void setOutputLimits(float outMin, float outMax)
Scale from outputs to 0-100%.
float getSetPoint()
Get the setpoint.
float _a
Definition: PID.h:174
float _Kc
Definition: PID.h:140
void setBias(float bias)
Set the bias.
float _prevProcessVariable
Definition: PID.h:153
float _inMax
Definition: PID.h:162
float compute(void)
PID calculation.
float _inMin
Definition: PID.h:161
float _setPoint
Definition: PID.h:150
float _outMin
Definition: PID.h:164
float _tSample
Definition: PID.h:177
bool _usingFeedForward
Definition: PID.h:137
float _tauR
Definition: PID.h:141
float _tauD
Definition: PID.h:142
float _pParam
Definition: PID.h:145
void setSetPoint(float sp)
Set the set point.
void reset()
Reset previous values of output and error.
void setTunings(float Kc, float tauI, float tauD)
Calculate PID constants.
float _accError
Definition: PID.h:169