Demonstration of the wireframe simulator with a simple visual servoing.
#include <cmath>
#include <limits>
#include <stdlib.h>
#include <visp3/core/vpCameraParameters.h>
#include <visp3/core/vpHomogeneousMatrix.h>
#include <visp3/core/vpImage.h>
#include <visp3/core/vpIoTools.h>
#include <visp3/core/vpMath.h>
#include <visp3/core/vpSphere.h>
#include <visp3/core/vpTime.h>
#include <visp3/core/vpVelocityTwistMatrix.h>
#include <visp3/gui/vpDisplayD3D.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayGTK.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/gui/vpPlot.h>
#include <visp3/io/vpImageIo.h>
#include <visp3/io/vpParseArgv.h>
#include <visp3/robot/vpSimulatorCamera.h>
#include <visp3/robot/vpWireFrameSimulator.h>
#include <visp3/visual_features/vpFeatureBuilder.h>
#include <visp3/visual_features/vpGenericFeature.h>
#include <visp3/vs/vpServo.h>
#define GETOPTARGS "dhp"
#if defined(VISP_HAVE_DISPLAY) \
&& (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
void usage(const char *name, const char *badparam)
{
fprintf(stdout, "\n\
Demonstration of the wireframe simulator with a simple visual servoing.\n\
\n\
The visual servoing consists in bringing the camera at a desired position from the object.\n\
\n\
The visual features used to compute the pose of the camera and thus the control law are special moments computed with the sphere's parameters.\n\
\n\
SYNOPSIS\n\
%s [-d] [-p] [-h]\n", name);
fprintf(stdout, "\n\
OPTIONS: Default\n\
-d \n\
Turn off the display.\n\
\n\
-p \n\
Turn off the plotter.\n\
\n\
-h\n\
Print the help.\n");
if (badparam)
fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
}
bool getOptions(int argc, const char **argv, bool &display, bool &plot)
{
const char *optarg_;
int c;
switch (c) {
case 'd':
display = false;
break;
case 'p':
plot = false;
break;
case 'h':
usage(argv[0], NULL);
return false;
default:
usage(argv[0], optarg_);
return false;
}
}
if ((c == 1) || (c == -1)) {
usage(argv[0], NULL);
std::cerr << "ERROR: " << std::endl;
std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
return false;
}
return true;
}
{
double gx = sphere.
get_x();
double gy = sphere.
get_y();
double h2;
if (std::fabs(gx) > std::numeric_limits<double>::epsilon() || std::fabs(gy) > std::numeric_limits<double>::epsilon())
else
h2 = 1 / (4 * n20);
double sx = gx * h2 / (sqrt(h2 + 1));
double sy = gy * h2 / (sqrt(h2 + 1));
double sz = sqrt(h2 + 1);
}
{
L = 0;
L[0][0] = -1 / sphere.
getR();
L[1][1] = -1 / sphere.
getR();
L[2][2] = -1 / sphere.
getR();
double s0, s1, s2;
for (unsigned int i = 0; i < 3; i++)
for (unsigned int j = 0; j < 3; j++)
L[i][j + 3] = sk[i][j];
}
int main(int argc, const char **argv)
{
try {
bool opt_display = true;
bool opt_plot = true;
if (getOptions(argc, argv, opt_display, opt_plot) == false) {
exit(-1);
}
#if defined VISP_HAVE_X11
#elif defined VISP_HAVE_OPENCV
#elif defined VISP_HAVE_GDI
#elif defined VISP_HAVE_D3D9
#elif defined VISP_HAVE_GTK
#endif
if (opt_display) {
display[0].
init(Iint, 100, 100,
"The internal view");
display[1].
init(Iext1, 100, 100,
"The first external view");
display[2].
init(Iext2, 100, 100,
"The second external view");
}
float sampling_time = 0.020f;
computeVisualFeatures(sphere, s);
computeVisualFeatures(sphere, sd);
computeInteractionMatrix(sd, sphere, L);
if (opt_plot) {
plotter =
new vpPlot(2, 480, 640, 750, 550,
"Real time curves plotter");
plotter->
setTitle(0,
"Visual features error");
plotter->
setTitle(1,
"Camera velocities");
}
int max_iter = 10;
if (opt_display) {
max_iter = 1000;
std::cout << "Click on a display" << std::endl;
};
}
int iter = 0;
bool stop = false;
while (iter++ < max_iter && !stop) {
t_prev = t;
if (opt_display) {
}
computeVisualFeatures(sphere, s);
if (opt_plot) {
plotter->
plot(1, iter, v);
}
if (opt_display) {
std::stringstream ss;
ss << "Loop time: " << t - t_prev << " ms";
stop = true;
}
}
std::cout <<
"|| s - s* || = " << (task.
getError()).sumSquare() << std::endl;
}
if (opt_plot && plotter != NULL) {
stop = true;
}
delete plotter;
}
return EXIT_SUCCESS;
std::cout << "Catch an exception: " << e << std::endl;
return EXIT_FAILURE;
}
}
#elif !(defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
int main()
{
std::cout << "Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
return EXIT_SUCCESS;
}
#else
int main()
{
std::cout << "You do not have X11, or GDI (Graphical Device Interface), or GTK functionalities to display images..." << std::endl;
std::cout << "Tip if you are on a unix-like system:" << std::endl;
std::cout << "- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
std::cout << "Tip if you are on a windows-like system:" << std::endl;
std::cout << "- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
return EXIT_SUCCESS;
}
#endif