PidController.hpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2008, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 #ifndef PIDCONTROLLER_HPP
35 #define PIDCONTROLLER_HPP
36 
37 
38 #include <string>
40 
41 
42 namespace youbot {
43 
44 /***************************************************/
94 /***************************************************/
95 
97 {
98 public:
99 
110  PidController(double P = 0.0, double I = 0.0, double D = 0.0, double I1 = 0.0, double I2 = -0.0);
111 
115  ~PidController();
116 
123  double updatePid(double p_error, boost::posix_time::time_duration dt);
124 
134  void initPid(double P, double I, double D, double I1, double I2);
135 
139  void reset();
140 
144  void setCurrentCmd(double cmd);
145 
149  double getCurrentCmd();
150 
157  void getCurrentPIDErrors(double& pe, double& ie, double& de);
158 
167  void setGains(double P, double I, double D, double i_max, double i_min);
168 
177  void getGains(double &p, double &i, double &d, double &i_max, double &i_min);
178 
187  double updatePid(double error, double error_dot, boost::posix_time::time_duration dt);
188 
190  {
191  if (this == &p)
192  return *this;
193 
194  p_gain_ = p.p_gain_;
195  i_gain_ = p.i_gain_;
196  d_gain_ = p.d_gain_;
197  i_max_ = p.i_max_;
198  i_min_ = p.i_min_;
199 
201  return *this;
202  }
203 
204 private:
205  double p_error_last_;
206  double p_error_;
207  double d_error_;
208  double i_error_;
209  double p_gain_;
210  double i_gain_;
211  double d_gain_;
212  double i_max_;
213  double i_min_;
214  double cmd_;
215  double last_i_error;
216 };
217 
218 }
219 
220 #endif
d
void setGains(double P, double I, double D, double i_max, double i_min)
Set PID gains for the controller.
void setCurrentCmd(double cmd)
Set current command for this PID controller.
double getCurrentCmd()
Return current command for this PID controller.
double updatePid(double p_error, boost::posix_time::time_duration dt)
Update the Pid loop with nonuniform time step size.
void getCurrentPIDErrors(double &pe, double &ie, double &de)
Return PID error terms for the controller.
~PidController()
Destructor of Pid class.
PidController(double P=0.0, double I=0.0, double D=0.0, double I1=0.0, double I2=-0.0)
Constructor, zeros out Pid values when created and initialize Pid-gains and integral term limits:[iMa...
A basic pid class.
void getGains(double &p, double &i, double &d, double &i_max, double &i_min)
Get PID gains for the controller.
void reset()
Reset the state of this PID controller.
void initPid(double P, double I, double D, double I1, double I2)
Initialize PID-gains and integral term limits:[iMax:iMin]-[I1:I2].
PidController & operator=(const PidController &p)


youbot_driver
Author(s): Jan Paulus
autogenerated on Mon Jun 10 2019 15:46:25