Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
servoKinovaJacoJoint.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
46
int
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 =
"./"
;
54
vpRobotKinova::CommandLayer
opt_command_layer =
vpRobotKinova::CMD_LAYER_UNSET
;
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
vpRobotKinova
robot;
116
robot.
setDoF
(opt_dof);
117
robot.setVerbose(opt_verbose);
118
robot.setPluginLocation(opt_plugin_path);
119
robot.setCommandLayer(opt_command_layer);
120
121
int
n_devices = robot.connect();
122
123
if
(!n_devices) {
124
std::cout <<
"There is no Kinova device connected."
<< std::endl;
125
return
EXIT_SUCCESS;
126
}
127
128
// Move robot to home position
129
robot.homing();
130
131
// Control robot in joint velocity
132
robot.setRobotState(
vpRobot::STATE_VELOCITY_CONTROL
);
133
vpColVector
qdot(opt_dof);
134
qdot[opt_dof - 1] =
vpMath::rad
(20);
// send 20 deg/s on last joint
135
136
// Sent new joint velocities each 5 ms
137
for
(
unsigned
int
i = 0;
i
< 300;
i
++) {
138
// We send the velocity vector as long as we want the robot to move along that vector
139
robot.setVelocity(
vpRobot::JOINT_STATE
, qdot);
140
vpTime::wait
(5);
141
}
142
143
// Control robot in joint position
144
robot.setRobotState(
vpRobot::STATE_POSITION_CONTROL
);
145
vpColVector
q, q1, q2;
146
147
// Move robot to home position
148
robot.homing();
149
150
// Get current joint position
151
robot.getPosition(
vpRobot::JOINT_STATE
, q);
152
153
// Move to first joint position
154
q1 = q;
155
q1[0] +=
vpMath::rad
(30);
156
robot.setPosition(
vpRobot::JOINT_STATE
, q1);
157
158
// Move to second joint position
159
q2 = q;
160
q2[0] +=
vpMath::rad
(-60);
161
robot.setPosition(
vpRobot::JOINT_STATE
, q2);
162
163
// Move back to home position
164
robot.setPosition(
vpRobot::JOINT_STATE
, q);
165
}
166
catch
(
const
vpException
&e) {
167
std::cout <<
"Catch exception: "
<<
e
.getStringMessage() << std::endl;
168
}
169
170
std::cout <<
"The end"
<< std::endl;
171
return
EXIT_SUCCESS;
172
#else
173
(void)(argc);
174
(void)(argv);
175
std::cout <<
"Install Jaco SDK, configure and build again ViSP to use this example..."
<< std::endl;
176
#endif
177
}
vpColVector
Implementation of column vector and the associated operations.
Definition
vpColVector.h:191
vpException
error that can be emitted by ViSP classes.
Definition
vpException.h:60
vpMath::rad
static double rad(double deg)
Definition
vpMath.h:129
vpRobotKinova
Definition
vpRobotKinova.h:113
vpRobotKinova::setDoF
void setDoF(unsigned int dof)
Definition
vpRobotKinova.cpp:76
vpRobotKinova::CommandLayer
CommandLayer
Definition
vpRobotKinova.h:115
vpRobotKinova::CMD_LAYER_UNSET
@ CMD_LAYER_UNSET
Definition
vpRobotKinova.h:115
vpRobotKinova::CMD_LAYER_USB
@ CMD_LAYER_USB
Definition
vpRobotKinova.h:115
vpRobotKinova::CMD_LAYER_ETHERNET
@ CMD_LAYER_ETHERNET
Definition
vpRobotKinova.h:115
vpRobot::JOINT_STATE
@ JOINT_STATE
Definition
vpRobot.h:79
vpRobot::STATE_POSITION_CONTROL
@ STATE_POSITION_CONTROL
Initialize the position controller.
Definition
vpRobot.h:65
vpRobot::STATE_VELOCITY_CONTROL
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
Definition
vpRobot.h:64
VISP_NAMESPACE_NAME
Definition
vpEigenConversion.h:44
ibvs-four-points.e
e
Definition
ibvs-four-points.py:272
vpTime::wait
VISP_EXPORT int wait(double t0, double t)
yolo-centering-task-afma6.i
i
Definition
yolo-centering-task-afma6.py:329
example
servo-kinova
servoKinovaJacoJoint.cpp
Generated by
1.17.0