Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
servoSimuPoint2DCamVelocity2.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
* Simulation of a 2D visual servoing on a point.
32
*/
33
49
50
#include <stdio.h>
51
#include <stdlib.h>
52
53
#include <visp3/core/vpConfig.h>
54
#include <visp3/core/vpHomogeneousMatrix.h>
55
#include <visp3/core/vpMath.h>
56
#include <visp3/io/vpParseArgv.h>
57
#include <visp3/robot/vpSimulatorCamera.h>
58
#include <visp3/visual_features/vpFeatureBuilder.h>
59
#include <visp3/visual_features/vpFeaturePoint.h>
60
#include <visp3/vs/vpServo.h>
61
62
// List of allowed command line options
63
#define GETOPTARGS "h"
64
65
#ifdef ENABLE_VISP_NAMESPACE
66
using namespace
VISP_NAMESPACE_NAME
;
67
#endif
68
69
void
usage(
const
char
*name,
const
char
*badparam);
70
bool
getOptions(
int
argc,
const
char
**argv);
71
80
void
usage(
const
char
*name,
const
char
*badparam)
81
{
82
fprintf(stdout,
"\n\
83
Simulation of a 2D visual servoing on a point:\n\
84
- eye-in-hand control law,\n\
85
- articular velocity are computed,\n\
86
- without display.\n\
87
\n\
88
SYNOPSIS\n\
89
%s [-h]\n"
,
90
name);
91
92
fprintf(stdout,
"\n\
93
OPTIONS: Default\n\
94
\n\
95
-h\n\
96
Print the help.\n"
);
97
98
if
(badparam)
99
fprintf(stdout,
"\nERROR: Bad parameter [%s]\n"
, badparam);
100
}
101
112
bool
getOptions(
int
argc,
const
char
**argv)
113
{
114
const
char
*optarg_;
115
int
c;
116
while
((c =
vpParseArgv::parse
(argc, argv, GETOPTARGS, &optarg_)) > 1) {
117
118
switch
(c) {
119
case
'h'
:
120
usage(argv[0],
nullptr
);
121
return
false
;
122
123
default
:
124
usage(argv[0], optarg_);
125
return
false
;
126
}
127
}
128
129
if
((c == 1) || (c == -1)) {
130
// standalone param or error
131
usage(argv[0],
nullptr
);
132
std::cerr <<
"ERROR: "
<< std::endl;
133
std::cerr <<
" Bad argument "
<< optarg_ << std::endl << std::endl;
134
return
false
;
135
}
136
137
return
true
;
138
}
139
140
int
main(
int
argc,
const
char
**argv)
141
{
142
#if (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
143
try
{
144
// Read the command line options
145
if
(getOptions(argc, argv) ==
false
) {
146
return
EXIT_FAILURE;
147
}
148
149
vpServo
task
;
150
vpSimulatorCamera
robot;
151
152
std::cout << std::endl;
153
std::cout <<
"-------------------------------------------------------"
<< std::endl;
154
std::cout <<
" Test program for vpServo "
<< std::endl;
155
std::cout <<
" Eye-in-hand task control, articular velocity are computed"
<< std::endl;
156
std::cout <<
" Simulation "
<< std::endl;
157
std::cout <<
" task : servo a point "
<< std::endl;
158
std::cout <<
"-------------------------------------------------------"
<< std::endl;
159
std::cout << std::endl;
160
161
// sets the initial camera location
162
vpHomogeneousMatrix
cMo
;
163
cMo
[0][3] = 0.1;
164
cMo
[1][3] = 0.2;
165
cMo
[2][3] = 2;
166
// Compute the position of the object in the world frame
167
vpHomogeneousMatrix
wMc, wMo;
168
robot.getPosition(wMc);
169
wMo = wMc *
cMo
;
170
171
// sets the point coordinates in the world frame
172
vpPoint
point(0, 0, 0);
173
174
// computes the point coordinates in the camera frame and its 2D
175
// coordinates
176
point.track(cMo);
177
178
// sets the current position of the visual feature
179
vpFeaturePoint
p
;
180
vpFeatureBuilder::create
(p, point);
// retrieve x,y and Z of the vpPoint structure
181
182
// sets the desired position of the visual feature
183
vpFeaturePoint
pd;
184
pd.
buildFrom
(0, 0, 1);
185
186
// define the task
187
// - we want an eye-in-hand control law
188
// - articular velocity are computed
189
task
.setServo(
vpServo::EYEINHAND_L_cVe_eJe
);
190
task
.setInteractionMatrixType(
vpServo::MEAN
);
191
192
// Set the position of the end-effector frame in the camera frame
193
vpHomogeneousMatrix
cMe;
194
vpVelocityTwistMatrix
cVe(cMe);
195
task
.set_cVe(cVe);
196
197
// Set the Jacobian (expressed in the end-effector frame)
198
vpMatrix
eJe;
199
robot.get_eJe(eJe);
200
task
.set_eJe(eJe);
201
202
// we want to see a point on a point
203
task
.addFeature(p, pd);
204
205
// set the gain
206
task
.setLambda(1);
207
// Display task information
208
task
.print();
209
210
unsigned
int
iter
= 0;
211
// loop
212
while
(iter++ < 100) {
213
std::cout <<
"---------------------------------------------"
<<
iter
<< std::endl;
214
vpColVector
v
;
215
216
// Set the Jacobian (expressed in the end-effector frame)
217
// since q is modified eJe is modified
218
robot.get_eJe(eJe);
219
task
.set_eJe(eJe);
220
221
// get the robot position
222
robot.getPosition(wMc);
223
// Compute the position of the object frame in the camera frame
224
cMo
= wMc.
inverse
() * wMo;
225
226
// new point position
227
point.track(cMo);
228
vpFeatureBuilder::create
(p, point);
// retrieve x,y and Z of the vpPoint structure
229
pd.
buildFrom
(0, 0, 1);
// Since vpServo::MEAN interaction matrix is
230
// used, we need to update the desired feature at
231
// each iteration
232
233
// compute the control law
234
v
=
task
.computeControlLaw();
235
236
// send the camera velocity to the controller
237
robot.setVelocity(
vpRobot::CAMERA_FRAME
, v);
238
239
std::cout <<
"|| s - s* || = "
<< (
task
.getError()).sumSquare() << std::endl;
240
}
241
242
// Display task information
243
task
.print();
244
return
EXIT_SUCCESS;
245
}
246
catch
(
const
vpException
&e) {
247
std::cout <<
"Catch a ViSP exception: "
<<
e
<< std::endl;
248
return
EXIT_FAILURE;
249
}
250
#else
251
(void)argc;
252
(void)argv;
253
std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV"
<< std::endl;
254
return
EXIT_SUCCESS;
255
#endif
256
}
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
vpFeatureBuilder::create
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Definition
vpFeatureBuilderPoint.cpp:90
vpFeaturePoint
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
Definition
vpFeaturePoint.h:190
vpFeaturePoint::buildFrom
vpFeaturePoint & buildFrom(const double &x, const double &y, const double &Z)
Definition
vpFeaturePoint.cpp:392
vpHomogeneousMatrix
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition
vpHomogeneousMatrix.h:221
vpHomogeneousMatrix::inverse
vpHomogeneousMatrix inverse() const
Definition
vpHomogeneousMatrix.cpp:1016
vpMatrix
Implementation of a matrix and operations on matrices.
Definition
vpMatrix.h:175
vpParseArgv::parse
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition
vpParseArgv.cpp:70
vpPoint
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition
vpPoint.h:79
vpRobot::CAMERA_FRAME
@ CAMERA_FRAME
Definition
vpRobot.h:81
vpServo
Definition
vpServo.h:159
vpServo::EYEINHAND_L_cVe_eJe
@ EYEINHAND_L_cVe_eJe
Definition
vpServo.h:183
vpServo::MEAN
@ MEAN
Definition
vpServo.h:229
vpSimulatorCamera
Class that defines the simplest robot: a free flying camera.
Definition
vpSimulatorCamera.h:113
vpVelocityTwistMatrix
Definition
vpVelocityTwistMatrix.h:175
VISP_NAMESPACE_NAME
Definition
vpEigenConversion.h:44
ibvs-four-points.p
p
Definition
ibvs-four-points.py:280
ibvs-four-points.iter
int iter
Definition
ibvs-four-points.py:236
ibvs-four-points.v
v
Definition
ibvs-four-points.py:271
ibvs-four-points.task
task
Definition
ibvs-four-points.py:210
ibvs-four-points.e
e
Definition
ibvs-four-points.py:272
realsense-mbt.cMo
cMo
Definition
realsense-mbt.py:212
example
robot-simulator
camera
servoSimuPoint2DCamVelocity2.cpp
Generated by
1.17.0