00001 /*!@file Controllers/PID.H Basic PID for the BeoSub */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003 // 00005 // by the University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Laurent Itti <itti@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Controllers/PID.H $ 00035 // $Id: PID.H 11516 2009-07-24 01:47:16Z lior $ 00036 // 00037 00038 #ifndef PID_H_DEFINED 00039 #define PID_H_DEFINED 00040 00041 #include "Util/Angle.H" 00042 00043 //! Definition and access functions for a BeoSub PID 00044 template <class T> class PID 00045 { 00046 public: 00047 00048 //! Constructor 00049 PID(const float pGain, const float iGain, const float dGain, 00050 const T& iMin, const T& iMax, 00051 const T& errThresh = 0, 00052 const T& posThresh = 0, const T& negThresh = 0, 00053 const T& maxMotor = 100,const T& minMotor = -100, 00054 const int noMoveThresh = 150, 00055 const bool runPID = true, 00056 const float speed = 1, 00057 const T& posStaticErrThresh = 50, 00058 const T& negStaticErrThresh = -50 00059 ); 00060 00061 //! Destructor 00062 ~PID(); 00063 00064 //! Set the gains 00065 void setPIDPgain(float p); 00066 void setPIDIgain(float i); 00067 void setPIDDgain(float d); 00068 void setSpeed(float s); 00069 void setPIDOn(bool val); 00070 00071 float getPIDPgain() { return itsPgain; } 00072 float getPIDIgain() { return itsIgain; } 00073 float getPIDDgain() { return itsDgain; } 00074 00075 T getVel() { return itsVel; } 00076 T getErr() { return itsErr; } 00077 T getVal() { return itsVal; } 00078 T getTarget() { return itsTarget; } 00079 T getPTerm() { return itsPTerm; } 00080 T getRunPID() { return itsRunPID; } 00081 00082 //! Receive a new measurement value and get the new recommended action 00083 T update(const T& target, const T& val); 00084 00085 //! Receive a new measurement value and get the new recommended action 00086 T update(const T& targetPos, const T& targetVel, const T& currentVal); 00087 00088 private: 00089 T itsIstate, itsDstate; 00090 float itsPgain, itsIgain, itsDgain; 00091 T itsImin, itsImax; 00092 T itsErrThresh, itsPosStaticErrThresh, itsNegStaticErrThresh, itsPosThresh, itsNegThresh; 00093 T itsMaxMotor, itsMinMotor; 00094 int itsNoMoveThresh; 00095 bool itsRunPID; 00096 float itsSpeed; 00097 int itsNoMoveCount; 00098 T itsVel; 00099 T itsErr; 00100 T itsVal; //current value 00101 T itsTarget; //current target 00102 T itsPTerm; //current correction 00103 T itsLastVal; //current correction 00104 }; 00105 00106 #endif 00107 00108 // ###################################################################### 00109 /* So things look consistent in everyone's emacs... */ 00110 /* Local Variables: */ 00111 /* indent-tabs-mode: nil */ 00112 /* End: */