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