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 <ros/ros.h> // included temporarily for debug statements
42 #include <cmath>
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 
102  void clearIntegrator() { integrator_ = 0.0; }
103 
104 protected:
105  double kp_;
106  double ki_;
107  double kd_;
108  double integrator_;
110  double last_error_;
111  double last_state_;
112  double tau_;
113  double max_;
114  double min_;
115 
123  inline double saturate(double val, double &min, double &max)
124  {
125  if (val > max)
126  val = max;
127  else if (val < min)
128  val = min;
129  return val;
130  }
131 };
132 } // namespace rosflight_utils
133 
134 #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:106
double last_error_
the last p_error, for computing the derivative;
Definition: simple_pid.h:110
double saturate(double val, double &min, double &max)
saturate saturates the variable val
Definition: simple_pid.h:123
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:109
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:112
double last_state_
the last state, for computing the derivative;
Definition: simple_pid.h:111
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:107
int i
double max_
Maximum Output.
Definition: simple_pid.h:113
int min(int a, int b)
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:105
double integrator_
the integral of p_error
Definition: simple_pid.h:108
double min_
Minimum Output.
Definition: simple_pid.h:114
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:147
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:71


rosflight_utils
Author(s):
autogenerated on Thu Apr 15 2021 05:10:06