60 #include <visp/vpDebug.h>
61 #include <visp/vpConfig.h>
63 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
68 #include <visp/vpCameraParameters.h>
69 #include <visp/vpDisplayX.h>
70 #include <visp/vpDisplayGTK.h>
71 #include <visp/vpDisplayGDI.h>
72 #include <visp/vpFeatureBuilder.h>
73 #include <visp/vpFeaturePointPolar.h>
74 #include <visp/vpHomogeneousMatrix.h>
75 #include <visp/vpImage.h>
76 #include <visp/vpImagePoint.h>
77 #include <visp/vpIoTools.h>
78 #include <visp/vpMath.h>
79 #include <visp/vpMeterPixelConversion.h>
80 #include <visp/vpProjectionDisplay.h>
81 #include <visp/vpServo.h>
82 #include <visp/vpServoDisplay.h>
83 #include <visp/vpSimulatorCamera.h>
84 #include <visp/vpParseArgv.h>
87 #define GETOPTARGS "cdh"
89 void usage(
const char *name,
const char *badparam);
90 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
100 void usage(
const char *name,
const char *badparam)
103 Tests a control law with the following characteristics:\n\
104 - eye-in-hand control\n\
105 - articular velocity are computed\n\
106 - servo on 4 points,\n\
107 - internal and external camera view displays.\n\
110 %s [-c] [-d] [-h]\n", name);
115 Disable the mouse click. Useful to automaze the \n\
116 execution of this program without humain intervention.\n\
119 Turn off the display.\n\
125 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
139 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
146 case 'c': click_allowed =
false;
break;
147 case 'd': display =
false;
break;
148 case 'h': usage(argv[0], NULL);
return false;
break;
151 usage(argv[0], optarg_);
156 if ((c == 1) || (c == -1)) {
158 usage(argv[0], NULL);
159 std::cerr <<
"ERROR: " << std::endl;
160 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
168 main(
int argc,
const char ** argv)
177 std::string username;
182 std::string logdirname;
184 logdirname =
"C:/temp/" + username;
186 logdirname =
"/tmp/" + username;
196 std::cerr << std::endl
197 <<
"ERROR:" << std::endl;
198 std::cerr <<
" Cannot create " << logdirname << std::endl;
202 std::string logfilename;
203 logfilename = logdirname +
"/log.dat";
206 std::ofstream flog(logfilename.c_str());
209 bool opt_click_allowed =
true;
210 bool opt_display =
true;
213 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
219 #if defined VISP_HAVE_X11
222 #elif defined VISP_HAVE_GTK
225 #elif defined VISP_HAVE_GDI
236 displayInt.
init(Iint,0,0,
"Internal view") ;
237 displayExt.
init(Iext,330,000,
"External view") ;
242 double px, py ; px = py = 500 ;
243 double u0, v0 ; u0 = 150, v0 = 160 ;
252 std::cout << std::endl ;
253 std::cout <<
"----------------------------------------------" << std::endl ;
254 std::cout <<
" Test program for vpServo " <<std::endl ;
255 std::cout <<
" Eye-in-hand task control, articular velocity are computed"
257 std::cout <<
" Simulation " << std::endl ;
258 std::cout <<
" task : servo 4 points " << std::endl ;
259 std::cout <<
"----------------------------------------------" << std::endl ;
260 std::cout << std::endl ;
269 #if defined(TRANS_Z_PURE)
276 #elif defined(TRANS_X_PURE)
284 #elif defined(ROT_Z_PURE)
292 #elif defined(ROT_X_PURE)
300 #elif defined(COMPLEX)
308 #elif defined(PROBLEM)
335 for (i = 0 ; i < 4 ; i++)
336 externalview.
insert(point[i]) ;
343 for (i = 0 ; i < 4 ; i++) {
344 point[i].
track(cMod);
353 for (i = 0 ; i < 4 ; i++)
354 point[i].track(cMo) ;
358 for (i = 0 ; i < 4 ; i++) {
384 for (i = 0 ; i < 4 ; i++)
391 std::cout <<
"\nDisplay task information: " << std::endl;
394 unsigned int iter=0 ;
396 while(iter++ < 200) {
397 std::cout <<
"---------------------------------------------"
398 << iter <<std::endl ;
413 for (i = 0 ; i < 4 ; i++) {
414 point[i].
track(cMo) ;
433 std::cout <<
"Display task information: " << std::endl;
445 flog << v[0] <<
" " << v[1] <<
" " << v[2] <<
" "
446 << v[3] <<
" " << v[4] <<
" " << v[5] <<
" ";
448 std::cout <<
"v: " << v.
t() << std::endl;
450 std::cout <<
"|| s - s* || = "<< ( task.
getError() ).sumSquare() << std::endl;
455 flog << ( task.
getError() ).t() <<
" ";
456 std::cout <<
"|| s - s* || = " << ( task.
getError() ).sumSquare() <<std::endl ;
459 for (i = 0 ; i < 4 ; i++) {
463 for (i = 0 ; i < 4 ; i++) {
464 flog << point[i].
get_x() <<
" " << point[i].
get_y() <<
" ";
473 std::cout <<
"\nClick in the internal camera view to continue..." << std::endl;
491 std::cout <<
"Final robot position with respect to the object frame:\n";
494 if (opt_display && opt_click_allowed) {
496 std::cout <<
"\n\nClick in the internal view to end..." << std::endl;
502 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
510 vpERROR_TRACE(
"You do not have X11, GTK or GDI display functionalities...");
Definition of the vpMatrix class.
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)
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).
void set_eJe(const vpMatrix &eJe_)
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.
void track(const vpHomogeneousMatrix &cMo)
double get_y() const
Get the point y coordinate in the image plane.
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
Class that defines 2D image point visual feature with polar coordinates described in ...
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that defines what is a point.
void set_i(const double ii)
vpColVector getError() const
vpColVector computeControlLaw()
static void display(const vpImage< unsigned char > &I)
vpRowVector t() const
transpose of Vector
Generic class defining intrinsic camera parameters.
void getPosition(vpHomogeneousMatrix &wMc) const
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
double get_x() const
Get the point x coordinate in the image plane.
void insert(vpForwardProjection &fp)
Class that consider the particular case of twist transformation matrix that allows to transform a vel...
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)
static double rad(double deg)
void set_j(const double jj)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
void set_cVe(const vpVelocityTwistMatrix &cVe_)
virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)=0
vpHomogeneousMatrix inverse() const
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
virtual bool getClick(bool blocking=true)=0
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
void get_eJe(vpMatrix &eJe)
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)
void setWorldCoordinates(const double ox, const double oy, const double oz)
Set the point world coordinates. We mean here the coordinates of the point in the object frame...