Demonstration of the wireframe simulator with a simple visual servoing.
#include <stdlib.h>
#include <cmath>
#include <limits>
#include <visp/vpCameraParameters.h>
#include <visp/vpDisplayOpenCV.h>
#include <visp/vpDisplayX.h>
#include <visp/vpDisplayGTK.h>
#include <visp/vpDisplayGDI.h>
#include <visp/vpDisplayD3D.h>
#include <visp/vpFeatureBuilder.h>
#include <visp/vpGenericFeature.h>
#include <visp/vpHomogeneousMatrix.h>
#include <visp/vpImage.h>
#include <visp/vpImageIo.h>
#include <visp/vpIoTools.h>
#include <visp/vpMath.h>
#include <visp/vpParseArgv.h>
#include <visp/vpRobotCamera.h>
#include <visp/vpServo.h>
#include <visp/vpSphere.h>
#include <visp/vpTime.h>
#include <visp/vpVelocityTwistMatrix.h>
#include <visp/vpWireFrameSimulator.h>
#define GETOPTARGS "dh"
#ifdef VISP_HAVE_DISPLAY
void usage(const char *name, const char *badparam);
bool getOptions(int argc, const char **argv, bool &display);
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] [-h]\n", name);
fprintf(stdout, "\n\
OPTIONS: Default\n\
-d \n\
Turn off the display.\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)
{
const char *optarg_;
int c;
switch (c) {
case 'd': display = false; break;
case 'h': usage(argv[0], NULL); return false; break;
default:
usage(argv[0], optarg_);
return false; break;
}
}
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*m20);
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;
if (getOptions(argc, argv, opt_display) == 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.040f;
computeVisualFeatures(sphere, s);
computeVisualFeatures(sphere, sd);
computeInteractionMatrix(sd,sphere,L);
sd.setInteractionMatrix(L);
int stop = 10;
if (opt_display)
{
stop = 1000;
std::cout << "Click on a display" << std::endl;
}
int iter = 0;
while(iter++ < stop)
{
if (opt_display)
{
}
cMo = cMw * wMo;
computeVisualFeatures(sphere, s);
if (opt_display)
{
}
std::cout <<
"|| s - s* || = " << ( task.
getError() ).sumSquare() <<std::endl ;
}
return 0;
}
std::cout << "Catch an exception: " << e << std::endl;
return 1;
}
}
#else
int
main()
{
vpERROR_TRACE(
"You do not have X11, OpenCV, GDI, D3D9 or GTK display functionalities...");
}
#endif