00001
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
00014 class VisualTargetCloseTrans : public Transition {
00015 public:
00016
00017 VisualTargetCloseTrans(StateNode* destination, unsigned int source_id, float threshold=225)
00018 : Transition("VisualTargetCloseTrans",destination), sid(source_id), distanceThreshold(threshold) {}
00019
00020
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
00025 virtual void DoStart() { Transition::DoStart(); erouter->addListener(this,EventBase::visObjEGID,sid); }
00026
00027
00028 virtual void DoStop() { erouter->removeListener(this); Transition::DoStop(); }
00029
00030
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=::IRDistOffset;
00037
00038
00039 if(RobotName == ERS7Info::TargetName)
00040 IRDistOffset=(distanceThreshold<350) ? ERS7Info::NearIRDistOffset : ERS7Info::FarIRDistOffset;
00041 if(x*x+y*y<0.02f && IRDistOffset!=-1U && state->sensors[IRDistOffset]<distanceThreshold)
00042 fire();
00043 }
00044
00045 protected:
00046
00047 unsigned int sid;
00048
00049
00050 float distanceThreshold;
00051 };
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 #endif