Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

MCNode.cc

Go to the documentation of this file.
00001 #include "MCNode.h"
00002 #include "Events/EventRouter.h"
00003 #include "Shared/MarkScope.h"
00004 
00005 #include "Shared/RobotInfo.h"
00006 #ifdef TGT_HAS_TAIL
00007 #include "TailWagNode.h"
00008 REGISTER_BEHAVIOR_MENU_OPT(TailWagNode,DEFAULT_TK_MENU,BEH_NONEXCLUSIVE);
00009 #endif
00010 
00011 const char MCNodeBase::defName[]="MCNode";
00012 const char MCNodeBase::defDesc[]="A generic wrapper for any MotionCommand";
00013 
00014 // These externs are declared in their respective header files, but
00015 // defined here instead of corresponding .cc files to avoid file bloat
00016 // (there would be nothing else in their .cc files)
00017 
00018 //! name for HeadPointerNode to pass as template argument
00019 extern const char defHeadPointerNodeName[]="HeadPointerNode";
00020 //! description for HeadPointerNode to pass as template argument
00021 extern const char defHeadPointerNodeDesc[]="Manages a HeadPointerMC to look in a given direction each time the node is activated";
00022 
00023 //! name for PIDNode to pass as template argument
00024 extern const char defPIDNodeName[]="PIDNode";
00025 //! description for PIDNode to pass as template argument
00026 extern const char defPIDNodeDesc[]="Manages a PIDMC to set joint power levels when the node is activated";
00027 
00028 //! name for CrabArmNode to pass as template argument
00029 extern const char defCrabArmNodeName[]="CrabArmNode";
00030 //! description for CrabArmNode to pass as template argument
00031 extern const char defCrabArmNodeDesc[]="Manages a CrabArmMC to reach in a given direction each time the node is activated";
00032 
00033 //! name for ArmNode to pass as template argument
00034 extern const char defArmNodeName[]="ArmNode";
00035 //! description for ArmNode to pass as template argument
00036 extern const char defArmNodeDesc[]="Manages an ArmMC to reach in a given direction each time the node is activated";
00037 
00038 //! name for TailWagNode to pass as template argument
00039 extern const char defTailWagNodeName[]="TailWagNode";
00040 //! description for TailWagNode to pass as template argument
00041 extern const char defTailWagNodeDesc[]="Wags the tail for as long as the state is active";
00042 
00043 //! name for PostureNode to pass as template argument
00044 extern const char defPostureNodeName[]="PostureNode";
00045 //! description for PostureNode to pass as template argument
00046 extern const char defPostureNodeDesc[]="Moves the body to the specified posture";
00047 
00048 //! name for MotionSequenceNode to pass as template argument
00049 extern const char defMotionSequenceNodeName[]="MotionSequenceNode";
00050 //! description for MotionSequenceNode to pass as template argument
00051 extern const char defMotionSequenceNodeDesc[]="Moves the body through the specified motion sequence";
00052 
00053 //! name for DynamicMotionSequenceNode to pass as template argument
00054 extern const char defDynamicMotionSequenceNodeName[]="DynamicMotionSequenceNode";
00055 //! description for DynamicMotionSequenceNode to pass as template argument
00056 extern const char defDynamicMotionSequenceNodeDesc[]="Moves the body through the specified dynamic motion sequence";
00057 
00058 //! name for WalkNode to pass as template argument
00059 extern const char defWalkNodeName[]="WalkNode";
00060 //! description for WalkNode to pass as template argument
00061 extern const char defWalkNodeDesc[]="Manages a WalkMC node to walk in a direction each time the node is activated.";
00062 
00063 //! name for WaypointWalkNode to pass as template argument
00064 extern const char defWaypointWalkNodeName[]="WaypointWalkNode";
00065 //! description for WaypointWalkNode to pass as template argument
00066 extern const char defWaypointWalkNodeDesc[]="Manages a WaypointWalkMC to perform a waypoint walk each time the node is activated.";
00067 
00068 void MCNodeBase::preStart() {
00069   StateNode::preStart();
00070   if(mc_id==MotionManager::invalid_MC_ID)
00071     mc_id = motman->addPersistentMotion(getPrivateMC(),priority);
00072   else
00073     motman->setPriority(mc_id,priority);
00074   erouter->addListener(this,EventBase::motmanEGID,mc_id,EventBase::statusETID);
00075 }
00076 
00077 void MCNodeBase::doEvent() {
00078   if(mcCompletes && event->getGeneratorID()==EventBase::motmanEGID && event->getSourceID()==mc_id)
00079     postStateCompletion();
00080   else
00081     StateNode::doEvent();
00082 }
00083 
00084 void MCNodeBase::stop() {
00085   if(hasPrivateMC()) {
00086     motman->removeMotion(mc_id);
00087     mc_id=MotionManager::invalid_MC_ID;
00088   } else if(mc_id!=MotionManager::invalid_MC_ID) {
00089     motman->setPriority(mc_id,MotionManager::kIgnoredPriority);
00090   }
00091   StateNode::stop(); // do this last (required)
00092 }
00093 
00094 void MCNodeBase::setMC(MotionManager::MC_ID new_mc_id) {
00095   if ( new_mc_id != MotionManager::invalid_MC_ID ) {
00096     erouter->removeListener(this,EventBase::motmanEGID, mc_id);
00097     if( mc != NULL ) {
00098       if ( mc_id != MotionManager::invalid_MC_ID )
00099         motman->removeMotion(mc_id);
00100       delete mc;
00101       mc=NULL;
00102     }
00103     mc_id = new_mc_id;
00104     if ( isActive() )
00105       erouter->addListener(this,EventBase::motmanEGID,mc_id,EventBase::statusETID);
00106   }
00107 }
00108 
00109 void MCNodeBase::setPriority(const float p) {
00110   priority = p;
00111   if ( mc_id != MotionManager::invalid_MC_ID )
00112     motman->setPriority(mc_id, priority);
00113 }
00114 
00115 void MCNodeBase::motionFails() {
00116   // Shut down the motion command: copied from stop() because we don't
00117   // want to call StateNode::stop() here; that would deactivate any
00118   // outgoing failure transition
00119   if(hasPrivateMC()) {
00120     motman->removeMotion(mc_id);
00121     mc_id=MotionManager::invalid_MC_ID;
00122   } else if(mc_id!=MotionManager::invalid_MC_ID) {
00123     motman->setPriority(mc_id,MotionManager::kIgnoredPriority);
00124   }
00125   postStateFailure();
00126 }
00127 
00128 /*! @file
00129  * @brief Implement's MCNode's default name and description strings (the class is templated, so everything else has to go in the header)
00130  * @author Ethan Tira-Thompson (ejt) (Creator)
00131  */

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