All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PID.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 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 
23 namespace gazebo
24 {
25  namespace common
26  {
29 
35  class PID
36  {
46  public: PID(double _p = 0.0, double _i = 0.0, double _d = 0.0,
47  double _imax = 0.0, double _imin = 0.0,
48  double _cmdMax = 0.0, double _cmdMin = 0.0);
49 
51  public: virtual ~PID();
52 
62  public: void Init(double _p = 0.0, double _i = 0.0, double _d = 0.0,
63  double _imax = 0.0, double _imin = 0.0,
64  double _cmdMax = 0.0, double _cmdMin = 0.0);
65 
68  public: void SetPGain(double _p);
69 
72  public: void SetIGain(double _i);
73 
76  public: void SetDGain(double _d);
77 
80  public: void SetIMax(double _i);
81 
84  public: void SetIMin(double _i);
85 
88  public: void SetCmdMax(double _c);
89 
92  public: void SetCmdMin(double _c);
93 
101  public: double Update(double _error, common::Time _dt);
102 
105  public: void SetCmd(double _cmd);
106 
109  public: double GetCmd();
110 
115  public: void GetErrors(double &_pe, double &_ie, double &_de);
116 
120  public: PID &operator=(const PID &_p)
121  {
122  if (this == &_p)
123  return *this;
124 
125  this->pGain = _p.pGain;
126  this->iGain = _p.iGain;
127  this->dGain = _p.dGain;
128  this->iMax = _p.iMax;
129  this->iMin = _p.iMin;
130  this->cmdMax = _p.cmdMax;
131 
132  this->Reset();
133  return *this;
134  }
135 
137  public: void Reset();
138 
140  private: double pErrLast;
141 
143  private: double pErr;
144 
146  private: double iErr;
147 
149  private: double dErr;
150 
152  private: double pGain;
153 
155  private: double iGain;
156 
158  private: double dGain;
159 
161  private: double iMax;
162 
164  private: double iMin;
165 
167  private: double cmd;
168 
170  private: double cmdMax;
171 
173  private: double cmdMin;
174  };
176  }
177 }
178 #endif