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

Tekkotsu v2.0
Generated Wed Jan 21 03:20:29 2004 by Doxygen 1.3.4