PID.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 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 #ifndef IGNITION_MATH_PID_HH_
18 #define IGNITION_MATH_PID_HH_
19 
20 #include <chrono>
21 #include <ignition/math/Helpers.hh>
22 
23 namespace ignition
24 {
25  namespace math
26  {
34  {
52  public: PID(const double _p = 0.0,
53  const double _i = 0.0,
54  const double _d = 0.0,
55  const double _imax = -1.0,
56  const double _imin = 0.0,
57  const double _cmdMax = -1.0,
58  const double _cmdMin = 0.0,
59  const double _cmdOffset = 0.0);
60 
62  public: ~PID() = default;
63 
81  public: void Init(const double _p = 0.0,
82  const double _i = 0.0,
83  const double _d = 0.0,
84  const double _imax = -1.0,
85  const double _imin = 0.0,
86  const double _cmdMax = -1.0,
87  const double _cmdMin = 0.0,
88  const double _cmdOffset = 0.0);
89 
92  public: void SetPGain(const double _p);
93 
96  public: void SetIGain(const double _i);
97 
100  public: void SetDGain(const double _d);
101 
104  public: void SetIMax(const double _i);
105 
108  public: void SetIMin(const double _i);
109 
112  public: void SetCmdMax(const double _c);
113 
116  public: void SetCmdMin(const double _c);
117 
121  public: void SetCmdOffset(const double _c);
122 
125  public: double PGain() const;
126 
129  public: double IGain() const;
130 
133  public: double DGain() const;
134 
137  public: double IMax() const;
138 
141  public: double IMin() const;
142 
145  public: double CmdMax() const;
146 
149  public: double CmdMin() const;
150 
153  public: double CmdOffset() const;
154 
162  public: double Update(const double _error,
163  const std::chrono::duration<double> &_dt);
164 
167  public: void SetCmd(const double _cmd);
168 
171  public: double Cmd() const;
172 
177  public: void Errors(double &_pe, double &_ie, double &_de) const;
178 
182  public: PID &operator=(const PID &_p);
183 
185  public: void Reset();
186 
188  private: double pErrLast = 0.0;
189 
191  private: double pErr = 0.0;
192 
194  private: double iErr = 0.0;
195 
197  private: double dErr = 0.0;
198 
200  private: double pGain;
201 
203  private: double iGain = 0.0;
204 
206  private: double dGain = 0.0;
207 
209  private: double iMax = -1.0;
210 
212  private: double iMin = 0.0;
213 
215  private: double cmd = 0.0;
216 
218  private: double cmdMax = -1.0;
219 
221  private: double cmdMin = 0.0;
222 
224  private: double cmdOffset = 0.0;
225  };
226  }
227 }
228 #endif
Generic PID controller class.
Definition: PID.hh:33
#define IGNITION_VISIBLE
Use to represent "symbol visible" if supported.
Definition: System.hh:59
Definition: Angle.hh:38