Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
servoKinovaJacoCart.cpp
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  * Example with Kinova Jaco robot.
33  *
34  * Authors:
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 
46 #include <iostream>
47 
48 #include <visp3/core/vpConfig.h>
49 #include <visp3/robot/vpRobotKinova.h>
50 
51 int main(int argc, char*argv[])
52 {
53 #ifdef VISP_HAVE_JACOSDK
54  std::string opt_plugin_path = "./";
56  bool opt_verbose = false;
57  unsigned int opt_dof = 6; // Consider a 6 DoF robot by default
58 
59  for (int i = 1; i < argc; i++) {
60  if (std::string(argv[i]) == "--plugin" && i + 1 < argc) {
61  opt_plugin_path = std::string(argv[i + 1]);;
62  }
63  if ((std::string(argv[i]) == "--command_layer" || std::string(argv[i]) == "-l") && i + 1 < argc) {
64  if (std::string(argv[i + 1]) == "usb") {
65  opt_command_layer = vpRobotKinova::CMD_LAYER_USB;
66  }
67  else if (std::string(argv[i + 1]) == "ethernet") {
68  opt_command_layer = vpRobotKinova::CMD_LAYER_ETHERNET;
69  }
70  else {
71  opt_command_layer = vpRobotKinova::CMD_LAYER_UNSET;
72  }
73  }
74  else if (std::string(argv[i]) == "--dof") {
75  opt_dof = static_cast<unsigned int>(std::atoi(argv[i + 1]));
76  }
77  else if (std::string(argv[i]) == "--verbose" || std::string(argv[i]) == "-v") {
78  opt_verbose = true;
79  }
80  else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
81  std::cout << "SYNOPSYS" << std::endl
82  << " " << argv[0] << " [--plugin <path>] [--command_layer <name>] [--dof <4,6,7>] "
83  << "[--verbose] [--help] [-v] [-h]\n" << std::endl;
84  std::cout << "DESCRIPTION" << std::endl
85  << " --plugin <path>" << std::endl
86  << " Path to Jaco SDK .so or .dll plugin location. Default: \"./\"." << std::endl << std::endl
87  << " --command_layer <name>, -l <name>" << std::endl
88  << " Command layer name, either \"usb\" or \"ethernet\"." << std::endl << std::endl
89  << " --dof" << std::endl
90  << " Degrees of freedom. Possible values are 4, 6 or 7. Default value: 6." << std::endl << std::endl
91  << " --verbose, -v" << std::endl
92  << " Enable verbose mode to print addition information." << std::endl << std::endl
93  << " --help, -h" << std::endl
94  << " Print this helper message." << std::endl << std::endl;
95  std::cout << "EXAMPLE" << std::endl
96 #ifdef __linux__
97  << " " << argv[0] << " --plugin /opt/JACO-SDK/API"
98 #elif _WIN32
99  << " " << argv[0] << " --plugin \"C:\\Program Files(x86)\\JACO - SDK\\API\\x64\""
100 #endif
101  << " --command_layer usb" << std::endl << std::endl;
102 
103  return EXIT_SUCCESS;
104  }
105  }
106 
107  try {
108 
109  vpRobotKinova robot;
110  robot.setDoF(opt_dof);
111  robot.setVerbose(opt_verbose);
112  robot.setPluginLocation(opt_plugin_path);
113  robot.setCommandLayer(opt_command_layer);
114 
115  unsigned int n_devices = robot.connect();
116 
117  if (!n_devices) {
118  std::cout << "There is no Kinova device connected." << std::endl;
119  return EXIT_SUCCESS;
120  }
121 
122  // Move robot to home position
123  robot.homing();
124 
125  // Control robot in joint velocity
127  vpColVector vcart(6);
128  vcart[1] = -0.10; // send 10 cm/s on along Y axis
129 
130  // Sent new joint velocities each 5 ms
131  for (unsigned int i = 0; i < 300; i++) {
132  // We send the velocity vector as long as we want the robot to move along that vector
134  vpTime::wait(5);
135  }
136 
137  // Control robot in joint position
139  vpColVector p, p1, p2;
140 
141  // Move robot to home position
142  robot.homing();
143 
144  // Get current cartesian position
146 
147  // Move to first cartesian position
148  p1 = p;
149  p1[1] -= 0.1;
151 
152  // Move to second cartesian position
153  p2 = p;
154  p2[1] += 0.15;
156 
157  // Move back to home position
159  }
160  catch (const vpException &e) {
161  std::cout << "Catch exception: " << e.getStringMessage() << std::endl;
162  }
163 
164  std::cout << "The end" << std::endl;
165  return EXIT_SUCCESS;
166 #else
167  (void)(argc);
168  (void)(argv);
169  std::cout << "Install Jaco SDK, configure and build again ViSP to use this example..." << std::endl;
170 #endif
171 }
VISP_EXPORT int wait(double t0, double t)
Definition: vpTime.cpp:173
Initialize the position controller.
Definition: vpRobot.h:67
error that can be emited by ViSP classes.
Definition: vpException.h:71
void setVerbose(bool verbose)
void setCommandLayer(CommandLayer command_layer)
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Definition: vpRobot.cpp:201
Initialize the velocity controller.
Definition: vpRobot.h:66
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position)
void setDoF(unsigned int dof)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
const std::string & getStringMessage() const
Send a reference (constant) related the error message (can be empty).
Definition: vpException.cpp:92
void setPluginLocation(const std::string &plugin_location)
void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q)