PID.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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 
24 namespace gazebo
25 {
26  namespace common
27  {
30 
37  {
47  public: PID(double _p = 0.0, double _i = 0.0, double _d = 0.0,
48  double _imax = 0.0, double _imin = 0.0,
49  double _cmdMax = 0.0, double _cmdMin = 0.0);
50 
52  public: virtual ~PID();
53 
63  public: void Init(double _p = 0.0, double _i = 0.0, double _d = 0.0,
64  double _imax = 0.0, double _imin = 0.0,
65  double _cmdMax = 0.0, double _cmdMin = 0.0);
66 
69  public: void SetPGain(double _p);
70 
73  public: void SetIGain(double _i);
74 
77  public: void SetDGain(double _d);
78 
81  public: void SetIMax(double _i);
82 
85  public: void SetIMin(double _i);
86 
89  public: void SetCmdMax(double _c);
90 
93  public: void SetCmdMin(double _c);
94 
97  public: double GetPGain() const;
98 
101  public: double GetIGain() const;
102 
105  public: double GetDGain() const;
106 
109  public: double GetIMax() const;
110 
113  public: double GetIMin() const;
114 
117  public: double GetCmdMax() const;
118 
121  public: double GetCmdMin() const;
122 
130  public: double Update(double _error, common::Time _dt);
131 
134  public: void SetCmd(double _cmd);
135 
138  public: double GetCmd();
139 
144  public: void GetErrors(double &_pe, double &_ie, double &_de);
145 
149  public: PID &operator=(const PID &_p)
150  {
151  if (this == &_p)
152  return *this;
153 
154  this->pGain = _p.pGain;
155  this->iGain = _p.iGain;
156  this->dGain = _p.dGain;
157  this->iMax = _p.iMax;
158  this->iMin = _p.iMin;
159  this->cmdMax = _p.cmdMax;
160  this->cmdMin = _p.cmdMin;
161  this->pErrLast = _p.pErrLast;
162  this->pErr = _p.pErr;
163  this->iErr = _p.iErr;
164  this->dErr = _p.dErr;
165  this->cmd = _p.cmd;
166 
167  this->Reset();
168  return *this;
169  }
170 
172  public: void Reset();
173 
175  private: double pErrLast;
176 
178  private: double pErr;
179 
181  private: double iErr;
182 
184  private: double dErr;
185 
187  private: double pGain;
188 
190  private: double iGain;
191 
193  private: double dGain;
194 
196  private: double iMax;
197 
199  private: double iMin;
200 
202  private: double cmd;
203 
205  private: double cmdMax;
206 
208  private: double cmdMin;
209  };
211  }
212 }
213 #endif
PID & operator=(const PID &_p)
Assignment operator.
Definition: PID.hh:149
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
Generic PID controller class.
Definition: PID.hh:36
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:43