00001 /*!@file Devices/rt100.H Interface to a UMI rt-100 robot arm */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Lior Elazary <elazary@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Devices/rt100.H $ 00035 // $Id: rt100.H 7833 2007-02-01 23:01:39Z rjpeters $ 00036 // 00037 00038 #ifndef RT100_H_DEFINED 00039 #define RT100_H_DEFINED 00040 00041 #include "Component/ModelComponent.H" 00042 #include "Component/ModelParam.H" 00043 #include "Util/Types.H" // for byte 00044 #include "Util/Assert.H" 00045 #include <vector> 00046 00047 class Serial; 00048 00049 //! Interface to a serial-servo-controller 00050 class RT100 : public ModelComponent 00051 { 00052 public: 00053 00054 static const int RT100_OK = 0; 00055 static const int RT100_FAIL = 1; 00056 static const unsigned char EMERGENCY_STOP = 0x24; 00057 00058 enum MOTOR_STATUS {TASK_IN_PROGRESS = 0, //task still in progress? 00059 TASK_COMPLETE = 1, //task complete? 00060 ERROR_LIMIT_EXCEEDED = 2, 00061 NO_MOVEMENT = 3, 00062 MODE_ABSOLUTE_RELATIVE = 4, 00063 MODE_POSITION_FORCE = 5 00064 }; 00065 00066 00067 enum IP {IP0=0, IP1=1}; 00068 enum PARAM {CP_ERROR, CURRENT_POSITION, ERROR_LIMIT, NEW_POSITION, SPEED, KP, KI, KD, 00069 DEAD_BAND, OFFSET, MAX_FORCE, CURRENT_FORCE, ACCELERATION_TIME, USER_RAM, 00070 USER_IO, ACTUAL_POSITION }; 00071 enum IP0MOTORS {IP0BASE1, IP0BASE2, IP0WRIST1, IP0WRIST2, IP0SENSOR}; 00072 enum IP1MOTORS {IP1ELBOW, IP1SHOLDER, IP1ZED, IP1YAW, IP1GRIPPER}; 00073 enum JOINTS {BASE1, BASE2, WRIST1, WRIST2, ROLL_WRIST, TILT_WRIST, 00074 SENSOR, ELBOW, SHOLDER, ZED, YAW, GRIPPER}; 00075 static const unsigned int NUM_JOINTS = 12; //increment if JOINTS are changed 00076 00077 enum MOTORS_TOGGLES {FORCE_POSITION, ABSOLUTE_RELATIVE, USER_INPUTOUTPUT}; 00078 enum MOTORES_STOP {DEAD_STOP, RAMP_STOP, 00079 FREE_STOP, //disables PWM output 00080 FREE_OFF}; //enable PWM output 00081 00082 //! Default constructor; see ModelComponent.H 00083 RT100(OptionManager& mgr, 00084 const std::string& descrName = "UMI RT100 Robot Arm Controller", 00085 const std::string& tagName = "RT100Controller", 00086 const char *defdev = "/dev/ttyS0"); 00087 00088 //! Destructor 00089 ~RT100(); 00090 00091 //! initalize the arm and set default values; 00092 int init(); 00093 00094 //! shutdown the arm and switch off all motors 00095 int shutdown(); 00096 00097 //! get the number of joints 00098 int getNumJoints(); 00099 00100 //! set the joint position, if immediate is true, then initiate a move command 00101 int setJointPosition(JOINTS joint, short int position, bool immediate = false); 00102 00103 //! get the current joints position 00104 int getJointPosition(JOINTS joint, short int *position); 00105 00106 //! set the joint parameter 00107 int setJointParam(JOINTS joint, PARAM param, short int val); 00108 00109 //! move the arm to the new position 00110 int moveArm(bool waitUntilComplete = false); 00111 00112 //! return if the move arm completed 00113 bool moveComplete(); 00114 00115 //! move the arm in interpolation mode 00116 int interpolationMove(std::vector<short int> &moveVals); 00117 00118 //! deferred write param to a particuler ctrl (done in 2 transactions) 00119 int deferredWrite(IP ipID, unsigned int ctrl, PARAM param,short int val); 00120 00121 //! deferred read param from a particuler ctrl (done in 2 transactions) 00122 int deferredRead(IP ipID, unsigned int ctrl, PARAM param,short int *val); 00123 00124 //! immediate read param from a particuler ctrl (done in 1 transactions) 00125 int immediateRead(IP ipID, unsigned int ctrl, PARAM param, short int *val); 00126 00127 //! immediate write param to a particuler ctrl (done in 1 transactions) 00128 int immediateWrite(IP ipID, unsigned int ctrl, PARAM param,short int val); 00129 00130 //! send raw commands to the arm (one byte command) 00131 int rawCommand(IP ip, unsigned char cmdType, 00132 unsigned char *resCode, short int *results = NULL); 00133 00134 //! send raw commands to the arm (one byte command) 00135 int rawCommand(IP ipID, unsigned char cmdType, 00136 unsigned char *resCode, 00137 unsigned char *byte1, 00138 unsigned char *byte2); 00139 00140 //! send raw commands to the arm (three byte command) 00141 int rawCommand(IP ip, unsigned char cmdType, 00142 unsigned char byte1, unsigned char byte2, 00143 unsigned char *resCode); 00144 00145 00146 //! initalize zed to home position and reset counters 00147 void initZed(); 00148 00149 //! initalize gripper to home position and reset counters 00150 void initGripper(); 00151 00152 //! initalize wrist to home position and reset counters 00153 void initWrist(); 00154 00155 //! initalize sholder to home position and reset counters 00156 void initSholder(); 00157 00158 //! initalize elbow and yaw to home position and reset counters 00159 void initElbowYaw(); 00160 00161 //! move the arm to home position 00162 void gotoHomePosition(); 00163 00164 00165 protected: 00166 nub::soft_ref<Serial> itsPort; //!< Serial port to use 00167 int switchIP(IP ipID); //switch to a diffrent ip 00168 00169 private: 00170 int itsWristTiltVal; //keep the tilt and rool value for calculating wrist position 00171 int itsWristRollVal; 00172 00173 }; 00174 00175 #endif 00176 00177 // ###################################################################### 00178 /* So things look consistent in everyone's emacs... */ 00179 /* Local Variables: */ 00180 /* indent-tabs-mode: nil */ 00181 /* End: */