Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
servoKinovaJacoCart.cpp
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 * Example with Kinova Jaco robot.
33 *
34*****************************************************************************/
35
43#include <iostream>
44
45#include <visp3/core/vpConfig.h>
46#include <visp3/robot/vpRobotKinova.h>
47
48int main(int argc, char *argv[])
49{
50#ifdef VISP_HAVE_JACOSDK
51 std::string opt_plugin_path = "./";
53 bool opt_verbose = false;
54 unsigned int opt_dof = 6; // Consider a 6 DoF robot by default
55
56 for (int i = 1; i < argc; i++) {
57 if (std::string(argv[i]) == "--plugin" && i + 1 < argc) {
58 opt_plugin_path = std::string(argv[i + 1]);
59 ;
60 }
61 if ((std::string(argv[i]) == "--command_layer" || std::string(argv[i]) == "-l") && i + 1 < argc) {
62 if (std::string(argv[i + 1]) == "usb") {
63 opt_command_layer = vpRobotKinova::CMD_LAYER_USB;
64 } else if (std::string(argv[i + 1]) == "ethernet") {
65 opt_command_layer = vpRobotKinova::CMD_LAYER_ETHERNET;
66 } else {
67 opt_command_layer = vpRobotKinova::CMD_LAYER_UNSET;
68 }
69 } else if (std::string(argv[i]) == "--dof") {
70 opt_dof = static_cast<unsigned int>(std::atoi(argv[i + 1]));
71 } else if (std::string(argv[i]) == "--verbose" || std::string(argv[i]) == "-v") {
72 opt_verbose = true;
73 } else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
74 std::cout << "SYNOPSYS" << std::endl
75 << " " << argv[0] << " [--plugin <path>] [--command_layer <name>] [--dof <4,6,7>] "
76 << "[--verbose] [--help] [-v] [-h]\n"
77 << std::endl;
78 std::cout << "DESCRIPTION" << std::endl
79 << " --plugin <path>" << std::endl
80 << " Path to Jaco SDK .so or .dll plugin location. Default: \"./\"." << std::endl
81 << std::endl
82 << " --command_layer <name>, -l <name>" << std::endl
83 << " Command layer name, either \"usb\" or \"ethernet\"." << std::endl
84 << std::endl
85 << " --dof" << std::endl
86 << " Degrees of freedom. Possible values are 4, 6 or 7. Default value: 6." << std::endl
87 << std::endl
88 << " --verbose, -v" << std::endl
89 << " Enable verbose mode to print addition information." << std::endl
90 << std::endl
91 << " --help, -h" << std::endl
92 << " Print this helper message." << std::endl
93 << std::endl;
94 std::cout << "EXAMPLE" << std::endl
95#ifdef __linux__
96 << " " << argv[0] << " --plugin /opt/JACO-SDK/API"
97#elif _WIN32
98 << " " << argv[0] << " --plugin \"C:\\Program Files(x86)\\JACO - SDK\\API\\x64\""
99#endif
100 << " --command_layer usb" << std::endl
101 << 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
145 robot.getPosition(vpRobot::END_EFFECTOR_FRAME, p);
146
147 // Move to first cartesian position
148 p1 = p;
149 p1[1] -= 0.1;
150 robot.setPosition(vpRobot::END_EFFECTOR_FRAME, p1);
151
152 // Move to second cartesian position
153 p2 = p;
154 p2[1] += 0.15;
155 robot.setPosition(vpRobot::END_EFFECTOR_FRAME, p2);
156
157 // Move back to home position
158 robot.setPosition(vpRobot::END_EFFECTOR_FRAME, p);
159 } catch (const vpException &e) {
160 std::cout << "Catch exception: " << e.getStringMessage() << std::endl;
161 }
162
163 std::cout << "The end" << std::endl;
164 return EXIT_SUCCESS;
165#else
166 (void)(argc);
167 (void)(argv);
168 std::cout << "Install Jaco SDK, configure and build again ViSP to use this example..." << std::endl;
169#endif
170}
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
Definition vpException.h:59
const std::string & getStringMessage() const
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
void setVerbose(bool verbose)
Definition vpRobot.h:157
@ END_EFFECTOR_FRAME
Definition vpRobot.h:79
@ STATE_POSITION_CONTROL
Initialize the position controller.
Definition vpRobot.h:65
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
Definition vpRobot.h:64
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Definition vpRobot.cpp:198
VISP_EXPORT int wait(double t0, double t)