00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef ARP2ARM_H
00028 #define ARP2ARM_H
00029
00030 #include "ArRobot.h"
00031 #include "ariaTypedefs.h"
00032 #include "ArSerialConnection.h"
00033 #include "ariaOSDef.h"
00034
00035
00036
00038 class P2ArmJoint
00039 {
00040 public:
00041
00042 P2ArmJoint();
00043 virtual ~P2ArmJoint();
00044
00045 ArTypes::UByte myPos;
00046 ArTypes::UByte myVel;
00047 ArTypes::UByte myHome;
00048 ArTypes::UByte myMin;
00049 ArTypes::UByte myCenter;
00050 ArTypes::UByte myMax;
00051 ArTypes::UByte myTicksPer90;
00052 };
00053
00073
00074 class ArP2Arm
00075 {
00076 public:
00077
00079 typedef enum {
00080 SUCCESS,
00081 ALREADY_INITED,
00082 NOT_INITED,
00083 ROBOT_NOT_SETUP,
00084 NO_ARM_FOUND,
00085 COMM_FAILED,
00086 COULD_NOT_OPEN_PORT,
00087 COULD_NOT_SET_UP_PORT,
00088 ALREADY_CONNECTED,
00089 NOT_CONNECTED,
00090 INVALID_JOINT,
00091 INVALID_POSITION
00092 } State;
00093
00095 typedef enum {
00096 StatusPacket,
00097 InfoPacket
00098 } PacketType;
00099
00101 typedef enum
00102 {
00103 StatusOff=0,
00104 StatusSingle=1,
00105 StatusContinuous=2
00106 } StatusType;
00107
00109 static const int ArmJoint1;
00111 static const int ArmJoint2;
00113 static const int ArmJoint3;
00115 static const int ArmJoint4;
00117 static const int ArmJoint5;
00119 static const int ArmJoint6;
00121 static const int ArmGood;
00123 static const int ArmInited;
00125 static const int ArmPower;
00127 static const int ArmHoming;
00129 static int NumJoints;
00130
00132 ArP2Arm();
00133
00135 virtual ~ArP2Arm();
00136
00138 void setRobot(ArRobot *robot) {myRobot=robot;}
00139
00141 virtual State init();
00142
00144 virtual State uninit();
00145
00147 virtual State powerOn(bool doWait=true);
00148
00150 virtual State powerOff();
00151
00153 virtual State requestInfo();
00154
00156 virtual State requestStatus(StatusType status);
00157
00159 virtual State requestInit();
00160
00162 virtual State checkArm(bool waitForResponse=true);
00163
00165 virtual State home(int joint=-1);
00166
00168 virtual State park();
00169
00171 virtual State moveTo(int joint, float pos, unsigned char vel=0);
00172
00174 virtual State moveToTicks(int joint, unsigned char pos);
00175
00177 virtual State moveStep(int joint, float pos, unsigned char vel=0);
00178
00180 virtual State moveStepTicks(int joint, signed char pos);
00181
00183 virtual State moveVel(int joint, int vel);
00184
00186 virtual State stop();
00187
00189 virtual State setAutoParkTimer(int waitSecs);
00190
00192 virtual State setGripperParkTimer(int waitSecs);
00193
00195 virtual void setStoppedCB(ArFunctor *func) {myStoppedCB=func;}
00196
00198 virtual void setPacketCB(ArFunctor1<PacketType> *func)
00199 {myPacketCB=func;}
00200
00202 virtual std::string getArmVersion() {return(myVersion);}
00203
00205 virtual float getJointPos(int joint);
00206
00208 virtual unsigned char getJointPosTicks(int joint);
00209
00211 virtual bool getMoving(int joint=-1);
00212
00214 virtual bool isPowered();
00215
00217 virtual bool isGood();
00218
00220 virtual int getStatus() {return(myStatus);}
00221
00223 virtual ArTime getLastStatusTime() {return(myLastStatusTime);}
00224
00226 virtual ArRobot * getRobot() {return(myRobot);}
00227
00229 virtual P2ArmJoint * getJoint(int joint);
00230
00232 virtual bool convertDegToTicks(int joint, float pos,
00233 unsigned char *ticks);
00234
00236 virtual bool convertTicksToDeg(int joint, unsigned char pos,
00237 float *degrees);
00238
00239
00240 protected:
00241
00242
00243 static const unsigned int ARMpac;
00244 static const unsigned int ARMINFOpac;
00245 static const unsigned char ComArmInfo;
00246 static const unsigned char ComArmStats;
00247 static const unsigned char ComArmInit;
00248 static const unsigned char ComArmCheckArm;
00249 static const unsigned char ComArmPower;
00250 static const unsigned char ComArmHome;
00251 static const unsigned char ComArmPark;
00252 static const unsigned char ComArmPos;
00253 static const unsigned char ComArmSpeed;
00254 static const unsigned char ComArmStop;
00255 static const unsigned char ComArmAutoPark;
00256 static const unsigned char ComArmGripperPark;
00257
00258 bool comArmInfo();
00259 bool comArmStats(StatusType stats=StatusSingle);
00260 bool comArmInit();
00261 bool comArmCheckArm();
00262 bool comArmPower(bool on);
00263 bool comArmHome(unsigned char joint=0xff);
00264 bool comArmPark();
00265 bool comArmPos(unsigned char joint, unsigned char pos);
00266 bool comArmSpeed(unsigned char joint, unsigned char speed);
00267 bool comArmStop(unsigned char joint=0xff);
00268 bool comArmAutoPark(int waitSecs);
00269 bool comArmGripperPark(int waitSecs);
00270
00271 bool armPacketHandler(ArRobotPacket *packet);
00272
00273 bool myInited;
00274 ArRobot *myRobot;
00275
00276 ArTime myLastStatusTime;
00277 ArTime myLastInfoTime;
00278 std::string myVersion;
00279 StatusType myStatusRequest;
00280 ArTypes::UByte2 myLastStatus;
00281 ArTypes::UByte2 myStatus;
00282 ArSerialConnection myCon;
00283 ArRetFunctorC<State, ArP2Arm> myAriaUninitCB;
00284 ArRetFunctor1C<bool, ArP2Arm, ArRobotPacket*> myArmPacketHandler;
00285 ArFunctor1<PacketType> *myPacketCB;
00286 ArFunctor *myStoppedCB;
00287
00288
00289
00290 P2ArmJoint myJoints[6];
00291 };
00292
00293 #endif // _ARP2ARM_H