PID.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16*/
17
18#ifndef _GAZEBO_PID_HH_
19#define _GAZEBO_PID_HH_
20
21#include "gazebo/common/Time.hh"
22#include "gazebo/util/system.hh"
23
24namespace gazebo
25{
26 namespace common
27 {
30
36 class GZ_COMMON_VISIBLE PID
37 {
51 public: PID(double _p = 0.0, double _i = 0.0, double _d = 0.0,
52 double _imax = 0.0, double _imin = 0.0,
53 double _cmdMax = -1.0, double _cmdMin = 0.0);
54
56 public: virtual ~PID();
57
71 public: void Init(double _p = 0.0, double _i = 0.0, double _d = 0.0,
72 double _imax = 0.0, double _imin = 0.0,
73 double _cmdMax = -1.0, double _cmdMin = 0.0);
74
77 public: void SetPGain(double _p);
78
81 public: void SetIGain(double _i);
82
85 public: void SetDGain(double _d);
86
89 public: void SetIMax(double _i);
90
93 public: void SetIMin(double _i);
94
97 public: void SetCmdMax(double _c);
98
101 public: void SetCmdMin(double _c);
102
105 public: double GetPGain() const;
106
109 public: double GetIGain() const;
110
113 public: double GetDGain() const;
114
117 public: double GetIMax() const;
118
121 public: double GetIMin() const;
122
125 public: double GetCmdMax() const;
126
129 public: double GetCmdMin() const;
130
138 public: double Update(double _error, common::Time _dt);
139
142 public: void SetCmd(double _cmd);
143
146 public: double GetCmd();
147
152 public: void GetErrors(double &_pe, double &_ie, double &_de);
153
157 public: PID &operator=(const PID &_p)
158 {
159 if (this == &_p)
160 return *this;
161
162 this->pGain = _p.pGain;
163 this->iGain = _p.iGain;
164 this->dGain = _p.dGain;
165 this->iMax = _p.iMax;
166 this->iMin = _p.iMin;
167 this->cmdMax = _p.cmdMax;
168 this->cmdMin = _p.cmdMin;
169 this->pErrLast = _p.pErrLast;
170 this->pErr = _p.pErr;
171 this->iErr = _p.iErr;
172 this->dErr = _p.dErr;
173 this->cmd = _p.cmd;
174
175 this->Reset();
176 return *this;
177 }
178
180 public: void Reset();
181
183 private: double pErrLast;
184
186 private: double pErr;
187
189 private: double iErr;
190
192 private: double dErr;
193
195 private: double pGain;
196
198 private: double iGain;
199
201 private: double dGain;
202
204 private: double iMax;
205
207 private: double iMin;
208
210 private: double cmd;
211
213 private: double cmdMax = -1.0;
214
216 private: double cmdMin = 0.0;
217 };
219 }
220}
221#endif
common
Definition FuelModelDatabase.hh:37
Generic PID controller class.
Definition PID.hh:37
virtual ~PID()
Destructor.
double GetPGain() const
Get the proportional Gain.
void SetPGain(double _p)
Set the proportional Gain.
void SetCmdMax(double _c)
Set the maximum value for the command.
void SetIGain(double _i)
Set the integral Gain.
void Reset()
Reset the errors and command.
double Update(double _error, common::Time _dt)
Update the Pid loop with nonuniform time step size.
double GetDGain() const
Get the derivative Gain.
void Init(double _p=0.0, double _i=0.0, double _d=0.0, double _imax=0.0, double _imin=0.0, double _cmdMax=-1.0, double _cmdMin=0.0)
Initialize PID-gains and integral term limits:[iMax:iMin]-[I1:I2].
double GetCmd()
Return current command for this PID controller.
PID(double _p=0.0, double _i=0.0, double _d=0.0, double _imax=0.0, double _imin=0.0, double _cmdMax=-1.0, double _cmdMin=0.0)
Constructor, zeros out Pid values when created and initialize Pid-gains and integral term limits:[iMa...
void SetDGain(double _d)
Set the derivtive Gain.
double GetCmdMax() const
Get the maximum value for the command.
void SetIMin(double _i)
Set the integral lower limit.
double GetCmdMin() const
Get the maximum value for the command.
void SetCmd(double _cmd)
Set current target command for this PID controller.
double GetIMin() const
Get the integral lower limit.
PID & operator=(const PID &_p)
Assignment operator.
Definition PID.hh:157
void SetCmdMin(double _c)
Set the maximum value for the command.
double GetIGain() const
Get the integral Gain.
void SetIMax(double _i)
Set the integral upper limit.
void GetErrors(double &_pe, double &_ie, double &_de)
Return PID error terms for the controller.
double GetIMax() const
Get the integral upper limit.
A Time class, can be used to hold wall- or sim-time.
Definition Time.hh:48
Forward declarations for the common classes.
Definition Animation.hh:27