Tekkotsu 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 #include "Shared/MarkScope.h"
00013 
00014 //! causes a transition when a visual object is "close"
00015 class VisualTargetCloseTrans : public Transition {
00016 public:
00017   //!constructor
00018   VisualTargetCloseTrans(StateNode* destination, unsigned int source_id, float threshold=225)
00019     : Transition(destination), sid(source_id), distanceThreshold(threshold) {}
00020 
00021   //!constructor
00022   VisualTargetCloseTrans(const std::string& name, StateNode* destination, unsigned int source_id, float threshold=225)
00023     : Transition(name,destination), sid(source_id), distanceThreshold(threshold) {}
00024 
00025   //!starts listening for the object specified by the source id in the constructor
00026   virtual void postStart() {
00027     Transition::postStart();
00028     erouter->addListener(this,EventBase::visObjEGID,sid);
00029   }
00030 
00031   //!if the object is "close", calls fire()
00032   virtual void doEvent() {
00033     const VisionObjectEvent* ve=dynamic_cast<const VisionObjectEvent*>(event);
00034     ASSERTRET(ve!=NULL,"Casting error");
00035     float x=ve->getCenterX();
00036     float y=ve->getCenterY();
00037     unsigned int IRDistOffset=::IRDistOffset;
00038     //The ERS-7 adds more IR distance sensors, so we have to
00039     //break it down so we can specify which one
00040     if(RobotName == ERS7Info::TargetName)
00041       IRDistOffset=(distanceThreshold<350) ? ERS7Info::NearIRDistOffset : ERS7Info::FarIRDistOffset;
00042     if(x*x+y*y<0.02f && IRDistOffset!=-1U && state->sensors[IRDistOffset]<distanceThreshold)
00043       fire(*event);
00044   }
00045 
00046 protected:
00047   //!Source ID of object to track
00048   unsigned int sid;
00049   
00050   //!Distance at which to trigger transition, in millimeters
00051   float distanceThreshold;
00052 };
00053 
00054 /*! @file
00055  * @brief Defines VisualTargetCloseTrans, which causes a transition when a visual object is "close"
00056  * @author ejt (Creator)
00057  */
00058 
00059 #endif

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