Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
servoKinovaJacoCart.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Example with Kinova Jaco robot.
32 */
33
40
41#include <iostream>
42
43#include <visp3/core/vpConfig.h>
44#include <visp3/robot/vpRobotKinova.h>
45
46int main(int argc, char *argv[])
47{
48#ifdef VISP_HAVE_JACOSDK
49#ifdef ENABLE_VISP_NAMESPACE
50 using namespace VISP_NAMESPACE_NAME;
51#endif
52
53 std::string opt_plugin_path = "./";
55 bool opt_verbose = false;
56 unsigned int opt_dof = 6; // Consider a 6 DoF robot by default
57
58 for (int i = 1; i < argc; i++) {
59 if (std::string(argv[i]) == "--plugin" && i + 1 < argc) {
60 opt_plugin_path = std::string(argv[i + 1]);
61 ;
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"
84 << std::endl;
85 std::cout << "DESCRIPTION" << std::endl
86 << " --plugin <path>" << std::endl
87 << " Path to Jaco SDK .so or .dll plugin location. Default: \"./\"." << std::endl
88 << std::endl
89 << " --command_layer <name>, -l <name>" << std::endl
90 << " Command layer name, either \"usb\" or \"ethernet\"." << std::endl
91 << std::endl
92 << " --dof" << std::endl
93 << " Degrees of freedom. Possible values are 4, 6 or 7. Default value: 6." << std::endl
94 << std::endl
95 << " --verbose, -v" << std::endl
96 << " Enable verbose mode to print addition information." << std::endl
97 << std::endl
98 << " --help, -h" << std::endl
99 << " Print this helper message." << std::endl
100 << std::endl;
101 std::cout << "EXAMPLE" << std::endl
102#ifdef __linux__
103 << " " << argv[0] << " --plugin /opt/JACO-SDK/API"
104#elif _WIN32
105 << " " << argv[0] << " --plugin \"C:\\Program Files(x86)\\JACO - SDK\\API\\x64\""
106#endif
107 << " --command_layer usb" << std::endl
108 << std::endl;
109
110 return EXIT_SUCCESS;
111 }
112 }
113
114 try {
115
116 vpRobotKinova robot;
117 robot.setDoF(opt_dof);
118 robot.setVerbose(opt_verbose);
119 robot.setPluginLocation(opt_plugin_path);
120 robot.setCommandLayer(opt_command_layer);
121
122 unsigned int n_devices = robot.connect();
123
124 if (!n_devices) {
125 std::cout << "There is no Kinova device connected." << std::endl;
126 return EXIT_SUCCESS;
127 }
128
129 // Move robot to home position
130 robot.homing();
131
132 // Control robot in joint velocity
133 robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL);
134 vpColVector vcart(6);
135 vcart[1] = -0.10; // send 10 cm/s on along Y axis
136
137 // Sent new joint velocities each 5 ms
138 for (unsigned int i = 0; i < 300; i++) {
139 // We send the velocity vector as long as we want the robot to move along that vector
140 robot.setVelocity(vpRobot::END_EFFECTOR_FRAME, vcart);
141 vpTime::wait(5);
142 }
143
144 // Control robot in joint position
145 robot.setRobotState(vpRobot::STATE_POSITION_CONTROL);
146 vpColVector p, p1, p2;
147
148 // Move robot to home position
149 robot.homing();
150
151 // Get current cartesian position
152 robot.getPosition(vpRobot::END_EFFECTOR_FRAME, p);
153
154 // Move to first cartesian position
155 p1 = p;
156 p1[1] -= 0.1;
157 robot.setPosition(vpRobot::END_EFFECTOR_FRAME, p1);
158
159 // Move to second cartesian position
160 p2 = p;
161 p2[1] += 0.15;
162 robot.setPosition(vpRobot::END_EFFECTOR_FRAME, p2);
163
164 // Move back to home position
165 robot.setPosition(vpRobot::END_EFFECTOR_FRAME, p);
166 }
167 catch (const vpException &e) {
168 std::cout << "Catch exception: " << e.getStringMessage() << std::endl;
169 }
170
171 std::cout << "The end" << std::endl;
172 return EXIT_SUCCESS;
173#else
174 (void)(argc);
175 (void)(argv);
176 std::cout << "Install Jaco SDK, configure and build again ViSP to use this example..." << std::endl;
177#endif
178}
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
Definition vpException.h:60
void setDoF(unsigned int dof)
@ END_EFFECTOR_FRAME
Definition vpRobot.h:80
@ STATE_POSITION_CONTROL
Initialize the position controller.
Definition vpRobot.h:65
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
Definition vpRobot.h:64
VISP_EXPORT int wait(double t0, double t)