Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pid.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __PID_H
25 #define __PID_H
26 
27 namespace lpzrobots {
28 
29  class PID
30  {
31  //*********************attributes***************
32  //private:
33  public:
34 
35  double position;
36  double lastposition;
37  double last2position;
38 
39  double error;
40  double lasterror;
41  double derivative;
43 
44  double KP;
45  double KI;
46  double KD;
47  double tau;
48 
49  double P;
50  double D;
51  double I;
52 
53  double force;
54  double lasttime; // last update time (to calc stepsize)
55 
56  //*********************methods******************
57  public :
58  /// KP is used as a general koefficient. KI and KD can be tuned without dependence of KP
59  PID ( double KP = 100 , double KI = 2.0 , double KD = 0.3 );
60 
61  void setKP(double KP);
62 
63  void setTargetPosition ( double newpos );
64 
65  double getTargetPosition ();
66 
67  /// perform one step of the PID controller with cutoff for large forces
68  double step ( double newsensorval, double time);
69  /// perform one step of the PID controller without cutoffs used for Center-Servos
70  double stepNoCutoff ( double newsensorval, double time);
71  /** perform one step of the PID controller for velocity control.
72  Meaning the misfit is in position space but the output is
73  the nominal velocity. The velocity is also limited. such that
74  the maximal velocity cannot be so that the error is overcompenstated
75  in one timestep.
76  */
77  double stepVelocity ( double newsensorval, double time);
78 
79  };
80 
81 }
82 
83 #endif
double stepNoCutoff(double newsensorval, double time)
perform one step of the PID controller without cutoffs used for Center-Servos
Definition: pid.cpp:93
double KI
Definition: pid.h:45
void setKP(double KP)
Definition: pid.cpp:50
double I
Definition: pid.h:51
double force
Definition: pid.h:53
double stepVelocity(double newsensorval, double time)
perform one step of the PID controller for velocity control.
Definition: pid.cpp:118
Definition: pid.h:29
double getTargetPosition()
Definition: pid.cpp:59
double last2position
Definition: pid.h:37
double lasterror
Definition: pid.h:40
double P
Definition: pid.h:49
double position
Definition: pid.h:35
double D
Definition: pid.h:50
double KD
Definition: pid.h:46
double lasttime
Definition: pid.h:54
void setTargetPosition(double newpos)
Definition: pid.cpp:54
PID(double KP=100, double KI=2.0, double KD=0.3)
KP is used as a general koefficient. KI and KD can be tuned without dependence of KP...
Definition: pid.cpp:33
double KP
Definition: pid.h:44
double targetposition
Definition: pid.h:42
double lastposition
Definition: pid.h:36
double derivative
Definition: pid.h:41
double error
Definition: pid.h:39
double step(double newsensorval, double time)
perform one step of the PID controller with cutoff for large forces
Definition: pid.cpp:67
double tau
Definition: pid.h:47