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;
static void display(vpServo &s, const vpCameraParameters &cam, vpImage< unsigned char > &I, vpColor currentColor=vpColor::green, vpColor desiredColor=vpColor::red, unsigned int thickness=1)
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)
create a new ste of two visual features
void setLambda(double _lambda)
set the gain lambda
vpColVector secondaryTask(vpColVector &de2dt)
Add a secondary task.
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void kill()
destruction (memory deallocation if required)
vpColVector getError() const
vpColVector computeControlLaw()
compute the desired control law
static void display(const vpImage< unsigned char > &I)
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 init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
Set the type of the interaction matrix (current, mean, desired, user).
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)
Class required to compute the visual servoing control law descbribed in and .
interface with the image for feature display
void setServo(vpServoType _servo_type)
Choice of the visual servoing control law.