Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
servoSimuThetaUCamVelocity.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 visual servoing using theta U visual features.
32
* tests the control law
33
* eye-in-hand control
34
* velocity computed in the camera frame
35
* using theta U visual feature
36
*/
37
45
46
#include <stdio.h>
47
#include <stdlib.h>
48
49
#include <visp3/core/vpConfig.h>
50
#include <visp3/core/vpHomogeneousMatrix.h>
51
#include <visp3/core/vpMath.h>
52
#include <visp3/io/vpParseArgv.h>
53
#include <visp3/robot/vpSimulatorCamera.h>
54
#include <visp3/visual_features/vpFeatureThetaU.h>
55
#include <visp3/visual_features/vpFeatureTranslation.h>
56
#include <visp3/vs/vpServo.h>
57
58
// List of allowed command line options
59
#define GETOPTARGS "h"
60
61
#ifdef ENABLE_VISP_NAMESPACE
62
using namespace
VISP_NAMESPACE_NAME
;
63
#endif
64
65
void
usage(
const
char
*name,
const
char
*badparam);
66
bool
getOptions(
int
argc,
const
char
**argv);
75
void
usage(
const
char
*name,
const
char
*badparam)
76
{
77
fprintf(stdout,
"\n\
78
Simulation of avisual servoing using theta U visual feature:\n\
79
- eye-in-hand control law,\n\
80
- velocity computed in the camera frame,\n\
81
- without display.\n\
82
\n\
83
SYNOPSIS\n\
84
%s [-h]\n"
,
85
name);
86
87
fprintf(stdout,
"\n\
88
OPTIONS: Default\n\
89
\n\
90
-h\n\
91
Print the help.\n"
);
92
93
if
(badparam)
94
fprintf(stdout,
"\nERROR: Bad parameter [%s]\n"
, badparam);
95
}
96
107
bool
getOptions(
int
argc,
const
char
**argv)
108
{
109
const
char
*optarg_;
110
int
c;
111
while
((c =
vpParseArgv::parse
(argc, argv, GETOPTARGS, &optarg_)) > 1) {
112
113
switch
(c) {
114
case
'h'
:
115
usage(argv[0],
nullptr
);
116
return
false
;
117
118
default
:
119
usage(argv[0], optarg_);
120
return
false
;
121
}
122
}
123
124
if
((c == 1) || (c == -1)) {
125
// standalone param or error
126
usage(argv[0],
nullptr
);
127
std::cerr <<
"ERROR: "
<< std::endl;
128
std::cerr <<
" Bad argument "
<< optarg_ << std::endl << std::endl;
129
return
false
;
130
}
131
132
return
true
;
133
}
134
135
int
main(
int
argc,
const
char
**argv)
136
{
137
#if (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
138
try
{
139
// Read the command line options
140
if
(getOptions(argc, argv) ==
false
) {
141
return
EXIT_FAILURE;
142
}
143
144
vpServo
task
;
145
vpSimulatorCamera
robot;
146
147
std::cout << std::endl;
148
std::cout <<
"-------------------------------------------------------"
<< std::endl;
149
std::cout <<
" Test program for vpServo "
<< std::endl;
150
std::cout <<
" Eye-in-hand task control, velocity computed in the camera frame"
<< std::endl;
151
std::cout <<
" Simulation "
<< std::endl;
152
std::cout <<
" task : servo using theta U visual feature "
<< std::endl;
153
std::cout <<
"-------------------------------------------------------"
<< std::endl;
154
std::cout << std::endl;
155
156
// sets the initial camera location
157
vpPoseVector
c_r_o(0.1, 0.2, 2,
vpMath::rad
(20),
vpMath::rad
(10),
vpMath::rad
(50));
158
159
vpHomogeneousMatrix
cMo
(c_r_o);
160
// Compute the position of the object in the world frame
161
vpHomogeneousMatrix
wMc, wMo;
162
robot.getPosition(wMc);
163
wMo = wMc *
cMo
;
164
165
// sets the desired camera location
166
vpPoseVector
cd_r_o(0, 0, 1,
vpMath::rad
(0),
vpMath::rad
(0),
vpMath::rad
(0));
167
vpHomogeneousMatrix
cdMo(cd_r_o);
168
169
// compute the rotation that the camera has to realize
170
vpHomogeneousMatrix
cdMc;
171
cdMc = cdMo *
cMo
.inverse();
172
vpFeatureThetaU
tu
(
vpFeatureThetaU::cdRc
);
173
tu
.buildFrom(cdMc);
174
175
// define the task
176
// - we want an eye-in-hand control law
177
// - robot is controlled in the camera frame
178
task
.setServo(
vpServo::EYEINHAND_CAMERA
);
179
task
.setInteractionMatrixType(
vpServo::DESIRED
);
180
181
task
.addFeature(tu);
182
183
// - set the gain
184
task
.setLambda(1);
185
186
// Display task information
187
task
.print();
188
189
unsigned
int
iter
= 0;
190
// loop
191
while
(iter++ < 200) {
192
std::cout <<
"---------------------------------------------"
<<
iter
<< std::endl;
193
vpColVector
v
;
194
195
// get the robot position
196
robot.getPosition(wMc);
197
// Compute the position of the object frame in the camera frame
198
cMo
= wMc.
inverse
() * wMo;
199
200
// new rotation to achieve
201
cdMc = cdMo *
cMo
.inverse();
202
tu
.buildFrom(cdMc);
203
204
// compute the control law
205
v
=
task
.computeControlLaw();
206
207
// send the camera velocity to the controller
208
robot.setVelocity(
vpRobot::CAMERA_FRAME
, v);
209
210
std::cout <<
"|| s - s* || = "
<< (
task
.getError()).sumSquare() << std::endl;
211
}
212
213
// Display task information
214
task
.print();
215
return
EXIT_SUCCESS;
216
}
217
catch
(
const
vpException
&e) {
218
std::cout <<
"Catch a ViSP exception: "
<<
e
<< std::endl;
219
return
EXIT_FAILURE;
220
}
221
#else
222
(void)argc;
223
(void)argv;
224
std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV"
<< std::endl;
225
return
EXIT_SUCCESS;
226
#endif
227
}
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
vpFeatureThetaU
Class that defines a 3D visual feature from a axis/angle parametrization that represent the rotati...
Definition
vpFeatureThetaU.h:227
vpFeatureThetaU::cdRc
@ cdRc
Definition
vpFeatureThetaU.h:240
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
vpMath::rad
static double rad(double deg)
Definition
vpMath.h:129
vpParseArgv::parse
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition
vpParseArgv.cpp:70
vpPoseVector
Implementation of a pose vector and operations on poses.
Definition
vpPoseVector.h:203
vpRobot::CAMERA_FRAME
@ CAMERA_FRAME
Definition
vpRobot.h:81
vpServo
Definition
vpServo.h:159
vpServo::EYEINHAND_CAMERA
@ EYEINHAND_CAMERA
Definition
vpServo.h:176
vpServo::DESIRED
@ DESIRED
Definition
vpServo.h:223
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.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
pbvs-four-points.tu
tu
Definition
pbvs-four-points.py:221
realsense-mbt.cMo
cMo
Definition
realsense-mbt.py:212
example
robot-simulator
camera
servoSimuThetaUCamVelocity.cpp
Generated by
1.17.0