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 HandEyeGripper GripperControl;
00044 KinematicJoint* gripperFrameKJ;
00045 KinematicJoint* KJjoints[NumArmJoints];
00046 float horScale, verScale;
00047
00048 enum DisplayMode_t {
00049 pitchAndYaw = 0,
00050 yawOnly,
00051 pitchOnly
00052 } displayMode;
00053
00054
00055 static const char CMD_unrelax = 'u';
00056 static const char CMD_relax = 'v';
00057 static const char CMD_gripper = 'w';
00058 static const char CMD_point = 'x';
00059 static const char CMD_speed = 'y';
00060 static const char CMD_connect = 'z';
00061
00062 float theta;
00063 float verZ;
00064 fmat::Column<3> horToBase;
00065 fmat::Column<3> verToBase;
00066 float speed;
00067 unsigned int OriJoint;
00068 int linksToDisplay;
00069
00070
00071 char armConfig[NumArmJoints];
00072 float qOffset[NumArmJoints];
00073 float yawCoords[NumArmJoints][2];
00074 float pitchCoords[NumArmJoints][2];
00075 int numYawJoints;
00076 int numPitchJoints;
00077
00078
00079
00080
00081
00082
00083 ArmController *theLastOne;
00084
00085
00086 Socket *cmdsock;
00087
00088
00089 void runCommand(unsigned char *command);
00090 void doEvent();
00091
00092 void cmdConnect();
00093
00094
00095 void cmdPointPicker(float param, float param2, float param3, int cmdno);
00096 void cmdGripper(float param, int cmdno);
00097 void cmdRelax();
00098 void cmdUnrelax();
00099 void setJoint(unsigned int joint, float param);
00100
00101 ArmController(const ArmController&);
00102 ArmController operator=(const ArmController&);
00103
00104 public:
00105
00106 ArmController() : BehaviorBase("ArmController"),
00107 arm_id(MotionManager::invalid_MC_ID), pidMCID(MotionManager::invalid_MC_ID),
00108 GripperControl(), gripperFrameKJ(NULL), KJjoints(),
00109 horScale(0), verScale(0), displayMode(), theta(0), verZ(0),
00110 horToBase(), verToBase(), speed(0.4f), OriJoint(),
00111 linksToDisplay(0), yawCoords(), pitchCoords(), numYawJoints(0), numPitchJoints(0),
00112 theLastOne(theOne),
00113 cmdsock(NULL)
00114 {
00115 for(unsigned int i =0; i < (NumArmJoints+1); i++)
00116 armConfig[i] = '\0';
00117 gripperFrameKJ = kine->getKinematicJoint(GripperFrameOffset)->cloneBranch();
00118 }
00119
00120
00121 virtual ~ArmController() {
00122 theOne = theLastOne;
00123 delete gripperFrameKJ;
00124 gripperFrameKJ=NULL;
00125 }
00126
00127
00128 virtual void doStart();
00129
00130 virtual void doStop();
00131
00132 void computeCoords();
00133 void sendCoords();
00134
00135 static std::string getClassDescription() {
00136 char tmp[20];
00137 sprintf(tmp,"%d",*config->main.armControl_port);
00138 return std::string("Listens to arm control commands coming in from port ")+tmp;
00139 }
00140 virtual std::string getDescription() const { return getClassDescription(); }
00141 };
00142
00143
00144
00145
00146
00147
00148 #endif