DeadReckoningBehavior.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_DeadReckoningBehavior_h_
00003 #define INCLUDED_DeadReckoningBehavior_h_
00004
00005 #include "Behaviors/BehaviorBase.h"
00006 #include "Events/EventRouter.h"
00007 #include "Events/LocomotionEvent.h"
00008 #include "Localization/HolonomicMotionModel.h"
00009 #include "Shared/WorldState.h"
00010
00011
00012
00013
00014
00015 template<class ParticleT>
00016 class DeadReckoningBehavior : public BehaviorBase, public HolonomicMotionModel<ParticleT> {
00017 public:
00018
00019 explicit DeadReckoningBehavior(const std::string& name="DeadReckoningBehavior")
00020 : BehaviorBase(name), HolonomicMotionModel<ParticleT>(), vel_x(), vel_y(), vel_a() {}
00021
00022
00023 DeadReckoningBehavior(float xVariance, float yVariance, float aVariance)
00024 : BehaviorBase("DeadReckoningBehavior"), HolonomicMotionModel<ParticleT>(xVariance,yVariance,aVariance),
00025 vel_x(), vel_y(), vel_a() {}
00026
00027 virtual void doStart() {
00028 vel_x = state->vel_x;
00029 vel_y = state->vel_y;
00030 vel_a = state->vel_a;
00031 HolonomicMotionModel<ParticleT>::setVelocity(vel_x,vel_y,vel_a);
00032 erouter->addListener(this, EventBase::locomotionEGID );
00033
00034 }
00035
00036 virtual void doEvent() {
00037 if (event->getGeneratorID() == EventBase::locomotionEGID) {
00038 const LocomotionEvent &locoevt = dynamic_cast<const LocomotionEvent&>(*event);
00039 float new_x = locoevt.x;
00040 float new_y = locoevt.y;
00041 float new_a = locoevt.a;
00042 if ( (new_x == 0 && new_y == 0 && new_a == 0 && (vel_x != 0 || vel_y != 0 || vel_a != 0))
00043 || fabs(new_x-vel_x) > 0.1
00044 || fabs(new_y-vel_y) > 0.1
00045 || fabs(new_a-vel_a) > 0.001 ) {
00046
00047 vel_x = new_x;
00048 vel_y = new_y;
00049 vel_a = new_a;
00050 HolonomicMotionModel<ParticleT>::setVelocity(vel_x,vel_y,vel_a,locoevt.getTimeStamp());
00051 }
00052 } else if (event->getGeneratorID() == EventBase::timerEGID) {
00053 float tempx;
00054 float tempy;
00055 float tempa;
00056 HolonomicMotionModel<ParticleT>::getPosition(tempx, tempy, tempa);
00057 std::cout << "DEADPOS " << tempx << " " << tempy << " " << tempa << std::endl;
00058 }
00059 }
00060
00061 static std::string getClassDescription() { return "Subscribes to LocomotionEvents and attempts to track robot movement over time"; }
00062 virtual std::string getDescription() const { return getClassDescription(); }
00063
00064 private:
00065 float vel_x, vel_y, vel_a;
00066 };
00067
00068
00069
00070
00071
00072
00073 #endif