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/PlanarThreeLinkArm.h"
00013 #include "Motion/HandEyeGripper.h"
00014 #include "Motion/PIDMC.h"
00015 #include "IPC/SharedObject.h"
00016 #include "Events/EventRouter.h"
00017 #include "Motion/KinematicJoint.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
00037 static ArmController * theOne;
00038 static int mechacmd_callback(char *buf, int bytes);
00039
00040 protected:
00041 MotionManager::MC_ID arm_id;
00042 MotionManager::MC_ID pidMCID;
00043 KinematicJoint* gripperFrameKJ;
00044 KinematicJoint* KJjoints[NumArmJoints];
00045 float horScale, verScale;
00046
00047 enum DisplayMode_t {
00048 pitchAndYaw = 0,
00049 yawOnly,
00050 pitchOnly
00051 } displayMode;
00052
00053
00054 static const char cmdUnrelax = 'u';
00055 static const char cmdRelax = 'v';
00056 static const char cmdGripper = 'w';
00057 static const char cmdPoint = 'x';
00058 static const char cmdSpeed = 'y';
00059 static const char cmdConnect = 'z';
00060 static const char cmdOrientation = 'o';
00061
00062
00063
00064 float theta;
00065
00066
00067
00068 float z;
00069
00070
00071 fmat::Column<3> horToBase;
00072
00073
00074 fmat::Column<3> verToBase;
00075
00076
00077 float speed;
00078
00079
00080 fmat::Quaternion orientation[2];
00081
00082
00083 int orientationIndex;
00084
00085
00086 unsigned int numYawJoints;
00087
00088
00089 unsigned int numPitchJoints;
00090
00091
00092 unsigned int linksToDisplay;
00093
00094
00095 char armConfig[NumArmJoints];
00096 float yawCoords[NumArmJoints][2];
00097 float pitchCoords[NumArmJoints][2];
00098
00099
00100
00101
00102
00103
00104 ArmController *theLastOne;
00105
00106
00107 Socket *cmdsock;
00108
00109
00110 void runCommand(unsigned char *command);
00111 void doEvent();
00112
00113
00114 void connect();
00115 void pointPicked(float param, float param2, float param3, int cmdno);
00116 void gripper(float param, int cmdno);
00117 void relax();
00118 void unrelax();
00119 void setOrientation(int index);
00120 void setJoint(unsigned int joint, float param);
00121
00122 ArmController(const ArmController&);
00123 ArmController operator=(const ArmController&);
00124
00125 public:
00126
00127 ArmController() : BehaviorBase("ArmController"),
00128 arm_id(MotionManager::invalid_MC_ID),
00129 pidMCID(MotionManager::invalid_MC_ID),
00130 gripperFrameKJ(NULL),
00131 KJjoints(),
00132 horScale(0),
00133 verScale(0),
00134 displayMode(),
00135 theta(0),
00136 z(0),
00137 horToBase(),
00138 verToBase(),
00139 speed(0.4f),
00140 orientation(),
00141 orientationIndex(0),
00142 numYawJoints(0),
00143 numPitchJoints(0),
00144 linksToDisplay(0),
00145 yawCoords(),
00146 pitchCoords(),
00147 theLastOne(theOne),
00148 cmdsock(NULL) {
00149 for(unsigned int i =0; i < (NumArmJoints+1); i++)
00150 armConfig[i] = '\0';
00151 gripperFrameKJ = kine->getKinematicJoint(GripperFrameOffset)->cloneBranch();
00152
00153 orientation[0] = fmat::Quaternion();
00154 orientation[1] = fmat::Quaternion::fromMatrix(fmat::rotationY(-M_PI_2));
00155 }
00156
00157
00158 virtual ~ArmController() {
00159 theOne = theLastOne;
00160 delete gripperFrameKJ;
00161 gripperFrameKJ = NULL;
00162 }
00163
00164
00165 virtual void doStart();
00166
00167 virtual void doStop();
00168
00169 void computeCoords();
00170 void sendCoords();
00171
00172 static std::string getClassDescription() {
00173 char tmp[20];
00174 sprintf(tmp,"%d",*config->main.armControl_port);
00175 return std::string("Listens to arm control commands coming in from port ")+tmp;
00176 }
00177
00178 virtual std::string getDescription() const { return getClassDescription(); }
00179 };
00180
00181
00182
00183
00184
00185
00186 #endif