Homepage Demos Overview Downloads Tutorials Reference
Credits

SmoothCompareTrans.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_SmoothCompareTrans_h_
00003 #define INCLUDED_SmoothCompareTrans_h_
00004 
00005 #include "Behaviors/Transitions/CompareTrans.h"
00006 
00007 //! A subclass of CompareTrans, which provides monitoring of exponentially weighted averages to a threshold
00008 /*! Has the additional requirement that template types must supply operator*=(float)
00009  *  and operator+=(T) for the weighted average
00010  *
00011  *  The gamma parameter is how much to weight the preceeding value - 1 will cause it to never update, 0 will cause it to only look at most recent.
00012  *  So, the lower the value, the faster it is to switch, but more prone to noise
00013  */
00014 template<class T>
00015 class SmoothCompareTrans : public CompareTrans<T> {
00016 public:
00017   //! constructor, see SmoothCompareTrans class notes for information
00018   SmoothCompareTrans(StateNode* destination, const T* monitor, typename SmoothCompareTrans<T>::Test_t test, const T& value, const EventBase& poll, float gammap=0)
00019     : CompareTrans<T>("SmoothCompareTrans",destination,&avg,test,value,poll), avg(*monitor), realmon(monitor),
00020     burnin((unsigned int)(1/(1-gammap))), tests(0), g(gammap)
00021   { }
00022 
00023   //! constructor, see SmoothCompareTrans class notes for information
00024   SmoothCompareTrans(const std::string& name, StateNode* destination, const T* monitor, typename SmoothCompareTrans<T>::Test_t test, const T& value, const EventBase& poll, float gammap=0)
00025     : CompareTrans<T>("SmoothCompareTrans",name,destination,&avg,test,value,poll), avg(*monitor), realmon(monitor),
00026     burnin((unsigned int)(1/(1-gammap))), tests(0), g(gammap)
00027   { }
00028 
00029   virtual void DoStart() {
00030     CompareTrans<T>::DoStart();
00031     avg=*realmon;
00032     tests=0;
00033   }
00034 
00035   //! sets number of tests to perform before allowing a transition; default 1/(1-g)
00036   void setBurnIn(unsigned int i) {
00037     burnin=i;
00038   }
00039 
00040   //! returns number of tests to perform before allowing a transition; default 1/(1-g)
00041   unsigned int getBurnIn() {
00042     return burnin;
00043   }
00044 
00045   //!don't care about the event, just a pulse to check the values
00046   virtual void processEvent(const EventBase& e) {
00047     avg*=g;
00048     T x(*realmon);
00049     x*=(1-g);
00050     avg+=x;
00051     tests++;
00052     if(tests>burnin)
00053       CompareTrans<T>::processEvent(e);
00054   }
00055 
00056 protected:
00057   T avg; //!< the current running average
00058   const T* realmon; //!< pointer to the value being monitored
00059 
00060   unsigned int burnin; //!< number of tests to perform before allowing a transition; default 1/(1-g)
00061   unsigned int tests; //!< counter of tests made since last DoStart()
00062 
00063   //! the gamma value controlling the exponential average, see the class documentation at the top
00064   float g; 
00065 
00066 private:
00067   SmoothCompareTrans(const SmoothCompareTrans& node); //!< don't call this
00068   SmoothCompareTrans operator=(const SmoothCompareTrans& node); //!< don't call this
00069 };
00070 
00071 /*! @file
00072  * @brief Defines SmoothCompareTrans, subclass of CompareTrans, which provides monitoring of exponentially weighted averages to a threshold
00073  * @author ejt (Creator)
00074  *
00075  * $Author: ejt $
00076  * $Name: tekkotsu-2_2_1 $
00077  * $Revision: 1.10 $
00078  * $State: Exp $
00079  * $Date: 2004/11/15 22:46:19 $
00080  */
00081 
00082 #endif

Tekkotsu v2.2.1
Generated Tue Nov 23 16:36:40 2004 by Doxygen 1.3.9.1