00001 #ifndef Included_MotionNodes_h_
00002 #define Included_MotionNodes_h_
00003
00004 #include "Crew/PilotNode.h"
00005 #include "Behaviors/Nodes/HeadPointerNode.h"
00006 #include "Behaviors/Nodes/PIDNode.h"
00007 #include "Behaviors/Nodes/PostureNode.h"
00008 #include "Behaviors/Nodes/PostMachine.h"
00009 #include "Behaviors/Transitions/CompletionTrans.h"
00010 #include "Behaviors/Transitions/TimeOutTrans.h"
00011
00012 class WalkForward : public PilotNode {
00013 public:
00014 WalkForward(const std::string &nodename, float _xdist=0) : PilotNode(nodename,PilotTypes::walk), xdist(_xdist) {}
00015 float xdist;
00016 virtual void preStart() {
00017 PilotNode::preStart();
00018 pilotreq.dx = xdist;
00019 }
00020 };
00021
00022 class WalkSideways : public PilotNode {
00023 public:
00024 WalkSideways(const std::string &nodename, float _ydist=0) : PilotNode(nodename,PilotTypes::walk), ydist(_ydist) {}
00025 float ydist;
00026 virtual void preStart() {
00027 PilotNode::preStart();
00028 pilotreq.dy = ydist;
00029 }
00030 };
00031
00032 class Turn : public PilotNode {
00033 public:
00034 Turn(const std::string &nodename, float _angle=0) : PilotNode(nodename,PilotTypes::walk), angle(_angle) {}
00035 float angle;
00036 virtual void preStart() {
00037 PilotNode::preStart();
00038 pilotreq.da = angle;
00039 }
00040 };
00041
00042 #ifdef TGT_HAS_ARMS
00043 class ArmPower : public PIDNode {
00044 public:
00045 ArmPower(const std::string &nodename, float _level) : PIDNode(nodename,ArmOffset,ArmOffset+NumArmJoints,_level), level(_level) {}
00046 float level;
00047 };
00048
00049 class ResetArm : public StateNode {
00050 public:
00051 ResetArm(const std::string &nodename="ResetArm") : StateNode(nodename) {}
00052 virtual void setup() {
00053 ArmPower *armpower1 = new ArmPower("armpower1",0.0);
00054 addNode(armpower1);
00055
00056 ArmPower *armpower2 = new ArmPower("armpower2",1.0);
00057 addNode(armpower2);
00058
00059 PostMachineCompletion *postmachinecompletion1 = new PostMachineCompletion("postmachinecompletion1");
00060 addNode(postmachinecompletion1);
00061
00062 startnode = armpower1;
00063
00064 armpower1->addTransition(new TimeOutTrans("timeouttrans1",armpower2,500));
00065 armpower2->addTransition(new NullTrans("nulltrans1",postmachinecompletion1));
00066 }
00067 };
00068 #else
00069 class ArmPower : public StateNode {
00070 public:
00071 ArmPower(const std::string &nodename, float _level) : StateNode(nodename), level(_level) {}
00072 float level;
00073 };
00074 class ResetArm : public StateNode {
00075 public:
00076 ResetArm(const std::string &nodename="ResetArm") : StateNode(nodename) {}
00077 };
00078 #endif
00079
00080
00081
00082 #if defined(TGT_IS_CALLIOPE2) || defined(TGT_IS_CALLIOPE3)
00083 class GripperPower : public PIDNode {
00084 public:
00085 GripperPower(const std::string &nodename, float _level) : PIDNode(nodename,GripperOffset,GripperOffset+1,_level), level(_level) {}
00086 float level;
00087 };
00088 #elif defined(TGT_IS_CALLIOPE5)
00089 class GripperPower : public PIDNode {
00090 public:
00091 GripperPower(const std::string &nodename, float _level) : PIDNode(nodename,LeftFingerOffset,RightFingerOffset+1,_level), level(_level) {}
00092 float level;
00093 };
00094 #else
00095 class GripperPower : public PostStateCompletion {
00096 public:
00097 GripperPower(const std::string &nodename, float _level) : PostStateCompletion(nodename), level(_level) {}
00098 float level;
00099 };
00100 #endif
00101
00102 class ResetGripper : public StateNode {
00103 public:
00104 ResetGripper(const std::string &nodename="ResetGripper") : StateNode(nodename) {}
00105 #if defined(TGT_IS_CALLIOPE2) || defined(TGT_IS_CALLIOPE3) || defined(TGT_IS_CALLIOPE5)
00106 virtual void setup() {
00107 GripperPower *gripperpower1 = new GripperPower("gripperpower1",0.0);
00108 addNode(gripperpower1);
00109
00110 GripperPower *gripperpower2 = new GripperPower("gripperpower2",1.0);
00111 addNode(gripperpower2);
00112
00113 PostMachineCompletion *postmachinecompletion2 = new PostMachineCompletion("postmachinecompletion2");
00114 addNode(postmachinecompletion2);
00115
00116 startnode = gripperpower1;
00117
00118 gripperpower1->addTransition(new TimeOutTrans("timeouttrans2",gripperpower2,500));
00119 gripperpower2->addTransition(new CompletionTrans("completiontrans1",postmachinecompletion2));
00120 }
00121 #endif
00122 };
00123
00124 #ifdef TGT_HAS_GRIPPER
00125 class OpenGripper : public ArmNode {
00126 public:
00127 OpenGripper(const std::string &nodename="OpenGripper", float _percentage=0.5) : ArmNode(nodename), percentage(_percentage) {}
00128 float percentage;
00129 virtual void start() {
00130 ArmNode::start();
00131 #if defined(TGT_IS_CALLIOPE) || defined(TGT_IS_CALLIOPE3)
00132 getMC()->setMaxSpeed(0.2);
00133 getMC()->openGripper(percentage);
00134 #endif
00135 }
00136 };
00137 #else
00138 class OpenGripper : public PostStateCompletion {
00139 public:
00140 OpenGripper(const std::string &nodename="OpenGripper", float _percentage=0.5) : PostStateCompletion(nodename), percentage(_percentage) {}
00141 float percentage;
00142 };
00143 #endif
00144
00145 #if defined(TGT_IS_CALLIOPE2) || defined(TGT_IS_CALLIOPE3) || defined(TGT_IS_CALLIOPE5)
00146 class ParkArm : public StateNode {
00147 public:
00148 ParkArm(const std::string &nodename="ParkArm") : StateNode(nodename) {}
00149 virtual void setup() {
00150 PostureNode *posturenode1 = new PostureNode("posturenode1","park1.pos");
00151 addNode(posturenode1);
00152
00153 PostureNode *posturenode2 = new PostureNode("posturenode2","park2.pos");
00154 addNode(posturenode2);
00155
00156 ArmPower *armpower3 = new ArmPower("armpower3",0.0);
00157 addNode(armpower3);
00158
00159 PostMachineCompletion *postmachinecompletion3 = new PostMachineCompletion("postmachinecompletion3");
00160 addNode(postmachinecompletion3);
00161
00162 startnode = posturenode1;
00163
00164 posturenode1->addTransition(new CompletionTrans("completiontrans2",posturenode2));
00165 posturenode2->addTransition(new CompletionTrans("completiontrans3",armpower3));
00166 armpower3->addTransition(new CompletionTrans("completiontrans4",postmachinecompletion3));
00167 }
00168 };
00169 #else
00170 class ParkArm : public PostStateCompletion {
00171 public:
00172 ParkArm(const std::string &nodename="ParkArm") : PostStateCompletion(nodename) {}
00173 };
00174 #endif
00175
00176
00177 #if defined(TGT_HAS_HEAD) && defined(TGT_HAS_GRIPPER)
00178 class LookAtGripper : public HeadPointerNode {
00179 public:
00180 LookAtGripper(const std::string &nodename, float _xoffset=0) : HeadPointerNode(nodename), xoffset(_xoffset) {}
00181 float xoffset;
00182 virtual void preStart() {
00183 HeadPointerNode::preStart();
00184 fmat::Column<3> gripperPos = kine->linkToBase(GripperFrameOffset).translation();
00185 getMC()->lookAtPoint(gripperPos[0]+xoffset, gripperPos[1], gripperPos[2]);
00186 }
00187 };
00188 #else
00189 class LookAtGripper : public PostStateCompletion {
00190 public:
00191 LookAtGripper(const std::string &nodename, float _xoffset=0) : PostStateCompletion(nodename), xoffset(_xoffset) {}
00192 float xoffset;
00193 };
00194 #endif
00195
00196 #endif