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
00015
00016
00017
00018
00019 extern const char defHeadPointerNodeName[]="HeadPointerNode";
00020
00021 extern const char defHeadPointerNodeDesc[]="Manages a HeadPointerMC to look in a given direction each time the node is activated";
00022
00023
00024 extern const char defPIDNodeName[]="PIDNode";
00025
00026 extern const char defPIDNodeDesc[]="Manages a PIDMC to set joint power levels when the node is activated";
00027
00028
00029 extern const char defCrabArmNodeName[]="CrabArmNode";
00030
00031 extern const char defCrabArmNodeDesc[]="Manages a CrabArmMC to reach in a given direction each time the node is activated";
00032
00033
00034 extern const char defArmNodeName[]="ArmNode";
00035
00036 extern const char defArmNodeDesc[]="Manages an ArmMC to reach in a given direction each time the node is activated";
00037
00038
00039 extern const char defTailWagNodeName[]="TailWagNode";
00040
00041 extern const char defTailWagNodeDesc[]="Wags the tail for as long as the state is active";
00042
00043
00044 extern const char defPostureNodeName[]="PostureNode";
00045
00046 extern const char defPostureNodeDesc[]="Moves the body to the specified posture";
00047
00048
00049 extern const char defMotionSequenceNodeName[]="MotionSequenceNode";
00050
00051 extern const char defMotionSequenceNodeDesc[]="Moves the body through the specified motion sequence";
00052
00053
00054 extern const char defDynamicMotionSequenceNodeName[]="DynamicMotionSequenceNode";
00055
00056 extern const char defDynamicMotionSequenceNodeDesc[]="Moves the body through the specified dynamic motion sequence";
00057
00058
00059 extern const char defWalkNodeName[]="WalkNode";
00060
00061 extern const char defWalkNodeDesc[]="Manages a WalkMC node to walk in a direction each time the node is activated.";
00062
00063
00064 extern const char defWaypointWalkNodeName[]="WaypointWalkNode";
00065
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();
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
00117
00118
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
00129
00130
00131