Homepage | Demos | Overview | Downloads | Tutorials | Reference | Credits |
SimpleChaseBallBehavior.hGo 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("SimpleChaseBallBehavior"), 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->addPersistentMotion(SharedObject<WalkMC>()); //the 'false' prevents autopruning 00031 erouter->addListener(this,EventBase::visObjEGID); 00032 } 00033 00034 //! removes motion commands and stops listening 00035 virtual void DoStop() { 00036 erouter->removeListener(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 protected: 00053 MotionManager::MC_ID walker_id; //!< a WalkMC object 00054 }; 00055 00056 /*! @file 00057 * @brief Describes SimpleChaseBallBehavior, which runs around after whatever the dog sees 00058 * @author ejt (Creator) 00059 * 00060 * $Author: ejt $ 00061 * $Name: tekkotsu-2_2_1 $ 00062 * $Revision: 1.10 $ 00063 * $State: Exp $ 00064 * $Date: 2004/11/11 01:45:36 $ 00065 */ 00066 00067 #endif |
Tekkotsu v2.2.1 |
Generated Tue Nov 23 16:36:40 2004 by Doxygen 1.3.9.1 |