WorldStateVelDaemon.hGo to the documentation of this file.00001
00002 #ifndef INCLUDED_WorldStateVelDaemon_h_
00003 #define INCLUDED_WorldStateVelDaemon_h_
00004
00005 #include "Behaviors/BehaviorBase.h"
00006 #include "Events/EventRouter.h"
00007 #include "Events/LocomotionEvent.h"
00008 #include "Shared/WorldState.h"
00009 #include "Events/EventTrapper.h"
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 class WorldStateVelDaemon : public BehaviorBase, public EventTrapper {
00020 public:
00021
00022 WorldStateVelDaemon() : BehaviorBase("WorldStateVelDaemon"), estopTime(1), old_x(0), old_y(0), old_a(0) {}
00023
00024 virtual void DoStart() {
00025 BehaviorBase::DoStart();
00026 erouter->addTrapper(this,EventBase::locomotionEGID);
00027 erouter->addListener(this,EventBase::estopEGID);
00028 }
00029
00030 virtual void DoStop() {
00031 erouter->removeListener(this);
00032 erouter->removeTrapper(this);
00033 BehaviorBase::DoStop();
00034 }
00035
00036
00037 virtual bool trapEvent(const EventBase& e) {
00038 const LocomotionEvent& le=dynamic_cast<const LocomotionEvent&>(e);
00039 old_x=le.x;
00040 old_y=le.y;
00041 old_a=le.a;
00042 if(!estopTime) {
00043 state->vel_x=le.x;
00044 state->vel_y=le.y;
00045 state->vel_a=le.a;
00046 state->vel_time=le.getTimeStamp();
00047 return false;
00048 }
00049 return true;
00050 }
00051
00052 virtual void processEvent(const EventBase& e) {
00053 if(e.getTypeID()==EventBase::deactivateETID) {
00054 if(estopTime) {
00055 estopTime=0;
00056 LocomotionEvent *le = new LocomotionEvent(EventBase::locomotionEGID,e.getSourceID(),EventBase::statusETID,e.getTimeStamp()-state->vel_time);
00057 le->setXYA(old_x,old_y,old_a);
00058 erouter->postEvent(le);
00059 }
00060 } else {
00061 if(!estopTime) {
00062 float older_x=old_x;
00063 float older_y=old_y;
00064 float older_a=old_a;
00065 erouter->postEvent(new LocomotionEvent(EventBase::locomotionEGID,e.getSourceID(),EventBase::statusETID,e.getTimeStamp()-state->vel_time));
00066 estopTime=e.getTimeStamp();
00067 old_x=older_x;
00068 old_y=older_y;
00069 old_a=older_a;
00070 }
00071 }
00072 }
00073
00074 static std::string getClassDescription() { return "Keeps the WorldState's velocity fields up to date"; }
00075 virtual std::string getDescription() const { return getClassDescription(); }
00076
00077 protected:
00078 unsigned int estopTime;
00079 float old_x;
00080 float old_y;
00081 float old_a;
00082 };
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 #endif
|