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"
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
233 displayInt.
init(Iint,0,0,
"Internal view") ;
234 displayExt.
init(Iext,330,000,
"External view") ;
239 double px, py ; px = py = 500 ;
240 double u0, v0 ; u0 = 150, v0 = 160 ;
249 std::cout << std::endl ;
250 std::cout <<
"----------------------------------------------" << std::endl ;
251 std::cout <<
" Test program for vpServo " <<std::endl ;
252 std::cout <<
" Eye-in-hand task control, articular velocity are computed"
254 std::cout <<
" Simulation " << std::endl ;
255 std::cout <<
" task : servo 4 points " << std::endl ;
256 std::cout <<
"----------------------------------------------" << std::endl ;
257 std::cout << std::endl ;
266 #if defined(TRANS_Z_PURE)
273 #elif defined(TRANS_X_PURE)
281 #elif defined(ROT_Z_PURE)
289 #elif defined(ROT_X_PURE)
297 #elif defined(COMPLEX)
305 #elif defined(PROBLEM)
332 for (i = 0 ; i < 4 ; i++)
333 externalview.
insert(point[i]) ;
340 for (i = 0 ; i < 4 ; i++) {
341 point[i].
track(cMod);
350 for (i = 0 ; i < 4 ; i++)
351 point[i].track(cMo) ;
355 for (i = 0 ; i < 4 ; i++) {
381 for (i = 0 ; i < 4 ; i++)
388 std::cout <<
"\nDisplay task information: " << std::endl;
391 unsigned int iter=0 ;
393 while(iter++ < 200) {
394 std::cout <<
"---------------------------------------------"
395 << iter <<std::endl ;
410 for (i = 0 ; i < 4 ; i++) {
411 point[i].
track(cMo) ;
430 std::cout <<
"Display task information: " << std::endl;
442 flog << v[0] <<
" " << v[1] <<
" " << v[2] <<
" "
443 << v[3] <<
" " << v[4] <<
" " << v[5] <<
" ";
445 std::cout <<
"v: " << v.
t() << std::endl;
447 std::cout <<
"|| s - s* || = "<< ( task.
getError() ).sumSquare() << std::endl;
452 flog << ( task.
getError() ).t() <<
" ";
453 std::cout <<
"|| s - s* || = " << ( task.
getError() ).sumSquare() <<std::endl ;
456 for (i = 0 ; i < 4 ; i++) {
460 for (i = 0 ; i < 4 ; i++) {
461 flog << point[i].
get_x() <<
" " << point[i].
get_y() <<
" ";
470 std::cout <<
"\nClick in the internal camera view to continue..." << std::endl;
488 std::cout <<
"Final robot position with respect to the object frame:\n";
491 if (opt_display && opt_click_allowed) {
493 std::cout <<
"\n\nClick in the internal view to end..." << std::endl;
501 vpERROR_TRACE(
"You do not have X11, GTK or GDI display functionalities...");
void set_j(const double j)
Definition of the vpMatrix class.
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)
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 set_i(const double i)
void setLambda(double _lambda)
set the gain lambda
void track(const vpHomogeneousMatrix &cMo)
double get_y() const
Get the point y coordinate in the image plane.
static const vpColor green
void set_cVe(vpVelocityTwistMatrix &_cVe)
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 kill()
destruction (memory deallocation if required)
vpColVector getError() const
vpColVector computeControlLaw()
compute the desired control law
static void display(const vpImage< unsigned char > &I)
void set_eJe(vpMatrix &_eJe)
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)
Set the type of the interaction matrix (current, mean, desired, user).
static double rad(double deg)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
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)
Class required to compute the visual servoing control law descbribed in and .
void get_eJe(vpMatrix &eJe)
interface with the image for feature display
void setServo(vpServoType _servo_type)
Choice of the visual servoing control law.
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...