Homepage Demos Overview Downloads Tutorials 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) : Transition("VisualTargetCloseTrans",destination), sid(source_id) {}
00018 
00019   //!constructor
00020   VisualTargetCloseTrans(const std::string& name, StateNode* destination, unsigned int source_id) : Transition("VisualTargetCloseTrans",name,destination), sid(source_id) {}
00021 
00022   //!starts listening for the object specified by the source id in the constructor
00023   virtual void DoStart() { Transition::DoStart(); erouter->addListener(this,EventBase::visObjEGID,sid); }
00024 
00025   //!called by StateNode when it becomes inactive - undo whatever you did in Enable()
00026   virtual void DoStop() { erouter->removeListener(this); Transition::DoStop(); }
00027 
00028   //!if the object is "close", calls fire()
00029   virtual void processEvent(const EventBase& e) {
00030     const VisionObjectEvent* ve=dynamic_cast<const VisionObjectEvent*>(&e);
00031     ASSERTRET(ve!=NULL,"Casting error");
00032     float x=ve->getCenterX();
00033     float y=ve->getCenterY();
00034     unsigned int IRDistOffset=-1U;
00035     //The ERS-7 adds more IR distance sensors, so we have to
00036     //break it down by model so we can specify which one
00037     if(state->robotDesign & WorldState::ERS210Mask)
00038       IRDistOffset=ERS210Info::IRDistOffset;
00039     else if(state->robotDesign & WorldState::ERS220Mask)
00040       IRDistOffset=ERS220Info::IRDistOffset;
00041     else if(state->robotDesign & WorldState::ERS7Mask)
00042       IRDistOffset=ERS7Info::NearIRDistOffset;
00043     if(x*x+y*y<0.02f && IRDistOffset!=-1U && state->sensors[IRDistOffset]<225)
00044       fire();
00045   }
00046 
00047 protected:
00048   //!Source ID of object to track
00049   unsigned int sid;
00050 };
00051 
00052 /*! @file
00053  * @brief Defines VisualTargetCloseTrans, which causes a transition when a visual object is "close"
00054  * @author ejt (Creator)
00055  *
00056  * $Author: ejt $
00057  * $Name: tekkotsu-2_2_2 $
00058  * $Revision: 1.14 $
00059  * $State: Exp $
00060  * $Date: 2004/11/15 22:46:19 $
00061  */
00062 
00063 #endif

Tekkotsu v2.2.2
Generated Tue Jan 4 15:43:15 2005 by Doxygen 1.4.0