Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

WaypointWalkNode.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_WaypointWalkNode_h_
00003 #define INCLUDED_WaypointWalkNode_h_
00004 
00005 #include "MCNode.h"
00006 #include "Motion/MotionManager.h"
00007 #define WALKMC_NO_WARN_NOOP
00008 #include "Motion/WaypointWalkMC.h"
00009 #undef WALKMC_NO_WARN_NOOP
00010 #include "Events/EventRouter.h"
00011 #include "Events/LocomotionEvent.h"
00012 
00013 //!default name for WaypointEngineNode's (have to instantiate a variable in order to use as a template argument)
00014 /*! instantiation will be placed in MCNode.cc to avoid file bloat */
00015 extern const char defWaypointWalkNodeName[];
00016 //!default description for WaypointWalkNode's (have to instantiate a variable in order to use as a template argument)
00017 /*! instantiation will be placed in MCNode.cc to avoid file bloat */
00018 extern const char defWaypointWalkNodeDesc[];
00019 
00020 //! A StateNode for doing a waypoint walk, use the template parameter to specify a custom walk MC, or use the ::WaypointWalkNode typedef to accept the "default" walk
00021 template<typename W, const char* mcName=defWaypointWalkNodeName, const char* mcDesc=defWaypointWalkNodeDesc>
00022 class WaypointEngineNode : public MCNode<W,mcName,mcDesc> {
00023 public:
00024   
00025   //! constructor
00026   WaypointEngineNode() : MCNode<W,mcName,mcDesc>() {}
00027   
00028   //! constructor
00029   WaypointEngineNode(const std::string& name) : MCNode<W,mcName,mcDesc>(name) {}
00030   
00031   //!destructor
00032   ~WaypointEngineNode() {}
00033   
00034   virtual void postStart() {
00035     // std::cout << "WaypointwalkNode id=" << MCNode<W,mcName,mcDesc>::getMC_ID() << "="
00036     //           << MCNode<W,mcName,mcDesc>::getMC()->getID() << " start" << std::endl;
00037     MCNode<W,mcName,mcDesc>::postStart();
00038     if ( MCNode<W,mcName,mcDesc>::isActive() ) {
00039       erouter->addListener(this, EventBase::locomotionEGID, MCNode<W,mcName,mcDesc>::getMC_ID(), EventBase::statusETID);
00040       MCNode<W,mcName,mcDesc>::getMC()->go();
00041     }
00042   }
00043   
00044   virtual void stop() {
00045     { MMAccessor<W> wp_walker = MCNode<W,mcName,mcDesc>::getMC();
00046       wp_walker->pause(); // prevent cycle() from running and setting the velocity again
00047       wp_walker->zeroVelocities();
00048     }
00049     // std::cout << "WaypointwalkNode id=" << MCNode<W,mcName,mcDesc>::getMC_ID() << "="
00050     //           << MCNode<W,mcName,mcDesc>::getMC()->getID() << " stop" << std::endl;
00051     MCNode<W,mcName,mcDesc>::stop();
00052   }
00053 
00054 protected:
00055   //! constructor
00056   WaypointEngineNode(const std::string& className, const std::string& instanceName) : 
00057   MCNode<W,mcName,mcDesc>(className,instanceName) {}
00058   
00059   void doEvent() {
00060     if ( static_cast<const LocomotionEvent&>(*this->event).isStop() )
00061       MCNode<W,mcName,mcDesc>::postStateCompletion();
00062   }
00063   
00064 };
00065 
00066 //! the prototypical WaypointWalkNode, using a WaypointWalkMC
00067 typedef WaypointEngineNode<WaypointWalkMC> WaypointWalkNode;
00068 
00069 /*! @file
00070  * @brief Describes WaypointEngineNode,  a StateNode for doing a waypoint walk; use the template parameter to specify a custom waypoint walk MC, or use the WaypointWalkNode typedef to accept the "default" walk
00071  * @author dst (Creator)
00072  */
00073 
00074 #endif

Tekkotsu v5.1CVS
Generated Fri Mar 16 05:26:54 2012 by Doxygen 1.6.3