Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

OutputPID.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_OutputPID_h
00003 #define INCLUDED_OutputPID_h
00004 
00005 //! This object holds all the information needed to control a single output
00006 class OutputPID {
00007 public:
00008   OutputPID() : weight(0) { pid[0]=pid[1]=pid[2]=0; } //!< Constructor
00009   OutputPID(const float p[3]) : weight(1) { set_pid(p); } //!< Constructor, allows non-explicit conversion
00010   OutputPID(const float p[3], float w) : weight(w) {set_pid(p);} //!< Constructor
00011   OutputPID(const float p, const float i, const float d) : weight(1) {set_pid(p,i,d);} //!< Constructor
00012   OutputPID(const float p, const float i, const float d, float w) : weight(w) {set_pid(p,i,d);} //!< Constructor
00013   OutputPID(const OutputPID& a, const OutputPID& b, float w) : weight(0) { set(a,b,w); } //!< Constructor, see set(a,b,w)
00014 
00015   inline void set(const float p[3], float w=1) { set_pid(p); weight=w; } //!< sets the value to @a v and weight to @a w
00016   inline void set(const float p, const float i, const float d, float w=1) { set_pid(p,i,d); weight=w; } //!< sets the value to @a v and weight to @a w
00017   
00018   //! sets the value to a weighted average of @a a and @a b (higher @a w, more @a a)
00019   inline void set(const OutputPID& a, const OutputPID& b, float w) {
00020     pid[0]=a.pid[0]*w+b.pid[0]*(1-w);
00021     pid[1]=a.pid[1]*w+b.pid[1]*(1-w);
00022     pid[2]=a.pid[2]*w+b.pid[2]*(1-w);
00023     weight=a.weight*w+b.weight*(1-w); 
00024   } 
00025   inline void unset() { weight=0; } //!< sets value and weight to 0
00026 
00027   float pid[3]; //!< pid value of the output
00028   float weight; //!< weight to be used in averaging, 0 to "fall through"
00029 
00030 protected:
00031    //! handy utility function, sets #pid[0:2] to @a p[0:2]
00032   inline void set_pid(const float p[3]) {
00033     pid[0]=p[0];
00034     pid[1]=p[1];
00035     pid[2]=p[2];
00036   }
00037    //! handy utility function, sets #pid[0:2] to [@a p,@a i,@a d]
00038   inline void set_pid(const float p, const float i, const float d) {
00039     pid[0]=p;
00040     pid[1]=i;
00041     pid[2]=d;
00042   }
00043 };
00044 
00045 /*! @file
00046  * @brief Describes OutputPID, holds information needed to control a single output
00047  * @author ejt (Creator)
00048  */
00049 
00050 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:45 2016 by Doxygen 1.6.3