Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ArP2Arm.h

00001 /*
00002 ActivMedia Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004,2005 ActivMedia Robotics, LLC
00004 
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 ActivMedia Robotics for information about a commercial version of ARIA at 
00022 robots@activmedia.com or 
00023 ActivMedia Robotics, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
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 // P2 Arm classes: ArP2Arm for control and ArP2ArmJoints for P2 Arm joint data
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   // AROS/P2OS parameters
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   //  ArmP2Model myModel;
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   // We have 6 joints. Including the gripper. It's here so that we can
00289   // store its position even though its not really a joint.
00290   P2ArmJoint myJoints[6];
00291 };
00292 
00293 #endif // _ARP2ARM_H

Generated on Wed Oct 19 12:56:36 2005 for Aria by  doxygen 1.4.0