Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

MotionNodes.h

Go to the documentation of this file.
00001 #ifndef _MOTION_NODES_H_
00002 #define _MOTION_NODES_H_
00003 
00004 #ifdef TGT_HAS_ARMS
00005 
00006 //************
00007 
00008 #include "Behaviors/StateNode.h"
00009 #include "Behaviors/Nodes/ArmNode.h"
00010 #include "Behaviors/Nodes/HeadPointerNode.h"
00011 #include "Behaviors/Nodes/DynamicMotionSequenceNode.h"
00012 #include "Behaviors/Nodes/PostureNode.h"
00013 #include "Behaviors/Nodes/SoundNode.h"
00014 #include "Behaviors/Nodes/SpeechNode.h"
00015 
00016 #if defined(TGT_HAS_LEGS) || defined(TGT_HAS_WHEELS)
00017 #include "Behaviors/Nodes/WalkNode.h"
00018 #endif
00019 
00020 #include "DualCoding/DualCoding.h"
00021 #include "DualCoding/VisualRoutinesStateNode.h"
00022 
00023 #include "Behaviors/Transition.h"
00024 #include "Behaviors/Transitions/CompareTrans.h"
00025 #include "Behaviors/Transitions/CompletionTrans.h"
00026 #include "Behaviors/Transitions/EventTrans.h"
00027 #include "Behaviors/Transitions/NullTrans.h"
00028 #include "Behaviors/Transitions/RandomTrans.h"
00029 #include "Behaviors/Transitions/SignalTrans.h"
00030 #include "Behaviors/Transitions/SmoothCompareTrans.h"
00031 #include "Behaviors/Transitions/TextMsgTrans.h"
00032 #include "Behaviors/Transitions/TimeOutTrans.h"
00033 #include "Behaviors/Transitions/VisualTargetTrans.h"
00034 #include <Behaviors/Transitions/TimeOutTrans.h>
00035 
00036 #ifdef TARGET_HAS_IR
00037 #include "Behaviors/Transitions/VisualTargetCloseTrans.h"
00038 #endif
00039 
00040 
00041 //************
00042 
00043 #include <Motion/MotionManager.h>
00044 
00045 #include <IPC/DriverMessaging.h>
00046 #include <Motion/PlanarThreeLinkArm.h>
00047 #include <Shared/fmatCore.h>
00048 
00049 #include <string>
00050 using namespace std;
00051 
00052 typedef fmat::Row<RobotInfo::NumArmJoints> ArmConfiguration;
00053 
00054 /*
00055   Nodes Defined:
00056 
00057   SetWrist
00058   SetArm
00059   SetJoint
00060   SetGround
00061   Twist
00062   Sway
00063   Rock
00064   Turn
00065   WalkSideways
00066   WalkForward
00067 */
00068 
00069 extern MotionManager::MC_ID motionNodesWalkMC;
00070 
00071 #if defined(TGT_HAS_LEGS) || defined(TGT_HAS_WHEELS)
00072 class ResetInitialPlacementXX : public WalkNode {
00073  public:
00074   ResetInitialPlacementXX(const std::string &nodename="ResetInitialPlacementXX") : WalkNode(nodename) {}
00075   virtual void doStart() {
00076   setMC(motionNodesWalkMC);
00077   motman->setPriority(motionNodesWalkMC, priority);
00078   getMC()->start();
00079   postStateCompletion();
00080   }
00081 };
00082 #endif
00083 
00084 class SetWrist : public ArmNode {
00085  public:
00086   SetWrist(const std::string &nodename, float _pitch=0, float _roll=0, float _grip=0) : ArmNode(nodename), pitch(_pitch), roll(_roll), grip(_grip) {}
00087   float pitch;  // cache the constructor's parameter
00088   float roll;  // cache the constructor's parameter
00089   float grip;  // cache the constructor's parameter
00090   virtual void doStart() {
00091   if (RobotInfo::NumArmJoints <= 3) {
00092     postStateCompletion();
00093     return;
00094   }
00095   cout<<"Setting wrist to ("<<pitch<<", "<<roll<<", "<<grip<<")"<<endl;
00096   //    getMC()->takeSnapshot();
00097   getMC()->setWrist(pitch, roll, grip);
00098   }
00099 };
00100 
00101 class SetArm : public ArmNode {
00102  public:
00103   SetArm(const std::string &nodename, float _shoulder=0, float _elbow=0, float _wrist=0) : ArmNode(nodename), shoulder(_shoulder), elbow(_elbow), wrist(_wrist) {}
00104   float shoulder;  // cache the constructor's parameter
00105   float elbow;  // cache the constructor's parameter
00106   float wrist;  // cache the constructor's parameter
00107   void move(float s, float e, float w) {
00108     cout<<"Setting arm to ("<<s<<", "<<e<<", "<<w<<")"<<endl;
00109     //    getMC()->takeSnapshot();
00110     getMC()->setJoints(s, e, w);
00111   }
00112 
00113   virtual void doStart() {
00114     if(const DataEvent<ArmConfiguration>* dev = dynamic_cast<const DataEvent<ArmConfiguration>*>(event)) {
00115       ArmConfiguration value = dev->getData();
00116       move(value[0], value[1], value[2]);
00117     } else {
00118       move(shoulder, elbow, wrist);
00119     }
00120   }
00121 };
00122 
00123 class SetJoint : public ArmNode {
00124  public:
00125   SetJoint(const std::string &nodename, string _jointName, float _storedVal=0, float _speed=0.4f) : ArmNode(nodename), jointName(_jointName), storedVal(_storedVal), speed(_speed) {}
00126   string jointName;  // cache the constructor's parameter
00127   float storedVal;  // cache the constructor's parameter
00128   float speed;  // cache the constructor's parameter
00129   void moveJoint(float value);  
00130   virtual void doStart() {
00131     if (const DataEvent<float> *dev = dynamic_cast<const DataEvent<float>*>(event)) {
00132       float receivedVal = dev->getData();
00133       moveJoint(receivedVal);
00134     } else {
00135       moveJoint(storedVal);
00136     }
00137   }
00138 };
00139 
00140 class SetServoPower : public StateNode {
00141  public:
00142   SetServoPower(const std::string &nodename, string _jointName, bool _val) : StateNode(nodename), jointName(_jointName), val(_val) {}
00143   string jointName;  // cache the constructor's parameter
00144   bool val;  // cache the constructor's parameter
00145   virtual void doStart() {
00146   /*  using namespace DriverMessaging;
00147     if(hasListener(ToggleServoPower::NAME)) {
00148     ToggleServoPower msg;
00149     msg.jointName = jointName;
00150     msg.holdPower = true;
00151     postMessage(msg);
00152     }
00153   */
00154   }
00155 };
00156 
00157 #if TGT_HAS_LEGS
00158 
00159 class SetGround : public WalkNode {
00160  public:
00161   SetGround(const std::string &nodename="SetGround", float _groundOffset=-10) : WalkNode(nodename), groundOffset(_groundOffset) {}
00162   float groundOffset;  // cache the constructor's parameter
00163   void setID() {
00164     if(motionNodesWalkMC == MotionManager::invalid_MC_ID){
00165       postStateCompletion();
00166       return;
00167     }
00168     setMC(motionNodesWalkMC);
00169     motman->setPriority(motionNodesWalkMC, priority);
00170   }
00171   
00172   void move(float offset) {
00173     cout<<"Setting ground plane to "<<offset<<endl;
00174     getMC()->groundPlane[3] = offset;
00175   }
00176 
00177   virtual void doStart() {
00178     setID();
00179     if(const DataEvent<float>* dev = dynamic_cast<const DataEvent<float>*>(event)) {
00180       float off = dev->getData();
00181       move(off);
00182     } else {
00183       move(groundOffset);
00184     }
00185   }
00186 };
00187 
00188 class Twist : public WalkNode {
00189  public:
00190   Twist(const std::string &nodename, float _angle=0) : WalkNode(nodename), angle(_angle) {}
00191   float angle;  // cache the constructor's parameter
00192   void setID() {
00193     if(motionNodesWalkMC == MotionManager::invalid_MC_ID){
00194       postStateCompletion();
00195       return;
00196     }
00197     setMC(motionNodesWalkMC);
00198     motman->setPriority(motionNodesWalkMC, priority);
00199   }
00200   
00201   void move(float howmuch) {
00202     cout<<"Twisting to "<<howmuch<<endl;
00203     getMC()->offsetA = howmuch;
00204   }
00205 
00206   virtual void doStart() {
00207     setID();
00208     if(const DataEvent<float>* dev = dynamic_cast<const DataEvent<float>*>(event)) {
00209       float off = dev->getData();
00210       move(off);
00211     } else {
00212       move(angle);
00213     }
00214   }
00215 };
00216 
00217 class Sway : public WalkNode {
00218  public:
00219   Sway(const std::string &nodename, float _offset=0) : WalkNode(nodename), offset(_offset) {}
00220   float offset;  // cache the constructor's parameter
00221   void setID() {
00222     if(motionNodesWalkMC == MotionManager::invalid_MC_ID){
00223       postStateCompletion();
00224       return;
00225     }
00226     setMC(motionNodesWalkMC);
00227     motman->setPriority(motionNodesWalkMC, priority);
00228   }
00229   
00230   void move(float howmuch) {
00231     cout<<"Swaying to "<<howmuch<<endl;
00232     getMC()->offsetY = howmuch;
00233   }
00234 
00235   virtual void doStart() {
00236     setID();
00237     if(const DataEvent<float>* dev = dynamic_cast<const DataEvent<float>*>(event)) {
00238       float off = dev->getData();
00239       move(off);
00240     } else {
00241       move(offset);
00242     }
00243   }
00244 };
00245 
00246 class Rock : public WalkNode {
00247  public:
00248   Rock(const std::string &nodename, float _offset=0) : WalkNode(nodename), offset(_offset) {}
00249   float offset;  // cache the constructor's parameter
00250   void setID() {
00251     if(motionNodesWalkMC == MotionManager::invalid_MC_ID){
00252       postStateCompletion();
00253       return;
00254     }
00255     setMC(motionNodesWalkMC);
00256     motman->setPriority(motionNodesWalkMC, priority);
00257   }
00258   
00259   void move(float howmuch) {
00260     cout<<"Rocking to "<<howmuch<<endl;
00261     getMC()->offsetX = howmuch;
00262   }
00263 
00264   virtual void doStart() {
00265     setID();
00266     if(const DataEvent<float>* dev = dynamic_cast<const DataEvent<float>*>(event)) {
00267       float off = dev->getData();
00268       move(off);
00269     } else {
00270       move(offset);
00271     }
00272   }
00273 };
00274 
00275 class Turn : public WalkNode {
00276  public:
00277   Turn(const std::string &nodename, float _myangle=0) : WalkNode(nodename), myangle(_myangle) {}
00278   float myangle;  // cache the constructor's parameter
00279   void setID() {
00280     if(motionNodesWalkMC == MotionManager::invalid_MC_ID){
00281       postStateCompletion();
00282       return;
00283     }
00284     setMC(motionNodesWalkMC);
00285     motman->setPriority(motionNodesWalkMC, priority);
00286   }
00287   
00288   void move(float ang) {
00289     cout<<"Turning by "<<ang<<endl;
00290     getMC()->setTargetVelocity(0, 0, 3*(float)M_PI/180);
00291     getMC()->setTargetDisplacement(0,0, ang);
00292   }
00293 
00294   virtual void doStart() {
00295     setID();
00296     if(const DataEvent<float>* dev = dynamic_cast<const DataEvent<float>*>(event)) {
00297       float val = dev->getData();
00298       move(val);
00299     } else {
00300       move(myangle);
00301     }
00302   }
00303 };
00304 
00305 class WalkSideways : public WalkNode {
00306  public:
00307   WalkSideways(const std::string &nodename, float _distance=0) : WalkNode(nodename), distance(_distance) {}
00308   float distance;  // cache the constructor's parameter
00309   void setID() {
00310     if(motionNodesWalkMC == MotionManager::invalid_MC_ID){
00311       postStateCompletion();
00312       return;
00313     }
00314     setMC(motionNodesWalkMC);
00315     motman->setPriority(motionNodesWalkMC, priority);
00316   }
00317   
00318   void move(float dist) {
00319     cout<<"Walking sideways "<<dist<<endl;
00320     getMC()->setTargetVelocity(0, 10, 0);
00321     getMC()->setTargetDisplacement(0, dist, 0);
00322   }
00323 
00324   virtual void doStart() {
00325     setID();
00326     if(const DataEvent<float>* dev = dynamic_cast<const DataEvent<float>*>(event)) {
00327       float dist = dev->getData();
00328       move(dist);
00329     } else {
00330       move(distance);
00331     }
00332   }
00333 };
00334 
00335 class WalkForward : public WalkNode {
00336  public:
00337   WalkForward(const std::string &nodename, float _distance=0) : WalkNode(nodename), distance(_distance) {}
00338   float distance;  // cache the constructor's parameter
00339   void setID() {
00340     if(motionNodesWalkMC == MotionManager::invalid_MC_ID){
00341       postStateCompletion();
00342       return;
00343     }
00344     setMC(motionNodesWalkMC);
00345     motman->setPriority(motionNodesWalkMC, priority);
00346   }
00347   
00348   void move(float dist) {
00349     cout<<"Walking forward by "<<dist<<endl;
00350     getMC()->setTargetVelocity(10, 0, 0);
00351     getMC()->setTargetDisplacement(dist, 0, 0);
00352   }
00353 
00354   virtual void doStart() {
00355     setID();
00356     if(const DataEvent<float>* dev = dynamic_cast<const DataEvent<float>*>(event)) {
00357       float dist = dev->getData();
00358       move(dist);
00359     } else {
00360       move(distance);
00361     }
00362   }
00363 };
00364 
00365 #else //TGT_HAS_LEGS
00366 
00367 class SetGround : public StateNode {
00368  public:
00369   SetGround(const std::string &nodename="SetGround", float _a=-10) : StateNode(nodename), a(_a) {}
00370   float a;  // cache the constructor's parameter
00371   virtual void doStart() {
00372   postStateCompletion();
00373   }
00374 };
00375   
00376 class Twist : public StateNode {
00377  public:
00378   Twist(const std::string &nodename, float _a=0) : StateNode(nodename), a(_a) {}
00379   float a;  // cache the constructor's parameter
00380   virtual void doStart() {
00381   postStateCompletion();
00382   }
00383 };
00384   
00385 class Sway : public StateNode {
00386  public:
00387   Sway(const std::string &nodename, float _a=0) : StateNode(nodename), a(_a) {}
00388   float a;  // cache the constructor's parameter
00389   virtual void doStart() {
00390   postStateCompletion();
00391   }
00392 };
00393   
00394 class Rock : public StateNode {
00395  public:
00396   Rock(const std::string &nodename, float _a=0) : StateNode(nodename), a(_a) {}
00397   float a;  // cache the constructor's parameter
00398   virtual void doStart() {
00399   postStateCompletion();
00400   }
00401 };
00402   
00403 class Turn : public StateNode {
00404  public:
00405   Turn(const std::string &nodename, float _a=0) : StateNode(nodename), a(_a) {}
00406   float a;  // cache the constructor's parameter
00407   virtual void doStart() {
00408   postStateCompletion();
00409   }
00410 };
00411   
00412 class WalkSideways : public StateNode {
00413  public:
00414   WalkSideways(const std::string &nodename, float _a=0) : StateNode(nodename), a(_a) {}
00415   float a;  // cache the constructor's parameter
00416   virtual void doStart() {
00417   postStateCompletion();
00418   }
00419 };
00420   
00421 class WalkForward : public StateNode {
00422  public:
00423   WalkForward(const std::string &nodename, float _a=0) : StateNode(nodename), a(_a) {}
00424   float a;  // cache the constructor's parameter
00425   virtual void doStart() {
00426   postStateCompletion();
00427   }
00428 };
00429   
00430 #endif //TGT_HAS_LEGS
00431 
00432 #else // not TGT_HAS_ARMS
00433 #include "Crew/PilotNode.h"
00434 
00435 class WalkForward : public PilotNode {
00436  public:
00437   WalkForward(const std::string &nodename, float _xdist=0) : PilotNode(nodename,PilotTypes::walk), xdist(_xdist) {}
00438   float xdist;  // cache the constructor's parameter
00439   virtual void preStart() {
00440   PilotNode::preStart();
00441   pilotreq.dx = xdist;
00442   }
00443 };
00444 
00445 class Turn : public PilotNode {
00446  public:
00447   Turn(const std::string &nodename, float _angle=0) : PilotNode(nodename,PilotTypes::walk), angle(_angle) {}
00448   float angle;  // cache the constructor's parameter
00449   virtual void preStart() {
00450   PilotNode::preStart();
00451   pilotreq.da = angle;
00452   }
00453 };
00454 
00455 #endif  //not TGT_HAS_ARMS
00456 
00457 #endif

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