Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
servoSimuPoint2DCamVelocity1.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
41
42
#include <stdio.h>
43
#include <stdlib.h>
44
45
#include <visp3/core/vpConfig.h>
46
#include <visp3/core/vpHomogeneousMatrix.h>
47
#include <visp3/core/vpMath.h>
48
#include <visp3/io/vpParseArgv.h>
49
#include <visp3/robot/vpSimulatorCamera.h>
50
#include <visp3/visual_features/vpFeatureBuilder.h>
51
#include <visp3/visual_features/vpFeaturePoint.h>
52
#include <visp3/vs/vpServo.h>
53
54
// List of allowed command line options
55
#define GETOPTARGS "h"
56
57
#ifdef ENABLE_VISP_NAMESPACE
58
using namespace
VISP_NAMESPACE_NAME
;
59
#endif
60
61
void
usage(
const
char
*name,
const
char
*badparam);
62
bool
getOptions(
int
argc,
const
char
**argv);
63
72
void
usage(
const
char
*name,
const
char
*badparam)
73
{
74
fprintf(stdout,
"\n\
75
Simulation of a 2D visual servoing on a point:\n\
76
- eye-in-hand control law,\n\
77
- velocity computed in the camera frame,\n\
78
- without display.\n\
79
\n\
80
SYNOPSIS\n\
81
%s [-h]\n"
,
82
name);
83
84
fprintf(stdout,
"\n\
85
OPTIONS: Default\n\
86
\n\
87
-h\n\
88
Print the help.\n"
);
89
90
if
(badparam)
91
fprintf(stdout,
"\nERROR: Bad parameter [%s]\n"
, badparam);
92
}
93
104
bool
getOptions(
int
argc,
const
char
**argv)
105
{
106
const
char
*optarg_;
107
int
c;
108
while
((c =
vpParseArgv::parse
(argc, argv, GETOPTARGS, &optarg_)) > 1) {
109
110
switch
(c) {
111
case
'h'
:
112
usage(argv[0],
nullptr
);
113
return
false
;
114
115
default
:
116
usage(argv[0], optarg_);
117
return
false
;
118
}
119
}
120
121
if
((c == 1) || (c == -1)) {
122
// standalone param or error
123
usage(argv[0],
nullptr
);
124
std::cerr <<
"ERROR: "
<< std::endl;
125
std::cerr <<
" Bad argument "
<< optarg_ << std::endl << std::endl;
126
return
false
;
127
}
128
129
return
true
;
130
}
131
132
int
main(
int
argc,
const
char
**argv)
133
{
134
#if (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
135
try
{
136
// Read the command line options
137
if
(getOptions(argc, argv) ==
false
) {
138
return
EXIT_FAILURE;
139
}
140
141
vpServo
task
;
142
vpSimulatorCamera
robot;
143
144
// sets the initial camera location
145
vpHomogeneousMatrix
cMo
;
146
cMo
[0][3] = 0.1;
147
cMo
[1][3] = 0.2;
148
cMo
[2][3] = 2;
149
150
// Compute the position of the object in the world frame
151
vpHomogeneousMatrix
wMc, wMo;
152
robot.getPosition(wMc);
153
wMo = wMc *
cMo
;
154
155
// sets the point coordinates in the world frame
156
vpPoint
point(0, 0, 0);
157
158
// computes the point coordinates in the camera frame and its 2D
159
// coordinates
160
point.track(cMo);
161
162
// sets the current position of the visual feature
163
vpFeaturePoint
p
;
164
vpFeatureBuilder::create
(p, point);
// retrieve x,y and Z of the vpPoint structure
165
166
// sets the desired position of the visual feature
167
vpFeaturePoint
pd;
168
pd.
buildFrom
(0, 0, 1);
// buildFrom(x,y,Z) ;
169
170
// define the task
171
// - we want an eye-in-hand control law
172
// - robot is controlled in the camera frame
173
task
.setServo(
vpServo::EYEINHAND_CAMERA
);
174
175
// we want to see a point on a point
176
std::cout << std::endl;
177
task
.addFeature(p, pd);
178
179
// set the gain
180
task
.setLambda(1);
181
182
// Display task information
183
task
.print();
184
185
unsigned
int
iter
= 0;
186
// loop
187
while
(iter++ < 100) {
188
std::cout <<
"---------------------------------------------"
<<
iter
<< std::endl;
189
vpColVector
v
;
190
191
// get the robot position
192
robot.getPosition(wMc);
193
// Compute the position of the object frame in the camera frame
194
cMo
= wMc.
inverse
() * wMo;
195
196
// new point position
197
point.track(cMo);
198
// retrieve x,y and Z of the vpPoint structure
199
vpFeatureBuilder::create
(p, point);
200
201
// compute the control law
202
v
=
task
.computeControlLaw();
203
204
// send the camera velocity to the controller
205
robot.setVelocity(
vpRobot::CAMERA_FRAME
, v);
206
207
std::cout <<
"|| s - s* || = "
<< (
task
.getError()).sumSquare() << std::endl;
208
}
209
210
// Display task information
211
task
.print();
212
return
EXIT_SUCCESS;
213
}
214
catch
(
const
vpException
&e) {
215
std::cout <<
"Catch a ViSP exception: "
<<
e
<< std::endl;
216
return
EXIT_FAILURE;
217
}
218
#else
219
(void)argc;
220
(void)argv;
221
std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV"
<< std::endl;
222
return
EXIT_SUCCESS;
223
#endif
224
}
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
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_CAMERA
@ EYEINHAND_CAMERA
Definition
vpServo.h:176
vpSimulatorCamera
Class that defines the simplest robot: a free flying camera.
Definition
vpSimulatorCamera.h:113
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
servoSimuPoint2DCamVelocity1.cpp
Generated by
1.17.0