Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
moveBiclops.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
* Tests the control law
32
*/
33
43
44
#include <iostream>
45
46
#include <visp3/core/vpConfig.h>
47
48
#ifdef VISP_HAVE_BICLOPS
49
50
#include <visp3/robot/vpRobotBiclops.h>
51
#include <visp3/io/vpParseArgv.h>
52
53
// List of allowed command line options
54
#define GETOPTARGS "c:h"
55
56
#ifdef ENABLE_VISP_NAMESPACE
57
using namespace
VISP_NAMESPACE_NAME
;
58
#endif
59
60
/*
61
* Print the program options.
62
*
63
* \param name : Program name.
64
* \param badparam : Bad parameter name.
65
* \param conf : Biclops configuration file.
66
*/
67
void
usage(
const
char
*name,
const
char
*badparam, std::string conf)
68
{
69
fprintf(stdout,
"\n\
70
Move the Biclops robot\n\
71
\n\
72
SYNOPSIS\n\
73
%s [-c <Biclops configuration file>] [-h]\n\
74
"
,
75
name);
76
77
fprintf(stdout,
"\n\
78
OPTIONS: Default\n\
79
-c <Biclops configuration file> %s\n\
80
Sets the Biclops robot configuration file.\n\n"
,
81
conf.c_str());
82
83
if
(badparam) {
84
fprintf(stderr,
"ERROR: \n"
);
85
fprintf(stderr,
"\nBad parameter [%s]\n"
, badparam);
86
}
87
}
88
98
bool
getOptions(
int
argc,
const
char
**argv, std::string &conf)
99
{
100
const
char
*optarg_;
101
int
c;
102
while
((c =
vpParseArgv::parse
(argc, argv, GETOPTARGS, &optarg_)) > 1) {
103
104
switch
(c) {
105
case
'c'
:
106
conf = optarg_;
107
break
;
108
case
'h'
:
109
usage(argv[0],
nullptr
, conf);
110
return
false
;
111
112
default
:
113
usage(argv[0], optarg_, conf);
114
return
false
;
115
}
116
}
117
118
if
((c == 1) || (c == -1)) {
119
// standalone param or error
120
usage(argv[0],
nullptr
, conf);
121
std::cerr <<
"ERROR: "
<< std::endl;
122
std::cerr <<
" Bad argument "
<< optarg_ << std::endl << std::endl;
123
return
false
;
124
}
125
126
return
true
;
127
}
128
129
int
main(
int
argc,
const
char
**argv)
130
{
131
std::string opt_conf =
"/usr/share/BiclopsDefault.cfg"
;
132
133
// Read the command line options
134
if
(getOptions(argc, argv, opt_conf) ==
false
) {
135
return
EXIT_FAILURE;
136
}
137
try
{
138
vpRobotBiclops
robot(opt_conf);
139
140
vpColVector
q(
vpBiclops::ndof
);
// desired position
141
vpColVector
qdot(
vpBiclops::ndof
);
// desired velocity
142
vpColVector
qm(
vpBiclops::ndof
);
// measured position
143
vpColVector
qm_dot(
vpBiclops::ndof
);
// measured velocity
144
145
robot.setRobotState(
vpRobot::STATE_POSITION_CONTROL
);
146
147
q = 0;
148
q[0] =
vpMath::rad
(-10);
149
q[1] =
vpMath::rad
(-20);
150
std::cout <<
"Set Joint position "
151
<<
" pan: "
<<
vpMath::deg
(q[0]) <<
" deg"
152
<<
" tilt: "
<<
vpMath::deg
(q[1]) <<
" deg"
<< std::endl;
153
robot.setPositioningVelocity(30.);
154
robot.setPosition(
vpRobot::JOINT_STATE
, q);
155
156
robot.getPosition(
vpRobot::JOINT_STATE
, qm);
157
std::cout <<
" Joint position "
158
<<
" pan: "
<<
vpMath::deg
(qm[0]) <<
" tilt: "
<<
vpMath::deg
(qm[1]) << std::endl;
159
robot.getVelocity(
vpRobot::JOINT_STATE
, qm);
160
std::cout <<
" Joint velocity "
161
<<
" pan: "
<<
vpMath::deg
(qm[0]) <<
" tilt: "
<<
vpMath::deg
(qm[1]) << std::endl;
162
163
q[0] =
vpMath::rad
(10);
164
q[1] =
vpMath::rad
(20);
165
std::cout <<
"Set Joint position "
166
<<
" pan: "
<<
vpMath::deg
(q[0]) <<
" deg"
167
<<
" tilt: "
<<
vpMath::deg
(q[1]) <<
" deg"
<< std::endl;
168
robot.setPositioningVelocity(10);
169
robot.setPosition(
vpRobot::JOINT_STATE
, q);
170
171
robot.getPosition(
vpRobot::JOINT_STATE
, qm);
172
std::cout <<
" Joint position: "
173
<<
" pan: "
<<
vpMath::deg
(qm[0]) <<
" tilt: "
<<
vpMath::deg
(qm[1]) << std::endl;
174
robot.getVelocity(
vpRobot::JOINT_STATE
, qm);
175
std::cout <<
" Joint velocity: "
176
<<
" pan: "
<<
vpMath::deg
(qm[0]) <<
" tilt: "
<<
vpMath::deg
(qm[1]) << std::endl;
177
178
std::cout <<
"Set STATE_VELOCITY_CONTROL"
<< std::endl;
179
robot.setRobotState(
vpRobot::STATE_VELOCITY_CONTROL
);
180
181
robot.getPosition(
vpRobot::JOINT_STATE
, qm);
182
std::cout <<
" Joint position: "
183
<<
" pan: "
<<
vpMath::deg
(qm[0]) <<
" deg"
184
<<
" tilt: "
<<
vpMath::deg
(qm[1]) <<
" deg"
<< std::endl;
185
robot.getVelocity(
vpRobot::JOINT_STATE
, qm);
186
std::cout <<
" Joint velocity "
187
<<
" pan: "
<<
vpMath::deg
(qm[0]) <<
" tilt: "
<<
vpMath::deg
(qm[1]) << std::endl;
188
189
qdot = 0;
190
// qdot[0] = vpMath::rad(0.1) ;
191
qdot[1] =
vpMath::rad
(25);
192
std::cout <<
"Set joint velocity for 5 sec"
193
<<
" pan: "
<<
vpMath::deg
(qdot[0]) <<
" deg/s"
194
<<
" tilt: "
<<
vpMath::deg
(qdot[1]) <<
" deg/s"
<< std::endl;
195
robot.setVelocity(
vpRobot::JOINT_STATE
, qdot);
196
197
// waits 5000ms
198
vpTime::wait
(5000.0);
199
200
robot.getPosition(
vpRobot::JOINT_STATE
, qm);
201
std::cout <<
" Joint position "
202
<<
" pan: "
<<
vpMath::deg
(qm[0]) <<
" deg"
203
<<
" tilt: "
<<
vpMath::deg
(qm[1]) <<
" deg"
<< std::endl;
204
robot.getVelocity(
vpRobot::JOINT_STATE
, qm);
205
std::cout <<
" Joint velocity "
206
<<
" pan: "
<<
vpMath::deg
(qm[0]) <<
" tilt: "
<<
vpMath::deg
(qm[1]) << std::endl;
207
208
qdot = 0;
209
// qdot[0] = vpMath::rad(0.1) ;
210
qdot[1] = -
vpMath::rad
(25);
211
std::cout <<
"Set joint velocity for 3 sec"
212
<<
" pan: "
<<
vpMath::deg
(qdot[0]) <<
" deg/s"
213
<<
" tilt: "
<<
vpMath::deg
(qdot[1]) <<
" deg/s"
<< std::endl;
214
robot.setVelocity(
vpRobot::JOINT_STATE
, qdot);
215
216
// waits 3000 ms
217
vpTime::wait
(3000.0);
218
219
robot.getPosition(
vpRobot::JOINT_STATE
, qm);
220
std::cout <<
" Joint position "
221
<<
" pan: "
<<
vpMath::deg
(qm[0]) <<
" deg"
222
<<
" tilt: "
<<
vpMath::deg
(qm[1]) <<
" deg"
<< std::endl;
223
robot.getVelocity(
vpRobot::JOINT_STATE
, qm);
224
std::cout <<
" Joint velocity "
225
<<
" pan: "
<<
vpMath::deg
(qm[0]) <<
" tilt: "
<<
vpMath::deg
(qm[1]) << std::endl;
226
227
qdot = 0;
228
// qdot[0] = vpMath::rad(0.1) ;
229
qdot[1] =
vpMath::rad
(10);
230
std::cout <<
"Set joint velocity for 2 sec"
231
<<
" pan: "
<<
vpMath::deg
(qdot[0]) <<
" deg/s"
232
<<
" tilt: "
<<
vpMath::deg
(qdot[1]) <<
" deg/s"
<< std::endl;
233
robot.setVelocity(
vpRobot::JOINT_STATE
, qdot);
234
235
// waits 2000 ms
236
vpTime::wait
(2000.0);
237
238
robot.getPosition(
vpRobot::JOINT_STATE
, qm);
239
std::cout <<
" Joint position "
240
<<
" pan: "
<<
vpMath::deg
(qm[0]) <<
" deg"
241
<<
" tilt: "
<<
vpMath::deg
(qm[1]) <<
" deg"
<< std::endl;
242
robot.getVelocity(
vpRobot::JOINT_STATE
, qm);
243
std::cout <<
" Joint velocity "
244
<<
" pan: "
<<
vpMath::deg
(qm[0]) <<
" tilt: "
<<
vpMath::deg
(qm[1]) << std::endl;
245
246
qdot = 0;
247
qdot[0] =
vpMath::rad
(-5);
248
// qdot[1] = vpMath::rad(-5);
249
250
std::cout <<
"Set joint velocity for 2 sec"
251
<<
" pan: "
<<
vpMath::deg
(qdot[0]) <<
" deg/s"
252
<<
" tilt: "
<<
vpMath::deg
(qdot[1]) <<
" deg/s"
<< std::endl;
253
robot.setVelocity(
vpRobot::JOINT_STATE
, qdot);
254
255
// waits 2000 ms
256
vpTime::wait
(2000.0);
257
258
robot.getPosition(
vpRobot::JOINT_STATE
, qm);
259
std::cout <<
" Joint position "
260
<<
" pan: "
<<
vpMath::deg
(qm[0]) <<
" deg"
261
<<
" tilt: "
<<
vpMath::deg
(qm[1]) <<
" deg"
<< std::endl;
262
robot.getVelocity(
vpRobot::JOINT_STATE
, qm);
263
std::cout <<
" Joint velocity "
264
<<
" pan: "
<<
vpMath::deg
(qm[0]) <<
" tilt: "
<<
vpMath::deg
(qm[1]) << std::endl;
265
return
EXIT_SUCCESS;
266
}
267
catch
(
const
vpException
&e) {
268
std::cout <<
"Catch an exception: "
<<
e
.getMessage() << std::endl;
269
return
EXIT_FAILURE;
270
}
271
}
272
#else
273
int
main()
274
{
275
std::cout <<
"You do not have an Biclops PT robot connected to your computer..."
<< std::endl;
276
return
EXIT_SUCCESS;
277
}
278
279
#endif
vpBiclops::ndof
static const unsigned int ndof
Number of dof.
Definition
vpBiclops.h:101
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
vpMath::deg
static double deg(double rad)
Definition
vpMath.h:119
vpParseArgv::parse
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition
vpParseArgv.cpp:70
vpRobotBiclops
Interface for the Biclops, pan, tilt head control.
Definition
vpRobotBiclops.h:92
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)
example
servo-biclops
moveBiclops.cpp
Generated by
1.17.0