Homepage Demos Overview Downloads Tutorials Reference
Credits

SimpleChaseBallBehavior.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_SimpleChaseBallBehavior_h_
00003 #define INCLUDED_SimpleChaseBallBehavior_h_
00004 
00005 #include "Behaviors/BehaviorBase.h"
00006 #include "Motion/MotionManager.h"
00007 #include "Motion/MMAccessor.h"
00008 
00009 #include "Events/EventRouter.h"
00010 #include "Events/VisionEvent.h"
00011 #include "Shared/WorldState.h"
00012 #include "Motion/WalkMC.h"
00013 #include "Vision/Vision.h"
00014 
00015 //! A simple behavior to chase after any objects seen by the vision system
00016 /*! Similar to ChaseBallBehavior, but this one doesn't try to move the head, so
00017  *  it's a little more... simple.  However, it does make sure to take into account
00018  *  which direction the head is pointing when it sees the object. */
00019 class SimpleChaseBallBehavior : public BehaviorBase {
00020 public:
00021   //!constructor
00022   SimpleChaseBallBehavior()
00023     : BehaviorBase(), walker_id(MotionManager::invalid_MC_ID)
00024   {}
00025   //!destructor
00026   virtual ~SimpleChaseBallBehavior() {}
00027 
00028   //! adds a headpointer and a walker, and a listens for vision events
00029   virtual void DoStart() {
00030     BehaviorBase::DoStart();
00031     walker_id = motman->addMotion(SharedObject<WalkMC>());
00032     erouter->addListener(this,EventBase::visionEGID);
00033   }
00034 
00035   //! removes motion commands and stops listening
00036   virtual void DoStop() {
00037     erouter->forgetListener(this);
00038     motman->removeMotion(walker_id);
00039     BehaviorBase::DoStop();
00040   }
00041 
00042   //! sets the head to point at the object and sets the body to move where the head points
00043   virtual void processEvent(const EventBase& event) {
00044     if(event.getGeneratorID()==EventBase::visionEGID && event.getTypeID()==EventBase::statusETID) {
00045       //in case the head isn't pointing straight forward, we'll straife
00046       float x=120.0f*cos(state->outputs[HeadOffset+PanOffset]);
00047       float y=120.0f*sin(state->outputs[HeadOffset+PanOffset]);
00048       float z=-static_cast<const VisionEvent*>(&event)->getCenterX();
00049       MMAccessor<WalkMC>(walker_id)->setTargetVelocity(x,y,z);
00050     }
00051   }
00052       
00053   virtual std::string getName() const { return "SimpleChaseBallBehavior"; } 
00054 
00055 protected:
00056   MotionManager::MC_ID walker_id;      //!< a WalkMC object
00057 };
00058 
00059 /*! @file
00060  * @brief Describes SimpleChaseBallBehavior, which runs around after whatever the dog sees
00061  * @author ejt (Creator)
00062  *
00063  * $Author: ejt $
00064  * $Name: tekkotsu-1_5 $
00065  * $Revision: 1.4 $
00066  * $State: Rel $
00067  * $Date: 2003/07/28 18:39:18 $
00068  */
00069 
00070 #endif

Tekkotsu v1.5
Generated Fri Oct 10 15:52:00 2003 by Doxygen 1.3.4