Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
servoSimuCircle2DCamVelocity.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 circle.
32
*/
41
50
51
#include <stdio.h>
52
#include <stdlib.h>
53
54
#include <visp3/core/vpCircle.h>
55
#include <visp3/core/vpConfig.h>
56
#include <visp3/core/vpHomogeneousMatrix.h>
57
#include <visp3/core/vpMath.h>
58
#include <visp3/io/vpParseArgv.h>
59
#include <visp3/robot/vpSimulatorCamera.h>
60
#include <visp3/visual_features/vpFeatureBuilder.h>
61
#include <visp3/visual_features/vpFeatureEllipse.h>
62
#include <visp3/vs/vpServo.h>
63
64
// List of allowed command line options
65
#define GETOPTARGS "h"
66
67
#ifdef ENABLE_VISP_NAMESPACE
68
using namespace
VISP_NAMESPACE_NAME
;
69
#endif
70
71
void
usage(
const
char
*name,
const
char
*badparam);
72
bool
getOptions(
int
argc,
const
char
**argv);
73
82
void
usage(
const
char
*name,
const
char
*badparam)
83
{
84
fprintf(stdout,
"\n\
85
Simulation of a 2D visual servoing on a circle:\n\
86
- eye-in-hand control law,\n\
87
- velocity computed in the camera frame,\n\
88
- without display.\n\
89
\n\
90
SYNOPSIS\n\
91
%s [-h]\n"
,
92
name);
93
94
fprintf(stdout,
"\n\
95
OPTIONS: Default\n\
96
\n\
97
-h\n\
98
Print the help.\n"
);
99
100
if
(badparam)
101
fprintf(stdout,
"\nERROR: Bad parameter [%s]\n"
, badparam);
102
}
103
113
bool
getOptions(
int
argc,
const
char
**argv)
114
{
115
const
char
*optarg_;
116
int
c;
117
while
((c =
vpParseArgv::parse
(argc, argv, GETOPTARGS, &optarg_)) > 1) {
118
119
switch
(c) {
120
case
'h'
:
121
usage(argv[0],
nullptr
);
122
return
false
;
123
124
default
:
125
usage(argv[0], optarg_);
126
return
false
;
127
}
128
}
129
130
if
((c == 1) || (c == -1)) {
131
// standalone param or error
132
usage(argv[0],
nullptr
);
133
std::cerr <<
"ERROR: "
<< std::endl;
134
std::cerr <<
" Bad argument "
<< optarg_ << std::endl << std::endl;
135
return
false
;
136
}
137
138
return
true
;
139
}
140
141
int
main(
int
argc,
const
char
**argv)
142
{
143
#if (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
144
try
{
145
// Read the command line options
146
if
(getOptions(argc, argv) ==
false
) {
147
return
EXIT_FAILURE;
148
}
149
150
vpServo
task
;
151
vpSimulatorCamera
robot;
152
153
std::cout << std::endl;
154
std::cout <<
"-------------------------------------------------------"
<< std::endl;
155
std::cout <<
" Test program for vpServo "
<< std::endl;
156
std::cout <<
" Simulation "
<< std::endl;
157
std::cout <<
" task : servo a circle "
<< 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
167
vpHomogeneousMatrix
wMc, wMo;
168
robot.getPosition(wMc);
169
wMo = wMc *
cMo
;
// Compute the position of the object in the world frame
170
171
vpHomogeneousMatrix
cMod;
172
cMod[0][3] = 0;
173
cMod[1][3] = 0;
174
cMod[2][3] = 1;
175
176
// sets the circle coordinates in the world frame
177
vpCircle
circle;
178
circle.
setWorldCoordinates
(0, 0, 1, 0, 0, 0, 0.1);
179
180
// sets the desired position of the visual feature
181
vpFeatureEllipse
pd;
182
circle.
track
(cMod);
183
vpFeatureBuilder::create
(pd, circle);
184
185
// project : computes the circle coordinates in the camera frame and its
186
// 2D coordinates
187
188
// sets the current position of the visual feature
189
vpFeatureEllipse
p
;
190
circle.
track
(cMo);
191
vpFeatureBuilder::create
(p, circle);
192
193
// define the task
194
// - we want an eye-in-hand control law
195
// - robot is controlled in the camera frame
196
task
.setServo(
vpServo::EYEINHAND_CAMERA
);
197
198
// - we want to see a circle on a circle
199
std::cout << std::endl;
200
task
.addFeature(p, pd);
201
202
// - set the gain
203
task
.setLambda(1);
204
205
// Display task information
206
task
.print();
207
208
unsigned
int
iter
= 0;
209
// loop
210
while
(iter++ < 500) {
211
std::cout <<
"---------------------------------------------"
<<
iter
<< std::endl;
212
vpColVector
v
;
213
214
// get the robot position
215
robot.getPosition(wMc);
216
// Compute the position of the object frame in the camera frame
217
cMo
= wMc.
inverse
() * wMo;
218
219
// new circle position: retrieve x,y and Z of the vpCircle structure
220
circle.
track
(cMo);
221
vpFeatureBuilder::create
(p, circle);
222
223
// compute the control law
224
v
=
task
.computeControlLaw();
225
std::cout <<
"task rank: "
<<
task
.getTaskRank() << std::endl;
226
// send the camera velocity to the controller
227
robot.setVelocity(
vpRobot::CAMERA_FRAME
, v);
228
229
std::cout <<
"|| s - s* || = "
<< (
task
.getError()).sumSquare() << std::endl;
230
}
231
232
// Display task information
233
task
.print();
234
return
EXIT_SUCCESS;
235
}
236
catch
(
const
vpException
&e) {
237
std::cout <<
"Catch a ViSP exception: "
<<
e
<< std::endl;
238
return
EXIT_FAILURE;
239
}
240
#else
241
(void)argc;
242
(void)argv;
243
std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV"
<< std::endl;
244
return
EXIT_SUCCESS;
245
#endif
246
}
vpCircle
Class that defines a 3D circle in the object frame and allows forward projection of a 3D circle in th...
Definition
vpCircle.h:87
vpCircle::setWorldCoordinates
void setWorldCoordinates(const vpColVector &oP) VP_OVERRIDE
Definition
vpCircle.cpp:58
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
vpFeatureEllipse
Class that defines 2D ellipse visual feature.
Definition
vpFeatureEllipse.h:56
vpForwardProjection::track
void track(const vpHomogeneousMatrix &cMo)
Definition
vpForwardProjection.cpp:101
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
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
servoSimuCircle2DCamVelocity.cpp
Generated by
1.17.0