57 #include <visp/vpConfig.h>
59 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
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/vpDisplayOpenCV.h>
70 #include <visp/vpFeatureBuilder.h>
71 #include <visp/vpFeatureLine.h>
72 #include <visp/vpHomogeneousMatrix.h>
73 #include <visp/vpImage.h>
74 #include <visp/vpMath.h>
75 #include <visp/vpParseArgv.h>
76 #include <visp/vpProjectionDisplay.h>
77 #include <visp/vpServo.h>
78 #include <visp/vpSimulatorCamera.h>
79 #include <visp/vpServoDisplay.h>
82 #define GETOPTARGS "cdh"
84 void usage(
const char *name,
const char *badparam);
85 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
95 void usage(
const char *name,
const char *badparam)
98 Simulation of a 2D visual servoing on a cylinder:\n\
99 - eye-in-hand control law,\n\
100 - velocity computed in the camera frame,\n\
101 - display the camera view.\n\
104 %s [-c] [-d] [-h]\n", name);
110 Disable the mouse click. Useful to automaze the \n\
111 execution of this program without humain intervention.\n\
114 Turn off the display.\n\
120 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
134 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
141 case 'c': click_allowed =
false;
break;
142 case 'd': display =
false;
break;
143 case 'h': usage(argv[0], NULL);
return false;
break;
146 usage(argv[0], optarg_);
151 if ((c == 1) || (c == -1)) {
153 usage(argv[0], NULL);
154 std::cerr <<
"ERROR: " << std::endl;
155 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
164 main(
int argc,
const char ** argv)
167 bool opt_display =
true;
168 bool opt_click_allowed =
true;
171 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
179 #if defined VISP_HAVE_X11
182 #elif defined VISP_HAVE_GTK
185 #elif defined VISP_HAVE_GDI
188 #elif defined VISP_HAVE_OPENCV
196 displayInt.
init(Iint, 100, 100,
"Internal view") ;
197 displayExt.
init(Iext, (
int)(130+Iint.
getWidth()), 100,
"External view") ;
218 double px, py ; px = py = 600 ;
219 double u0, v0 ; u0 = v0 = 256 ;
243 externalview.
insert(cylinder) ;
246 cylinder.track(cMod) ;
252 for(i=0 ; i < 2 ; i++)
257 cylinder.track(cMo) ;
262 for(i=0 ; i < 2 ; i++)
297 if (opt_display && opt_click_allowed) {
298 std::cout <<
"\n\nClick in the internal camera view window to start..." << std::endl;
308 unsigned int iter=0 ;
312 std::cout <<
"---------------------------------------------" << iter++ <<std::endl ;
323 cylinder.track(cMo) ;
326 for(i=0 ; i < 2 ; i++)
347 std::cout <<
"|| s - s* || = " << ( task.
getError() ).sumSquare() <<std::endl ;
349 while(( task.
getError() ).sumSquare() > 1e-9) ;
365 double vitesse = 0.5;
366 unsigned int tempo = 800;
376 cylinder.track(cMo) ;
378 for(i=0 ; i < 2 ; i++)
395 if ( iter%tempo < 200 /*&& iter%tempo >= 0*/)
398 e1[0] = fabs(vitesse) ;
400 rapport = vitesse/proj_e1[0];
405 if ( iter%tempo < 400 && iter%tempo >= 200)
408 e2[1] = fabs(vitesse) ;
410 rapport = vitesse/proj_e2[1];
415 if ( iter%tempo < 600 && iter%tempo >= 400)
418 e1[0] = -fabs(vitesse) ;
420 rapport = -vitesse/proj_e1[0];
425 if ( iter%tempo < 800 && iter%tempo >= 600)
428 e2[1] = -fabs(vitesse) ;
430 rapport = -vitesse/proj_e2[1];
437 std::cout <<
"|| s - s* || = " << ( task.
getError() ).sumSquare() <<std::endl ;
442 if (opt_display && opt_click_allowed) {
443 std::cout <<
"\nClick in the internal camera view window to end..." << std::endl;
453 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
463 std::cout <<
"You do not have X11, GTK, GDI or OpenCV display functionalities..." << std::endl;
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
void display(vpImage< unsigned char > &I, const vpHomogeneousMatrix &cextMo, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &color, const bool &displayTraj=false, const unsigned int thickness=1)
unsigned int getWidth() const
void print(const unsigned int select=FEATURE_ALL) const
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
Class that defines the simplest robot: a free flying camera.
Display for windows using GDI (available on any windows 32 platform).
Define the X11 console to display images.
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, const unsigned int select=vpBasicFeature::FEATURE_ALL)
error that can be emited by ViSP classes.
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
vpColVector secondaryTask(const vpColVector &de2dt)
vpColVector getError() const
vpColVector computeControlLaw()
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
Generic class defining intrinsic camera parameters.
void getPosition(vpHomogeneousMatrix &wMc) const
Class that defines a 2D line visual feature which is composed by two parameters that are and ...
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void insert(vpForwardProjection &fp)
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
static double rad(double deg)
Class that defines what is a cylinder.
Class that provides a data structure for the column vectors as well as a set of operations on these v...
vpHomogeneousMatrix inverse() const
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
virtual bool getClick(bool blocking=true)=0
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
interface with the image for feature display
void setServo(const vpServoType &servo_type)
static void display(const vpServo &s, const vpCameraParameters &cam, const vpImage< unsigned char > &I, vpColor currentColor=vpColor::green, vpColor desiredColor=vpColor::red, unsigned int thickness=1)