Homepage Demos Overview Downloads Tutorials Reference
Credits
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Search

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     // in the near future, these two will be unnecessary.
00034     // (vision will use erouter to check if it has listeners)
00035     vision->enableEvents(VisionEventNS::RedBallSID);
00036     vision->enableEvents(VisionEventNS::PinkBallSID);
00037   }
00038 
00039   //! removes motion commands and stops listening
00040   virtual void DoStop() {
00041     erouter->forgetListener(this);
00042     motman->removeMotion(walker_id);
00043     BehaviorBase::DoStop();
00044   }
00045 
00046   //! sets the head to point at the object and sets the body to move where the head points
00047   virtual void processEvent(const EventBase& event) {
00048     if(event.getGeneratorID()==EventBase::visionEGID && event.getTypeID()==EventBase::statusETID) {
00049       //in case the head isn't pointing straight forward, we'll straife
00050       float x=120.0f*cos(state->outputs[HeadOffset+PanOffset]);
00051       float y=120.0f*sin(state->outputs[HeadOffset+PanOffset]);
00052       float z=-static_cast<const VisionEvent*>(&event)->getCenterX();
00053       MMAccessor<WalkMC>(walker_id)->setTargetVelocity(x,y,z);
00054     }
00055   }
00056       
00057   virtual std::string getName() const { return "SimpleChaseBallBehavior"; } 
00058 
00059 protected:
00060   MotionManager::MC_ID walker_id;      //!< a WalkMC object
00061 };
00062 
00063 /*! @file
00064  * @brief Describes SimpleChaseBallBehavior, which runs around after whatever the dog sees
00065  * @author ejt (Creator)
00066  *
00067  * $Author: ejt $
00068  * $Name: tekkotsu-1_4_1 $
00069  * $Revision: 1.3 $
00070  * $State: Exp $
00071  * $Date: 2003/06/12 18:06:11 $
00072  */
00073 
00074 #endif

Tekkotsu v1.4
Generated Sat Jul 19 00:06:31 2003 by Doxygen 1.3.2