ArmController.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_ArmController_h_
00003 #define INCLUDED_ArmController_h_
00004
00005 #include <iostream>
00006 #include "Wireless/Wireless.h"
00007 #include "Behaviors/BehaviorBase.h"
00008 #include "Motion/MotionManager.h"
00009 #include "Events/EventRouter.h"
00010 #include "Events/EventBase.h"
00011 #include "Shared/Config.h"
00012 #include "Motion/PIDMC.h"
00013 #include "Motion/MotionSequenceMC.h"
00014 #include "IPC/SharedObject.h"
00015 #include "Events/EventRouter.h"
00016 #include "Motion/KinematicJoint.h"
00017 #include "Shared/TimeET.h"
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 class ArmController : public BehaviorBase {
00032
00033 public:
00034
00035
00036 static ArmController * theOne;
00037 static int mechacmd_callback(char *buf, int bytes);
00038
00039 protected:
00040
00041 MotionManager::MC_ID armMCID;
00042
00043
00044 MotionManager::MC_ID pidMCID;
00045
00046
00047 MotionManager::MC_ID seqMCID;
00048
00049
00050 KinematicJoint* gripperFrameKJ;
00051
00052
00053 KinematicJoint* successJ;
00054
00055
00056 KinematicJoint* KJjoints[NumArmJoints];
00057
00058
00059 float horScale;
00060
00061
00062 float verScale;
00063
00064
00065 unsigned int numSteps;
00066
00067
00068 std::queue<fmat::Column<3> > steps;
00069
00070
00071 enum DisplayMode_t {
00072 pitchAndYaw = 0,
00073 yawOnly,
00074 pitchOnly
00075 } displayMode;
00076
00077
00078 static const char cmdUnrelax = 'u';
00079 static const char cmdRelax = 'v';
00080 static const char cmdGripper = 'w';
00081 static const char cmdPoint = 'x';
00082 static const char cmdSpeed = 'y';
00083 static const char cmdConnect = 'z';
00084 static const char cmdOrientation = 'o';
00085
00086
00087
00088 float theta;
00089
00090
00091
00092 float z;
00093
00094
00095 fmat::Column<3> horToBase;
00096
00097
00098 fmat::Column<3> verToBase;
00099
00100
00101 float speed;
00102
00103
00104 fmat::Quaternion orientation[2];
00105
00106
00107 int orientationIndex;
00108
00109
00110 unsigned int numYawJoints;
00111
00112
00113 unsigned int numPitchJoints;
00114
00115
00116 unsigned int linksToDisplay;
00117
00118
00119 TimeET reachablePointsDelay;
00120
00121
00122 char armConfig[NumArmJoints];
00123
00124
00125 float yawCoords[NumArmJoints][2];
00126
00127
00128 float pitchCoords[NumArmJoints][2];
00129
00130
00131
00132
00133
00134
00135
00136 ArmController *theLastOne;
00137
00138
00139 Socket *cmdsock;
00140
00141
00142 void runCommand(unsigned char *command);
00143 void doEvent();
00144
00145
00146 void connect();
00147 void pointPicked(float param, float param2, float param3, int cmdno);
00148 void gripper(float param, int cmdno);
00149 void relax();
00150 void unrelax();
00151 void setJoint(unsigned int joint, float param);
00152
00153 ArmController(const ArmController&);
00154 ArmController operator=(const ArmController&);
00155
00156 public:
00157
00158 ArmController() : BehaviorBase("ArmController"),
00159 armMCID(MotionManager::invalid_MC_ID),
00160 pidMCID(MotionManager::invalid_MC_ID),
00161 seqMCID(MotionManager::invalid_MC_ID),
00162 gripperFrameKJ(NULL),
00163 successJ(NULL),
00164 KJjoints(),
00165 horScale(0),
00166 verScale(0),
00167 numSteps(40),
00168 steps(),
00169 displayMode(),
00170 theta(0),
00171 z(0),
00172 horToBase(),
00173 verToBase(),
00174 speed(0.4f),
00175 orientation(),
00176 orientationIndex(0),
00177 numYawJoints(0),
00178 numPitchJoints(0),
00179 linksToDisplay(0),
00180 reachablePointsDelay(),
00181 yawCoords(),
00182 pitchCoords(),
00183 theLastOne(theOne),
00184 cmdsock(NULL) {
00185 for(unsigned int i =0; i < (NumArmJoints+1); i++)
00186 armConfig[i] = '\0';
00187 gripperFrameKJ = kine->getKinematicJoint(GripperFrameOffset)->cloneBranch();
00188 successJ = kine->getKinematicJoint(GripperFrameOffset)->cloneBranch();
00189
00190 #ifdef TGT_IS_CALLIOPE5
00191 orientation[0] = fmat::Quaternion::aboutY(M_PI_2);
00192 orientation[1] = fmat::Quaternion::aboutY(M_PI);
00193 #else
00194 orientation[0] = orientation[1] = fmat::Quaternion::IDENTITY;
00195 #endif
00196 }
00197
00198
00199 virtual ~ArmController() {
00200 theOne = theLastOne;
00201 delete gripperFrameKJ;
00202 gripperFrameKJ = NULL;
00203 }
00204
00205
00206 virtual void doStart();
00207
00208 virtual void doStop();
00209
00210
00211 void computeCoords();
00212
00213
00214 void sendCoords();
00215
00216
00217
00218
00219 void sendReachablePoints(DisplayMode_t d);
00220
00221 static std::string getClassDescription() {
00222 char tmp[20];
00223 sprintf(tmp,"%d",*config->main.armControl_port);
00224 return std::string("Listens to arm control commands coming in from port ")+tmp;
00225 }
00226
00227 virtual std::string getDescription() const { return getClassDescription(); }
00228 };
00229
00230
00231
00232
00233
00234
00235 #endif