56 #include <visp3/core/vpDebug.h> 57 #include <visp3/core/vpConfig.h> 59 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)) 64 #include <visp3/core/vpCameraParameters.h> 65 #include <visp3/gui/vpDisplayX.h> 66 #include <visp3/gui/vpDisplayGTK.h> 67 #include <visp3/gui/vpDisplayGDI.h> 68 #include <visp3/gui/vpDisplayOpenCV.h> 69 #include <visp3/visual_features/vpFeatureBuilder.h> 70 #include <visp3/visual_features/vpFeaturePointPolar.h> 71 #include <visp3/core/vpHomogeneousMatrix.h> 72 #include <visp3/core/vpImage.h> 73 #include <visp3/core/vpImagePoint.h> 74 #include <visp3/core/vpIoTools.h> 75 #include <visp3/core/vpMath.h> 76 #include <visp3/core/vpMeterPixelConversion.h> 77 #include <visp3/gui/vpProjectionDisplay.h> 78 #include <visp3/vs/vpServo.h> 79 #include <visp3/vs/vpServoDisplay.h> 80 #include <visp3/robot/vpSimulatorCamera.h> 81 #include <visp3/io/vpParseArgv.h> 84 #define GETOPTARGS "cdh" 86 void usage(
const char *name,
const char *badparam);
87 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
97 void usage(
const char *name,
const char *badparam)
100 Tests a control law with the following characteristics:\n\ 101 - eye-in-hand control\n\ 102 - articular velocity are computed\n\ 103 - servo on 4 points,\n\ 104 - internal and external camera view displays.\n\ 107 %s [-c] [-d] [-h]\n", name);
112 Disable the mouse click. Useful to automaze the \n\ 113 execution of this program without humain intervention.\n\ 116 Turn off the display.\n\ 122 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
136 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
143 case 'c': click_allowed =
false;
break;
144 case 'd': display =
false;
break;
145 case 'h': usage(argv[0], NULL);
return false;
break;
148 usage(argv[0], optarg_);
153 if ((c == 1) || (c == -1)) {
155 usage(argv[0], NULL);
156 std::cerr <<
"ERROR: " << std::endl;
157 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
165 main(
int argc,
const char ** argv)
174 std::string username;
179 std::string logdirname;
181 logdirname =
"C:/temp/" + username;
183 logdirname =
"/tmp/" + username;
193 std::cerr << std::endl
194 <<
"ERROR:" << std::endl;
195 std::cerr <<
" Cannot create " << logdirname << std::endl;
199 std::string logfilename;
200 logfilename = logdirname +
"/log.dat";
203 std::ofstream flog(logfilename.c_str());
206 bool opt_click_allowed =
true;
207 bool opt_display =
true;
210 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
216 #if defined VISP_HAVE_X11 219 #elif defined VISP_HAVE_GTK 222 #elif defined VISP_HAVE_GDI 225 #elif defined VISP_HAVE_OPENCV 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) 334 for (i = 0 ; i < 4 ; i++)
335 externalview.
insert(point[i]) ;
342 for (i = 0 ; i < 4 ; i++) {
343 point[i].
track(cMod);
352 for (i = 0 ; i < 4 ; i++)
353 point[i].track(cMo) ;
357 for (i = 0 ; i < 4 ; i++) {
383 for (i = 0 ; i < 4 ; i++)
390 std::cout <<
"\nDisplay task information: " << std::endl;
393 unsigned int iter=0 ;
395 while(iter++ < 200) {
396 std::cout <<
"---------------------------------------------" 397 << iter <<std::endl ;
412 for (i = 0 ; i < 4 ; i++) {
413 point[i].
track(cMo) ;
432 std::cout <<
"Display task information: " << std::endl;
444 flog << v[0] <<
" " << v[1] <<
" " << v[2] <<
" " 445 << v[3] <<
" " << v[4] <<
" " << v[5] <<
" ";
447 std::cout <<
"v: " << v.
t() << std::endl;
449 std::cout <<
"|| s - s* || = "<< ( task.
getError() ).sumSquare() << std::endl;
454 flog << ( task.
getError() ).t() <<
" ";
455 std::cout <<
"|| s - s* || = " << ( task.
getError() ).sumSquare() <<std::endl ;
458 for (i = 0 ; i < 4 ; i++) {
462 for (i = 0 ; i < 4 ; i++) {
463 flog << point[i].
get_x() <<
" " << point[i].
get_y() <<
" ";
472 std::cout <<
"\nClick in the internal camera view to continue..." << std::endl;
490 std::cout <<
"Final robot position with respect to the object frame:\n";
493 if (opt_display && opt_click_allowed) {
495 std::cout <<
"\n\nClick in the internal view to end..." << std::endl;
501 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
509 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)
Implementation of a matrix and operations on matrices.
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)
Implementation of an homogeneous matrix and operations on such kind of matrices.
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.
Generic class defining intrinsic camera parameters.
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)
vpHomogeneousMatrix getPosition() const
Implementation of a velocity twist matrix and operations on such kind of matrices.
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
static double rad(double deg)
void set_j(const double jj)
void setWorldCoordinates(const double oX, const double oY, const double oZ)
Implementation of column vector and the associated operations.
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)