57 #include <visp/vpConfig.h>
59 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
64 #include <visp/vpCameraParameters.h>
65 #include <visp/vpCylinder.h>
66 #include <visp/vpDisplayX.h>
67 #include <visp/vpDisplayGTK.h>
68 #include <visp/vpDisplayGDI.h>
69 #include <visp/vpFeatureBuilder.h>
70 #include <visp/vpFeatureLine.h>
71 #include <visp/vpHomogeneousMatrix.h>
72 #include <visp/vpImage.h>
73 #include <visp/vpMath.h>
74 #include <visp/vpParseArgv.h>
75 #include <visp/vpProjectionDisplay.h>
76 #include <visp/vpServo.h>
77 #include <visp/vpSimulatorCamera.h>
78 #include <visp/vpServoDisplay.h>
81 #define GETOPTARGS "cdh"
92 void usage(
const char *name,
const char *badparam)
95 Simulation of a 2D visual servoing on a cylinder:\n\
96 - eye-in-hand control law,\n\
97 - velocity computed in the camera frame,\n\
98 - display the camera view.\n\
101 %s [-c] [-d] [-h]\n", name);
107 Disable the mouse click. Useful to automaze the \n\
108 execution of this program without humain intervention.\n\
111 Turn off the display.\n\
117 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
131 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
138 case 'c': click_allowed =
false;
break;
139 case 'd': display =
false;
break;
140 case 'h': usage(argv[0], NULL);
return false;
break;
143 usage(argv[0], optarg);
148 if ((c == 1) || (c == -1)) {
150 usage(argv[0], NULL);
151 std::cerr <<
"ERROR: " << std::endl;
152 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
161 main(
int argc,
const char ** argv)
163 bool opt_display =
true;
164 bool opt_click_allowed =
true;
167 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
175 #if defined VISP_HAVE_X11
178 #elif defined VISP_HAVE_GTK
181 #elif defined VISP_HAVE_GDI
189 displayInt.
init(Iint, 100, 100,
"Internal view") ;
190 displayExt.
init(Iext, (
int)(130+Iint.
getWidth()), 100,
"External view") ;
211 double px, py ; px = py = 600 ;
212 double u0, v0 ; u0 = v0 = 256 ;
236 externalview.
insert(cylinder) ;
239 cylinder.track(cMod) ;
245 for(i=0 ; i < 2 ; i++)
250 cylinder.track(cMo) ;
255 for(i=0 ; i < 2 ; i++)
290 if (opt_display && opt_click_allowed) {
291 std::cout <<
"\n\nClick in the internal camera view window to start..." << std::endl;
301 unsigned int iter=0 ;
305 std::cout <<
"---------------------------------------------" << iter++ <<std::endl ;
316 cylinder.track(cMo) ;
319 for(i=0 ; i < 2 ; i++)
340 std::cout <<
"|| s - s* || = " << ( task.
getError() ).sumSquare() <<std::endl ;
342 while(( task.
getError() ).sumSquare() > 1e-9) ;
358 double vitesse = 0.5;
359 unsigned int tempo = 800;
369 cylinder.track(cMo) ;
371 for(i=0 ; i < 2 ; i++)
388 if ( iter%tempo < 200 /*&& iter%tempo >= 0*/)
391 e1[0] = fabs(vitesse) ;
393 rapport = vitesse/proj_e1[0];
398 if ( iter%tempo < 400 && iter%tempo >= 200)
401 e2[1] = fabs(vitesse) ;
403 rapport = vitesse/proj_e2[1];
408 if ( iter%tempo < 600 && iter%tempo >= 400)
411 e1[0] = -fabs(vitesse) ;
413 rapport = -vitesse/proj_e1[0];
418 if ( iter%tempo < 800 && iter%tempo >= 600)
421 e2[1] = -fabs(vitesse) ;
423 rapport = -vitesse/proj_e2[1];
430 std::cout <<
"|| s - s* || = " << ( task.
getError() ).sumSquare() <<std::endl ;
435 if (opt_display && opt_click_allowed) {
436 std::cout <<
"\nClick in the internal camera view window to end..." << std::endl;
450 std::cout <<
"You do not have X11, GTK or GDI display functionalities..." << std::endl;