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