1 /**************************************************************************** 2 * 3 * ViSP, open source Visual Servoing Platform software. 4 * Copyright (C) 2005 - 2019 by Inria. All rights reserved. 5 * 6 * This software is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * See the file LICENSE.txt at the root directory of this source 11 * distribution for additional information about the GNU GPL. 12 * 13 * For using ViSP with software that can not be combined with the GNU 14 * GPL, please contact Inria about acquiring a ViSP Professional 15 * Edition License. 16 * 17 * See http://visp.inria.fr for more information. 18 * 19 * This software was developed at: 20 * Inria Rennes - Bretagne Atlantique 21 * Campus Universitaire de Beaulieu 22 * 35042 Rennes Cedex 23 * France 24 * 25 * If you have questions regarding the use of this file, please contact 26 * Inria at visp@inria.fr 27 * 28 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 29 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 30 * 31 * Description: 32 * Interface for Kinova Jaco robot. 33 * 34 * Authors: 35 * Fabien Spindler 36 * 37 *****************************************************************************/ 38 39 #ifndef vpRobotKinova_h 40 #define vpRobotKinova_h 41 42 /*! 43 44 \file vpRobotKinova.h 45 46 Interface for Kinova robot using Jaco SDK. 47 48 */ 49 50 #include <visp3/core/vpConfig.h> 51 52 #ifdef VISP_HAVE_JACOSDK 53 54 #include <KinovaTypes.h> 55 56 #ifdef __linux__ 57 #include <dlfcn.h> 58 #include <vector> 59 #include <stdio.h> 60 #include <unistd.h> 61 #include <Kinova.API.CommLayerUbuntu.h> 62 #include <Kinova.API.UsbCommandLayerUbuntu.h> 63 #elif _WIN32 64 #include <Windows.h> 65 #include <conio.h> 66 #include <iostream> 67 #include <CommunicationLayer.h> 68 #include <CommandLayer.h> 69 #endif 70 71 #include <visp3/core/vpHomogeneousMatrix.h> 72 #include <visp3/robot/vpRobot.h> 73 74 /*! 75 76 \class vpRobotKinova 77 78 \ingroup group_robot_real_arm 79 80 Interface for Kinova Jaco2 robot. 81 82 This class is a wrapper over Kinova Jaco SDK that could be downloaded from Kinova Robotics 83 <a href="https://www.kinovarobotics.com/en/knowledge-hub/all-kinova-products">software resources</a> 84 by following the link under `Gen2 7 DoF > SDK 1.5.1`. 85 86 It allows to control Kinova Jaco2 robot Gen 2 with 7 DoF, 6 DoF and 4 DoF. 87 88 To select the degrees of freedom corresponding to your robot use setDoF(). 89 90 */ 91 class VISP_EXPORT vpRobotKinova : public vpRobot 92 { 93 public: 94 typedef enum { 95 CMD_LAYER_USB, 96 CMD_LAYER_ETHERNET, 97 CMD_LAYER_UNSET 98 } CommandLayer; 99 100 vpRobotKinova(); 101 virtual ~vpRobotKinova(); 102 103 int connect(); 104 105 void get_eJe(vpMatrix &eJe); 106 void get_fJe(vpMatrix &fJe); 107 108 /*! 109 * Return constant transformation between end-effector and tool frame. 110 * If your tool is a camera, this transformation is obtained by hand-eye calibration. 111 */ get_eMc()112 vpHomogeneousMatrix get_eMc() const { return m_eMc; } 113 getActiveDevice()114 int getActiveDevice() const { return m_active_device; } getNumDevices()115 int getNumDevices() const { return m_devices_count; } 116 void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &q); 117 void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position); 118 void getPosition(const vpRobot::vpControlFrameType frame, vpPoseVector &pose); 119 120 void homing(); 121 122 /*! 123 * Set constant transformation between end-effector and tool frame. 124 * If your tool is a camera, this transformation is obtained by hand-eye calibration. 125 */ set_eMc(vpHomogeneousMatrix & eMc)126 void set_eMc(vpHomogeneousMatrix &eMc) { m_eMc = eMc; } 127 void setActiveDevice(int device); 128 /*! 129 * Set command layer indicating if the robot is controlled throw USB or Ethernet. 130 * \param[in] command_layer : Layer used to control the robot. 131 */ setCommandLayer(CommandLayer command_layer)132 void setCommandLayer(CommandLayer command_layer) { m_command_layer = command_layer; } 133 void setDoF(unsigned int dof); 134 void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q); 135 /*! 136 * \param[in] plugin_location: Path to Jaco SDK plugins (ie. `Kinova.API.USBCommandLayerUbuntu.so` on 137 * unix-like platform or `CommandLayerWindows.dll` on Windows platform). By default this location is empty, 138 * meaning that we suppose that the plugins are located in the same folder as the binary that want to use 139 * them. 140 */ setPluginLocation(const std::string & plugin_location)141 void setPluginLocation(const std::string &plugin_location) { m_plugin_location = plugin_location; } 142 void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel); 143 /*! 144 * Enable or disable verbose mode to print to stdout additional information. 145 * \param[in] verbose : true to enable verbose, false to disable. By default verbose 146 * mode is disabled. 147 */ setVerbose(bool verbose)148 void setVerbose(bool verbose) { m_verbose = verbose; } 149 150 protected: 151 void closePlugin(); 152 void getJointPosition(vpColVector &q); 153 void init(); 154 void loadPlugin(); 155 void setCartVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &v); 156 void setJointVelocity(const vpColVector &qdot); 157 158 protected: 159 vpHomogeneousMatrix m_eMc; //!< Constant transformation between end-effector and tool (or camera) frame 160 std::string m_plugin_location; 161 bool m_verbose; 162 bool m_plugin_loaded; 163 int m_devices_count; 164 KinovaDevice *m_devices_list; 165 int m_active_device; 166 CommandLayer m_command_layer; 167 168 #ifdef __linux__ 169 void * m_command_layer_handle; //!< A handle to the API. 170 #elif _WIN32 171 HINSTANCE m_command_layer_handle; //!< A handle to the API. 172 #endif 173 174 private: 175 int (*KinovaCloseAPI)(); 176 int (*KinovaGetAngularCommand)(AngularPosition &); 177 int (*KinovaGetCartesianCommand)(CartesianPosition &); 178 int (*KinovaGetDevices)(KinovaDevice devices[MAX_KINOVA_DEVICE], int &result); 179 int (*KinovaInitFingers)(); 180 int (*KinovaInitAPI)(); 181 int (*KinovaMoveHome)(); 182 int (*KinovaSendBasicTrajectory)(TrajectoryPoint command); 183 int (*KinovaSetActiveDevice)(KinovaDevice device); 184 int (*KinovaSetAngularControl)(); 185 int (*KinovaSetCartesianControl)(); 186 }; 187 188 #endif 189 #endif 190