Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

VisualTargetCloseTrans.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_VisualTargetCloseTrans_h_
00003 #define INCLUDED_VisualTargetCloseTrans_h_
00004 
00005 #include "Events/EventRouter.h"
00006 #include "Events/VisionObjectEvent.h"
00007 #include "Shared/debuget.h"
00008 #include "Shared/WorldState.h"
00009 #include "Shared/ERS210Info.h"
00010 #include "Shared/ERS220Info.h"
00011 #include "Shared/ERS7Info.h"
00012 
00013 //! causes a transition when a visual object is "close"
00014 class VisualTargetCloseTrans : public Transition {
00015 public:
00016   //!constructor
00017   VisualTargetCloseTrans(StateNode* destination, unsigned int source_id, float threshold=225)
00018     : Transition("VisualTargetCloseTrans",destination), sid(source_id), distanceThreshold(threshold) {}
00019 
00020   //!constructor
00021   VisualTargetCloseTrans(const std::string& name, StateNode* destination, unsigned int source_id, float threshold=225)
00022     : Transition("VisualTargetCloseTrans",name,destination), sid(source_id), distanceThreshold(threshold) {}
00023 
00024   //!starts listening for the object specified by the source id in the constructor
00025   virtual void DoStart() { Transition::DoStart(); erouter->addListener(this,EventBase::visObjEGID,sid); }
00026 
00027   //!called by StateNode when it becomes inactive - undo whatever you did in Enable()
00028   virtual void DoStop() { erouter->removeListener(this); Transition::DoStop(); }
00029 
00030   //!if the object is "close", calls fire()
00031   virtual void processEvent(const EventBase& e) {
00032     const VisionObjectEvent* ve=dynamic_cast<const VisionObjectEvent*>(&e);
00033     ASSERTRET(ve!=NULL,"Casting error");
00034     float x=ve->getCenterX();
00035     float y=ve->getCenterY();
00036     unsigned int IRDistOffset=-1U;
00037     //The ERS-7 adds more IR distance sensors, so we have to
00038     //break it down by model so we can specify which one
00039     if(state->robotDesign & WorldState::ERS210Mask)
00040       IRDistOffset=ERS210Info::IRDistOffset;
00041     else if(state->robotDesign & WorldState::ERS220Mask)
00042       IRDistOffset=ERS220Info::IRDistOffset;
00043     else if(state->robotDesign & WorldState::ERS7Mask)
00044       IRDistOffset=ERS7Info::NearIRDistOffset;
00045     if(x*x+y*y<0.02f && IRDistOffset!=-1U && state->sensors[IRDistOffset]<distanceThreshold)
00046       fire();
00047   }
00048 
00049 protected:
00050   //!Source ID of object to track
00051   unsigned int sid;
00052   
00053   //!Distance at which to trigger transition, in millimeters
00054   float distanceThreshold;
00055 };
00056 
00057 /*! @file
00058  * @brief Defines VisualTargetCloseTrans, which causes a transition when a visual object is "close"
00059  * @author ejt (Creator)
00060  *
00061  * $Author: ejt $
00062  * $Name: tekkotsu-2_4_1 $
00063  * $Revision: 1.15 $
00064  * $State: Exp $
00065  * $Date: 2005/06/13 21:22:41 $
00066  */
00067 
00068 #endif

Tekkotsu v2.4.1
Generated Tue Aug 16 16:32:49 2005 by Doxygen 1.4.4