Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

DeadReckoningBehavior.h

Go to the documentation of this file.
00001 //-*-c++-*-
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 //! Subscribes to LocomotionEvents and attempts to track robot movement over time using a fairly generic HolonomicMotionModel
00012 /*! Can be used as a ParticleFilter::MotionModel, or as a component of other behaviors.
00013  *
00014  *  If you want a regular report on position, the behavior will output current position on timer events */
00015 template<class ParticleT>
00016 class DeadReckoningBehavior : public BehaviorBase, public HolonomicMotionModel<ParticleT> {
00017 public:
00018   //! constructor
00019   explicit DeadReckoningBehavior(const std::string& name="DeadReckoningBehavior")
00020     : BehaviorBase(name), HolonomicMotionModel<ParticleT>(), vel_x(), vel_y(), vel_a() {}
00021   
00022   //! constructor
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     //erouter->addTimer(this, 0, 500);
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)) // robot has just stopped
00043      || fabs(new_x-vel_x) > 0.1       // translation velocity change > 0.1 mm/sec
00044      || fabs(new_y-vel_y) > 0.1 
00045      || fabs(new_a-vel_a) > 0.001 ) { // angular velocity change > 0.001 rad/sec
00046   // std::cout << "New DeadReckoning velocities: " << new_x << " " << new_y << " " << new_a << std::endl;
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 /*! @file
00069  * @brief Defines DeadReckoningBehavior, which subscribes to LocomotionEvents and attempts to track robot movement over time using a fairly generic HolonomicMotionModel
00070  * @author Ethan Tira-Thompson (ejt) (Creator)
00071  */
00072 
00073 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:37 2016 by Doxygen 1.6.3