Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
vpRobotKinova.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 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 https://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 *****************************************************************************/
35 
44 #ifndef vpRobotKinova_h
45 #define vpRobotKinova_h
46 
47 #include <visp3/core/vpConfig.h>
48 
49 #ifdef VISP_HAVE_JACOSDK
50 
51 #include <KinovaTypes.h>
52 
53 #ifdef __linux__
54 #include <Kinova.API.CommLayerUbuntu.h>
55 #include <Kinova.API.UsbCommandLayerUbuntu.h>
56 #include <dlfcn.h>
57 #include <stdio.h>
58 #include <unistd.h>
59 #include <vector>
60 #elif _WIN32
61 #include <CommandLayer.h>
62 #include <CommunicationLayer.h>
63 #include <winsock2.h>
64 #include <windows.h>
65 #include <conio.h>
66 #include <iostream>
67 #endif
68 
69 #include <visp3/core/vpHomogeneousMatrix.h>
70 #include <visp3/robot/vpRobot.h>
71 
90 class VISP_EXPORT vpRobotKinova : public vpRobot
91 {
92 public:
93  typedef enum { CMD_LAYER_USB, CMD_LAYER_ETHERNET, CMD_LAYER_UNSET } CommandLayer;
94 
95  vpRobotKinova();
96  virtual ~vpRobotKinova() VP_OVERRIDE;
97 
98  int connect();
99 
100  void get_eJe(vpMatrix &eJe) VP_OVERRIDE;
101  void get_fJe(vpMatrix &fJe) VP_OVERRIDE;
102 
107  vpHomogeneousMatrix get_eMc() const { return m_eMc; }
108 
109  int getActiveDevice() const { return m_active_device; }
110  int getNumDevices() const { return m_devices_count; }
111  void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE;
112  void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position) VP_OVERRIDE;
113  void getPosition(const vpRobot::vpControlFrameType frame, vpPoseVector &pose);
114 
115  void homing();
116 
121  void set_eMc(vpHomogeneousMatrix &eMc) { m_eMc = eMc; }
122  void setActiveDevice(int device);
127  void setCommandLayer(CommandLayer command_layer) { m_command_layer = command_layer; }
128  void setDoF(unsigned int dof);
129  void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) VP_OVERRIDE;
136  void setPluginLocation(const std::string &plugin_location) { m_plugin_location = plugin_location; }
137  void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE;
143  void setVerbose(bool verbose) { m_verbose = verbose; }
144 
145 protected:
146  void closePlugin();
147  void getJointPosition(vpColVector &q);
148  void init();
149  void loadPlugin();
150  void setCartVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &v);
151  void setJointVelocity(const vpColVector &qdot);
152 
153 protected:
155  std::string m_plugin_location;
156  bool m_verbose;
159  KinovaDevice *m_devices_list;
162 
163 #ifdef __linux__
164  void *m_command_layer_handle;
165 #elif _WIN32
166  HINSTANCE m_command_layer_handle;
167 #endif
168 
169 private:
170  int (*KinovaCloseAPI)();
171  int (*KinovaGetAngularCommand)(AngularPosition &);
172  int (*KinovaGetCartesianCommand)(CartesianPosition &);
173  int (*KinovaGetDevices)(KinovaDevice devices[MAX_KINOVA_DEVICE], int &result);
174  int (*KinovaInitFingers)();
175  int (*KinovaInitAPI)();
176  int (*KinovaMoveHome)();
177  int (*KinovaSendBasicTrajectory)(TrajectoryPoint command);
178  int (*KinovaSetActiveDevice)(KinovaDevice device);
179  int (*KinovaSetAngularControl)();
180  int (*KinovaSetCartesianControl)();
181 };
182 END_VISP_NAMESPACE
183 #endif
184 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:169
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:203
void set_eMc(vpHomogeneousMatrix &eMc)
void setCommandLayer(CommandLayer command_layer)
KinovaDevice * m_devices_list
int getNumDevices() const
std::string m_plugin_location
vpHomogeneousMatrix m_eMc
Constant transformation between end-effector and tool (or camera) frame.
CommandLayer m_command_layer
void setVerbose(bool verbose)
void setPluginLocation(const std::string &plugin_location)
int getActiveDevice() const
Class that defines a generic virtual robot.
Definition: vpRobot.h:59
vpControlFrameType
Definition: vpRobot.h:77
virtual void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)=0
virtual void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position)=0
Get the robot position (frame has to be specified).
virtual void init()=0
virtual void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &q)=0
virtual void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q)=0
Set a displacement (frame has to be specified) in position control.