KatanaNativeInterface  $VERSION$
kmlExt.h
Go to the documentation of this file.
00001 /*
00002  *   Katana Native Interface - A C++ interface to the robot arm Katana.
00003  *   Copyright (C) 2005 Neuronics AG
00004  *   Check out the AUTHORS file for detailed contact information.
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 
00021 
00022 /******************************************************************************************************************/
00023 #ifndef _KMLEXT_H_
00024 #define _KMLEXT_H_
00025 /******************************************************************************************************************/
00026 #include "common/dllexport.h"
00027 #include "common/exception.h"
00028 
00029 #include "KNI/kmlBase.h"
00030 #include "KNI/kmlMotBase.h"
00031 
00032 #include <vector>
00033 
00034 
00035 /******************************************************************************************************************/
00036 
00041 
00045 class ConfigFileOpenException : public Exception {
00046 public:
00047         ConfigFileOpenException(const std::string & port) throw ():
00048                 Exception("Cannot open configuration file '" + port + "'", -40) {}
00049 };
00050 
00054 
00055 namespace KNI {
00056     class kmlFactory; 
00057 }
00058 
00064 class DLLDIR CKatana {
00065 protected:
00066         //-------------------------------------//
00067         CKatBase*       base;   
00068 
00069         bool _gripperIsPresent;
00070         int  _gripperOpenEncoders;
00071         int  _gripperCloseEncoders;
00073         int mKatanaType;
00074 
00077         void setTolerance(long idx, int enc_tolerance);
00078 
00079 public:
00080         //-------------------------------------//
00081         CKatBase* GetBase()        { return base; } 
00082 
00086         CKatana()  { base = new CKatBase; }
00089         ~CKatana() { delete base; }
00090         //------------------------------------------------------------------------------//
00093         void create(const char* configurationFile, CCplBase* protocol);
00094         void create(KNI::kmlFactory* infos,  CCplBase* protocol);
00095         
00098         void create(TKatGNL& gnl,               
00099                                 TKatMOT& mot,   
00100                                 TKatSCT& sct,   
00101                                 TKatEFF& eff,   
00102                                 CCplBase* protocol      
00103                                 );
00104         //------------------------------------------------------------------------------//
00105 
00106 
00107         /* \brief calibrates the robot
00108          */
00109         void calibrate();
00110 
00111         void calibrate( long idx,       
00112                         TMotCLB clb,    
00113                         TMotSCP scp,    
00114                         TMotDYL dyl     
00115         );
00116 
00117         //------------------------------------------------------------------------------//
00118 
00119         void searchMechStop(long idx,           
00120                             TSearchDir dir,     
00121                             TMotSCP    scp,     
00122                             TMotDYL    dyl      
00123         );
00124 
00125 
00126         //------------------------------------------------------------------------------//
00129         void inc(long idx, int dif, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
00132         void dec(long idx, int dif, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
00136         void mov(long idx, int tar, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
00137 
00138         //------------------------------------------------------------------------------//
00141         void incDegrees(long idx, double dif, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
00144         void decDegrees(long idx, double dif, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
00148         void movDegrees(long idx, double tar, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
00149 
00150         //------------------------------------------------------------------------------//
00151 
00152 
00158         void setTPSP(long idx, int tar);
00163         void resetTPSP();
00168         void sendTPSP(bool wait = false, long timeout = TM_ENDLESS);
00174         void setTPSPDegrees(long idx, double tar);
00175 
00176         //------------------------------------------------------------------------------//
00177         // public just for dubbuging purposes
00181         bool checkENLD(long idx, double degrees);
00182 
00183         //------------------------------------------------------------------------------//
00184         
00188         void setGripperParameters(bool isPresent, int openEncoders, int closeEncoders);
00189 
00190         //------------------------------------------------------------------------------//
00191 
00194         void enableCrashLimits();
00197         void disableCrashLimits();
00200         void unBlock();
00203         void setCrashLimit(long idx, int limit);
00206         void setPositionCollisionLimit(long idx, int limit);
00209         void setSpeedCollisionLimit(long idx, int limit);
00210 
00211         //------------------------------------------------------------------------------//
00212 
00213         short getNumberOfMotors() const;
00214         int getMotorEncoders(short number, bool refreshEncoders = true) const;
00215 
00219         std::vector<int>::iterator getRobotEncoders(std::vector<int>::iterator start, std::vector<int>::const_iterator end, bool refreshEncoders = true) const;
00220 
00224         std::vector<int> getRobotEncoders(bool refreshEncoders = true) const;
00225 
00226         short getMotorVelocityLimit( short number ) const;
00227         short getMotorAccelerationLimit( short number ) const;
00228 
00229         void setMotorVelocityLimit( short number, short velocity );
00230         void setMotorAccelerationLimit( short number, short acceleration );
00231 
00232         void setRobotVelocityLimit( short velocity );
00235         void setRobotAccelerationLimit( short acceleration );
00236 
00237         void moveMotorByEnc( short number, int encoders,       bool waitUntilReached = false, int waitTimeout = 0);
00238         void moveMotorBy   ( short number, double radianAngle, bool waitUntilReached = false, int waitTimeout = 0);
00239         
00240         void moveMotorToEnc( short number, int encoders,       bool waitUntilReached = false, int encTolerance = 100, int waitTimeout = 0);
00241         void moveMotorTo   ( short number, double radianAngle, bool waitUntilReached = false, int waitTimeout = 0);
00242 
00243         void waitForMotor( short number, int encoders, int encTolerance = 100, short mode = 0, int waitTimeout = 5000);
00244 
00248         void moveRobotToEnc(std::vector<int>::const_iterator start, std::vector<int>::const_iterator end, bool waitUntilReached = false, int encTolerance = 100, int waitTimeout = 0);
00252         void moveRobotToEnc(std::vector<int> encoders, bool waitUntilReached = false, int encTolerance = 100, int waitTimeout = 0);
00254         void moveRobotToEnc4D(std::vector<int> target, int velocity=180, int acceleration = 1, int encTolerance = 100);
00255 
00256         void openGripper (bool waitUntilReached = false, int waitTimeout = 100);
00257         void closeGripper(bool waitUntilReached = false, int waitTimeout = 100);
00258 
00259         void freezeRobot();
00260         void freezeMotor(short number);
00261         void switchRobotOn();
00262         void switchRobotOff();
00263         void switchMotorOn(short number);
00264         void switchMotorOff(short number);
00265 
00269     void startSplineMovement(bool exactflag, int moreflag = 1);
00270 
00273     void startFourSplinesMovement(bool exactflag);
00274 
00278     void sendSplineToMotor(unsigned short number, short targetPosition, short duration, short p1, short p2, short p3, short p4);
00279 
00284         void sendFourSplinesToMotor(unsigned short number, short targetPosition, short duration, std::vector<short>& coefficients);
00285         void sendFourSplinesToMotor(unsigned short number, short targetPosition, short duration, short p01, short p11, short p21, short p31, short p02, short p12, short p22, short p32,short p03, short p13, short p23, short p33,short p04, short p14, short p24, short p34);
00286 };
00287 
00288 /******************************************************************************************************************/
00289 #endif //_KMLEXT_H_
00290 /******************************************************************************************************************/