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 #include "DualCoding/VRmixin.h"
00013 
00014 //!default name for WaypointEngineNode's (have to instantiate a variable in order to use as a template argument)
00015 /*! instantiation will be placed in MCNode.cc to avoid file bloat */
00016 extern const char defWaypointWalkNodeName[];
00017 //!default description for WaypointWalkNode's (have to instantiate a variable in order to use as a template argument)
00018 /*! instantiation will be placed in MCNode.cc to avoid file bloat */
00019 extern const char defWaypointWalkNodeDesc[];
00020 
00021 //! 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
00022 template<typename W, const char* mcName=defWaypointWalkNodeName, const char* mcDesc=defWaypointWalkNodeDesc>
00023 class WaypointEngineNode : public MCNode<W,mcName,mcDesc> {
00024 public:
00025   
00026   //! constructor
00027   WaypointEngineNode() : MCNode<W,mcName,mcDesc>() {}
00028   
00029   //! constructor
00030   WaypointEngineNode(const std::string& name) : MCNode<W,mcName,mcDesc>(name) {}
00031   
00032   //!destructor
00033   ~WaypointEngineNode() {}
00034   
00035   virtual void postStart() {
00036     // std::cout << "WaypointwalkNode id=" << MCNode<W,mcName,mcDesc>::getMC_ID() << "="
00037     //           << MCNode<W,mcName,mcDesc>::getMC()->getID() << " start" << std::endl;
00038     MCNode<W,mcName,mcDesc>::postStart();
00039     if ( MCNode<W,mcName,mcDesc>::isActive() ) {
00040       erouter->addListener(this, EventBase::locomotionEGID, MCNode<W,mcName,mcDesc>::getMC_ID(), EventBase::statusETID);
00041       MCNode<W,mcName,mcDesc>::getMC()->go();
00042     }
00043     erouter->addTimer(this, 9999, 2000, true);
00044 
00045     DualCoding::VRmixin::isWalkingFlag = true;
00046   }
00047   
00048   virtual void stop() {
00049     { MMAccessor<W> wp_walker = MCNode<W,mcName,mcDesc>::getMC();
00050       wp_walker->pause(); // prevent cycle() from running and setting the velocity again
00051       wp_walker->zeroVelocities();
00052     }
00053     // std::cout << "WaypointwalkNode id=" << MCNode<W,mcName,mcDesc>::getMC_ID() << "="
00054     //           << MCNode<W,mcName,mcDesc>::getMC()->getID() << " stop" << std::endl;
00055     DualCoding::VRmixin::autoRefreshSketchWorld();
00056     MCNode<W,mcName,mcDesc>::stop();
00057 
00058     DualCoding::VRmixin::isWalkingFlag = false;
00059   }
00060 
00061 protected:
00062   //! constructor
00063   WaypointEngineNode(const std::string& className, const std::string& instanceName) : 
00064   MCNode<W,mcName,mcDesc>(className,instanceName) {}
00065   
00066   void doEvent() {
00067     if ( MCNode<W,mcName,mcDesc>::event->getGeneratorID() == EventBase::timerEGID && MCNode<W,mcName,mcDesc>::event->getSourceID() == 9999 )
00068       DualCoding::VRmixin::autoRefreshSketchWorld();
00069     else if ( static_cast<const LocomotionEvent&>(*MCNode<W,mcName,mcDesc>::event).isStop() )
00070       MCNode<W,mcName,mcDesc>::postStateCompletion();
00071   }
00072   
00073 };
00074 
00075 //! the prototypical WaypointWalkNode, using a WaypointWalkMC
00076 typedef WaypointEngineNode<WaypointWalkMC> WaypointWalkNode;
00077 
00078 /*! @file
00079  * @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
00080  * @author dst (Creator)
00081  */
00082 
00083 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:52 2016 by Doxygen 1.6.3