Gazebo Math

API Reference

6.12.0
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 #include <ignition/math/config.hh>
23 
24 namespace ignition
25 {
26  namespace math
27  {
28  // Inline bracket to help doxygen filtering.
29  inline namespace IGNITION_MATH_VERSION_NAMESPACE {
30  //
37  // cppcheck-suppress class_X_Y
38  class IGNITION_MATH_VISIBLE PID
39  {
57  public: PID(const double _p = 0.0,
58  const double _i = 0.0,
59  const double _d = 0.0,
60  const double _imax = -1.0,
61  const double _imin = 0.0,
62  const double _cmdMax = -1.0,
63  const double _cmdMin = 0.0,
64  const double _cmdOffset = 0.0);
65 
67  public: ~PID() = default;
68 
86  public: void Init(const double _p = 0.0,
87  const double _i = 0.0,
88  const double _d = 0.0,
89  const double _imax = -1.0,
90  const double _imin = 0.0,
91  const double _cmdMax = -1.0,
92  const double _cmdMin = 0.0,
93  const double _cmdOffset = 0.0);
94 
97  public: void SetPGain(const double _p);
98 
101  public: void SetIGain(const double _i);
102 
105  public: void SetDGain(const double _d);
106 
109  public: void SetIMax(const double _i);
110 
113  public: void SetIMin(const double _i);
114 
117  public: void SetCmdMax(const double _c);
118 
121  public: void SetCmdMin(const double _c);
122 
126  public: void SetCmdOffset(const double _c);
127 
130  public: double PGain() const;
131 
134  public: double IGain() const;
135 
138  public: double DGain() const;
139 
142  public: double IMax() const;
143 
146  public: double IMin() const;
147 
150  public: double CmdMax() const;
151 
154  public: double CmdMin() const;
155 
158  public: double CmdOffset() const;
159 
167  public: double Update(const double _error,
168  const std::chrono::duration<double> &_dt);
169 
172  public: void SetCmd(const double _cmd);
173 
176  public: double Cmd() const;
177 
182  public: void Errors(double &_pe, double &_ie, double &_de) const;
183 
187  public: PID &operator=(const PID &_p);
188 
190  public: void Reset();
191 
193  private: double pErrLast = 0.0;
194 
196  private: double pErr = 0.0;
197 
199  private: double iErr = 0.0;
200 
202  private: double dErr = 0.0;
203 
205  private: double pGain;
206 
208  private: double iGain = 0.0;
209 
211  private: double dGain = 0.0;
212 
214  private: double iMax = -1.0;
215 
217  private: double iMin = 0.0;
218 
220  private: double cmd = 0.0;
221 
223  private: double cmdMax = -1.0;
224 
226  private: double cmdMin = 0.0;
227 
229  private: double cmdOffset = 0.0;
230  };
231  }
232  }
233 }
234 #endif
Definition: AdditivelySeparableScalarField3.hh:27
void SetCmdOffset(const double _c)
Set the offset value for the command, which is added to the result of the PID controller.
void SetIGain(const double _i)
Set the integral Gain.
double CmdMin() const
Get the minimun value for the command.
double CmdMax() const
Get the maximum value for the command.
double IMin() const
Get the integral lower limit.
double PGain() const
Get the proportional Gain.
void Errors(double &_pe, double &_ie, double &_de) const
Return PID error terms for the controller.
~PID()=default
Destructor.
void SetDGain(const double _d)
Set the derivative Gain.
double Cmd() const
Return current command for this PID controller.
void Init(const double _p=0.0, const double _i=0.0, const double _d=0.0, const double _imax=-1.0, const double _imin=0.0, const double _cmdMax=-1.0, const double _cmdMin=0.0, const double _cmdOffset=0.0)
Initialize PID-gains and integral term limits:[iMax:iMin]-[I1:I2].
void SetCmdMax(const double _c)
Set the maximum value for the command.
void SetCmdMin(const double _c)
Set the minimum value for the command.
Generic PID controller class. Generic proportional-integral-derivative controller class that keeps tr...
Definition: PID.hh:38
void Reset()
Reset the errors and command.
void SetIMax(const double _i)
Set the integral upper limit.
void SetIMin(const double _i)
Set the integral lower limit.
PID & operator=(const PID &_p)
Assignment operator.
double IGain() const
Get the integral Gain.
void SetCmd(const double _cmd)
Set current target command for this PID controller.
PID(const double _p=0.0, const double _i=0.0, const double _d=0.0, const double _imax=-1.0, const double _imin=0.0, const double _cmdMax=-1.0, const double _cmdMin=0.0, const double _cmdOffset=0.0)
Constructor, zeros out Pid values when created and initialize Pid-gains and integral term limits:[iMa...
double DGain() const
Get the derivative Gain.
double IMax() const
Get the integral upper limit.
double Update(const double _error, const std::chrono::duration< double > &_dt)
Update the Pid loop with nonuniform time step size.
void SetPGain(const double _p)
Set the proportional Gain.
double CmdOffset() const
Get the offset value for the command.