60 #include <visp/vpDebug.h>
61 #include <visp/vpConfig.h>
63 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
68 #include <visp/vpCameraParameters.h>
69 #include <visp/vpDisplayX.h>
70 #include <visp/vpDisplayGTK.h>
71 #include <visp/vpDisplayGDI.h>
72 #include <visp/vpDisplayOpenCV.h>
73 #include <visp/vpFeatureBuilder.h>
74 #include <visp/vpFeaturePointPolar.h>
75 #include <visp/vpHomogeneousMatrix.h>
76 #include <visp/vpImage.h>
77 #include <visp/vpImagePoint.h>
78 #include <visp/vpIoTools.h>
79 #include <visp/vpMath.h>
80 #include <visp/vpMeterPixelConversion.h>
81 #include <visp/vpProjectionDisplay.h>
82 #include <visp/vpServo.h>
83 #include <visp/vpServoDisplay.h>
84 #include <visp/vpSimulatorCamera.h>
85 #include <visp/vpParseArgv.h>
88 #define GETOPTARGS "cdh"
90 void usage(
const char *name,
const char *badparam);
91 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
101 void usage(
const char *name,
const char *badparam)
104 Tests a control law with the following characteristics:\n\
105 - eye-in-hand control\n\
106 - articular velocity are computed\n\
107 - servo on 4 points,\n\
108 - internal and external camera view displays.\n\
111 %s [-c] [-d] [-h]\n", name);
116 Disable the mouse click. Useful to automaze the \n\
117 execution of this program without humain intervention.\n\
120 Turn off the display.\n\
126 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
140 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
147 case 'c': click_allowed =
false;
break;
148 case 'd': display =
false;
break;
149 case 'h': usage(argv[0], NULL);
return false;
break;
152 usage(argv[0], optarg_);
157 if ((c == 1) || (c == -1)) {
159 usage(argv[0], NULL);
160 std::cerr <<
"ERROR: " << std::endl;
161 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
169 main(
int argc,
const char ** argv)
178 std::string username;
183 std::string logdirname;
185 logdirname =
"C:/temp/" + username;
187 logdirname =
"/tmp/" + username;
197 std::cerr << std::endl
198 <<
"ERROR:" << std::endl;
199 std::cerr <<
" Cannot create " << logdirname << std::endl;
203 std::string logfilename;
204 logfilename = logdirname +
"/log.dat";
207 std::ofstream flog(logfilename.c_str());
210 bool opt_click_allowed =
true;
211 bool opt_display =
true;
214 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
220 #if defined VISP_HAVE_X11
223 #elif defined VISP_HAVE_GTK
226 #elif defined VISP_HAVE_GDI
229 #elif defined VISP_HAVE_OPENCV
240 displayInt.
init(Iint,0,0,
"Internal view") ;
241 displayExt.
init(Iext,330,000,
"External view") ;
246 double px, py ; px = py = 500 ;
247 double u0, v0 ; u0 = 150, v0 = 160 ;
256 std::cout << std::endl ;
257 std::cout <<
"----------------------------------------------" << std::endl ;
258 std::cout <<
" Test program for vpServo " <<std::endl ;
259 std::cout <<
" Eye-in-hand task control, articular velocity are computed"
261 std::cout <<
" Simulation " << std::endl ;
262 std::cout <<
" task : servo 4 points " << std::endl ;
263 std::cout <<
"----------------------------------------------" << std::endl ;
264 std::cout << std::endl ;
273 #if defined(TRANS_Z_PURE)
280 #elif defined(TRANS_X_PURE)
288 #elif defined(ROT_Z_PURE)
296 #elif defined(ROT_X_PURE)
304 #elif defined(COMPLEX)
312 #elif defined(PROBLEM)
339 for (i = 0 ; i < 4 ; i++)
340 externalview.
insert(point[i]) ;
347 for (i = 0 ; i < 4 ; i++) {
348 point[i].
track(cMod);
357 for (i = 0 ; i < 4 ; i++)
358 point[i].track(cMo) ;
362 for (i = 0 ; i < 4 ; i++) {
388 for (i = 0 ; i < 4 ; i++)
395 std::cout <<
"\nDisplay task information: " << std::endl;
398 unsigned int iter=0 ;
400 while(iter++ < 200) {
401 std::cout <<
"---------------------------------------------"
402 << iter <<std::endl ;
417 for (i = 0 ; i < 4 ; i++) {
418 point[i].
track(cMo) ;
437 std::cout <<
"Display task information: " << std::endl;
449 flog << v[0] <<
" " << v[1] <<
" " << v[2] <<
" "
450 << v[3] <<
" " << v[4] <<
" " << v[5] <<
" ";
452 std::cout <<
"v: " << v.
t() << std::endl;
454 std::cout <<
"|| s - s* || = "<< ( task.
getError() ).sumSquare() << std::endl;
459 flog << ( task.
getError() ).t() <<
" ";
460 std::cout <<
"|| s - s* || = " << ( task.
getError() ).sumSquare() <<std::endl ;
463 for (i = 0 ; i < 4 ; i++) {
467 for (i = 0 ; i < 4 ; i++) {
468 flog << point[i].
get_x() <<
" " << point[i].
get_y() <<
" ";
477 std::cout <<
"\nClick in the internal camera view to continue..." << std::endl;
495 std::cout <<
"Final robot position with respect to the object frame:\n";
498 if (opt_display && opt_click_allowed) {
500 std::cout <<
"\n\nClick in the internal view to end..." << std::endl;
506 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
514 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)
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_)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
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)
The vpDisplayOpenCV allows to display image using the opencv library.
vpRowVector t() const
Transpose of a 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 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_)
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...