simple_pid.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Robert Leishman, BYU MAGICC Lab.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * * Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
38 #ifndef ROTOR_CONTROLLER_SIMPLE_PID_H
39 #define ROTOR_CONTROLLER_SIMPLE_PID_H
40 
41 #include <cmath>
42 #include <ros/ros.h> // included temporarily for debug statements
43 
44 namespace rosflight_utils
45 {
53 class SimplePID
54 {
55 public:
59  SimplePID();
60 
70  SimplePID(double p, double i = 0.0, double d = 0.0, double max = DBL_MAX, double min = -DBL_MAX, double tau = 0.15);
71 
79  double computePID(double desired, double current, double dt, double x_dot = INFINITY);
80 
89  void setGains(double p, double i = 0.0, double d = 0.0, double tau = 0.15);
90 
97  void setLimits(double max, double min);
98 
103  {
104  integrator_ = 0.0;
105  }
106 
107 protected:
108  double kp_;
109  double ki_;
110  double kd_;
111  double integrator_;
113  double last_error_;
114  double last_state_;
115  double tau_;
116  double max_;
117  double min_;
118 
126  inline double saturate(double val, double &min, double &max)
127  {
128  if (val > max)
129  val = max;
130  else if (val < min)
131  val = min;
132  return val;
133  }
134 };
135 }
136 
137 #endif // ROTOR_CONTROLLER_SIMPLE_PID_H
d
double ki_
the integral gain (zero if you don&#39;t want integral control)
Definition: simple_pid.h:109
double last_error_
the last p_error, for computing the derivative;
Definition: simple_pid.h:113
double saturate(double val, double &min, double &max)
saturate saturates the variable val
Definition: simple_pid.h:126
void setLimits(double max, double min)
setgains is used to set the gains for a controller after it&#39;s been initialized. It will rewrite whate...
double differentiator_
used for noise reduced differentiation
Definition: simple_pid.h:112
The simplePID class is a basic, tried and true PID controller. Only P (proportional) gains are necess...
Definition: simple_pid.h:53
This file defines a simple PID controller to be used by other classes to implement a PID control loop...
Definition: simple_pid.h:44
double tau_
the noise reduction term for the derivative
Definition: simple_pid.h:115
double last_state_
the last state, for computing the derivative;
Definition: simple_pid.h:114
SimplePID()
SimplePID is the basic initializer;.
Definition: simple_pid.cpp:39
double kd_
the derivative gain (zero if you don&#39;t want derivative control)
Definition: simple_pid.h:110
double max_
Maximum Output.
Definition: simple_pid.h:116
void clearIntegrator()
clearIntegrator allows you to clear the integrator, in case of integrator windup. ...
Definition: simple_pid.h:102
double kp_
the proportional gain
Definition: simple_pid.h:108
double integrator_
the integral of p_error
Definition: simple_pid.h:111
double min_
Minimum Output.
Definition: simple_pid.h:117
void setGains(double p, double i=0.0, double d=0.0, double tau=0.15)
setgains is used to set the gains for a controller after it&#39;s been initialized. It will rewrite whate...
Definition: simple_pid.cpp:144
double computePID(double desired, double current, double dt, double x_dot=INFINITY)
computePID computes the PID control for the given error and timestep (since the last control was comp...
Definition: simple_pid.cpp:66


rosflight_utils
Author(s):
autogenerated on Wed Jul 3 2019 20:00:31