VisualTargetCloseTrans.h
Go to the documentation of this file.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 #include "Shared/MarkScope.h"
00013
00014
00015 class VisualTargetCloseTrans : public Transition {
00016 public:
00017
00018 VisualTargetCloseTrans(StateNode* destination, unsigned int source_id, float threshold=225)
00019 : Transition(destination), sid(source_id), distanceThreshold(threshold) {}
00020
00021
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
00026 virtual void postStart() {
00027 Transition::postStart();
00028 erouter->addListener(this,EventBase::visObjEGID,sid);
00029 }
00030
00031
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
00039
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
00048 unsigned int sid;
00049
00050
00051 float distanceThreshold;
00052 };
00053
00054
00055
00056
00057
00058
00059 #endif