Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

LostTargetTrans.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_LostTargetTrans_h_
00003 #define INCLUDED_LostTargetTrans_h_
00004 
00005 #include "Behaviors/Transitions/TimeOutTrans.h"
00006 
00007 //! Causes a transition if the target has not been seen @e minframe times within @e delay milliseconds.
00008 class LostTargetTrans : public TimeOutTrans {
00009  public:
00010 
00011   //! constructor, specify delay in milliseconds
00012   LostTargetTrans(StateNode* destination, unsigned int source_id,
00013       unsigned int delay, int minframes=5) :
00014     TimeOutTrans("LostTargetTrans","LostTargetTrans",destination,delay),
00015     sid(source_id), minf(minframes), counter(0) {}
00016 
00017   //! constructor, specify delay in milliseconds
00018   LostTargetTrans(const std::string &name, StateNode* destination, unsigned int source_id,
00019       unsigned int delay, int minframes=5) :
00020     TimeOutTrans("LostTargetTrans",name,destination,delay),
00021     sid(source_id), minf(minframes), counter(0) {}
00022 
00023   //!starts timer
00024   virtual void preStart() {
00025     TimeOutTrans::preStart();
00026     erouter->addListener(this,EventBase::visObjEGID,sid);
00027   }
00028 
00029   virtual void doEvent() {
00030     if (event->getGeneratorID()==EventBase::visObjEGID && event->getSourceID()==sid) {
00031       ++counter;
00032       if (counter > minf) resetTimer();
00033     }
00034     else
00035       TimeOutTrans::doEvent();
00036   }
00037 
00038   //! resets timer; does not deactivate it
00039   virtual void resetTimer() {
00040     TimeOutTrans::resetTimer();
00041     counter = 0;
00042   }
00043 
00044   //! set minimum number of frames that target must be seen before resetting the timer
00045   virtual void set_minframes(int minframes) { minf = minframes; }
00046 
00047 protected:
00048   //! constructor, only to be called by subclasses (which need to specify their own @a classname)
00049   LostTargetTrans(const std::string &classname, const std::string &instancename, 
00050       StateNode* destination, unsigned int source_id,
00051       unsigned int delay, int minframes=5) :
00052     TimeOutTrans(classname,instancename,destination,delay),
00053     sid(source_id), minf(minframes), counter(0) {}
00054 
00055 
00056  private:
00057   unsigned int sid; //!< the source id from the detector of the object which is being monitored
00058   int minf;   //!< number of frames that target must be seen before resetting the timer
00059   int counter; //!< number of frames target has been seen so far
00060 };
00061 
00062 #endif
00063 
00064 /*! @file
00065  * @brief Defines LostTargetTrans, which causes a transition if the target has not been seen @e minframe times within @e delay milliseconds.
00066  * @author ejt (Creator)
00067  */

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