Homepage Demos Overview Downloads Tutorials 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 #include "Events/VisionObjectEvent.h"
00007 
00008 
00009 //! Causes a transition if the target has not been seen @e minframe times within
00010 //! @e delay milliseconds.
00011 
00012 class LostTargetTrans : public TimeOutTrans {
00013  public:
00014 
00015   //! constructor, specify delay in milliseconds
00016   LostTargetTrans(StateNode* destination, unsigned int source_id,
00017       unsigned int delay, int minframes=5) :
00018     TimeOutTrans("LostTargetTrans","LostTargetTrans",destination,delay),
00019     sid(source_id), minf(minframes), counter(0) {}
00020 
00021   //! constructor, specify delay in milliseconds
00022   LostTargetTrans(const std::string &name, StateNode* destination, unsigned int source_id,
00023       unsigned int delay, int minframes=5) :
00024     TimeOutTrans("LostTargetTrans",name,destination,delay),
00025     sid(source_id), minf(minframes), counter(0) {}
00026 
00027   //!starts timer
00028   virtual void DoStart() {
00029     TimeOutTrans::DoStart();
00030     erouter->addListener(this,EventBase::visObjEGID,sid);
00031   }
00032 
00033   virtual void processEvent(const EventBase &e) {
00034     if (e.getGeneratorID()==EventBase::visObjEGID && e.getSourceID()==sid) {
00035       ++counter;
00036       if (counter > minf) resetTimer();
00037     }
00038     else
00039       TimeOutTrans::processEvent(e);
00040   }
00041 
00042   //! resets timer; does not deactivate it
00043   virtual void resetTimer() {
00044     TimeOutTrans::resetTimer();
00045     counter = 0;
00046   }
00047 
00048   //! set minimum number of frames that target must be seen before resetting the timer
00049   virtual void set_minframes(int minframes) { minf = minframes; }
00050 
00051 protected:
00052   LostTargetTrans(const std::string &classname, const std::string &instancename, 
00053       StateNode* destination, unsigned int source_id,
00054       unsigned int delay, int minframes=5) :
00055     TimeOutTrans(classname,instancename,destination,delay),
00056     sid(source_id), minf(minframes), counter(0) {}
00057 
00058 
00059  private:
00060   unsigned int sid;
00061   int minf;   //!< number of frames that target must be seen before resetting the timer
00062   int counter; //!< number of frames target has been seen so far
00063 };
00064 
00065 #endif

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