55 #include <visp3/core/vpConfig.h>
57 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
62 #include <visp3/core/vpCameraParameters.h>
63 #include <visp3/gui/vpDisplayX.h>
64 #include <visp3/gui/vpDisplayGTK.h>
65 #include <visp3/gui/vpDisplayGDI.h>
66 #include <visp3/gui/vpDisplayOpenCV.h>
67 #include <visp3/visual_features/vpFeatureBuilder.h>
68 #include <visp3/visual_features/vpFeaturePoint.h>
69 #include <visp3/core/vpHomogeneousMatrix.h>
70 #include <visp3/core/vpImage.h>
71 #include <visp3/core/vpMath.h>
72 #include <visp3/io/vpParseArgv.h>
73 #include <visp3/gui/vpProjectionDisplay.h>
74 #include <visp3/vs/vpServo.h>
75 #include <visp3/vs/vpServoDisplay.h>
76 #include <visp3/robot/vpSimulatorCamera.h>
79 #define GETOPTARGS "cdh"
81 void usage(
const char *name,
const char *badparam);
82 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
92 void usage(
const char *name,
const char *badparam)
95 Tests a control law with the following characteristics:\n\
96 - eye-in-hand control\n\
97 - articular velocity are computed\n\
98 - servo on 4 points,\n\
99 - internal and external camera view displays.\n\
102 %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;
160 main(
int argc,
const char ** argv)
163 bool opt_click_allowed =
true;
164 bool opt_display =
true;
167 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
173 #if defined VISP_HAVE_X11
176 #elif defined VISP_HAVE_GTK
179 #elif defined VISP_HAVE_GDI
182 #elif defined VISP_HAVE_OPENCV
193 displayInt.
init(Iint,0,0,
"Internal view") ;
194 displayExt.
init(Iext,330,000,
"External view") ;
199 double px, py ; px = py = 500 ;
200 double u0, v0 ; u0 = 150, v0 = 160 ;
208 std::cout << std::endl ;
209 std::cout <<
"----------------------------------------------" << std::endl ;
210 std::cout <<
" Test program for vpServo " <<std::endl ;
211 std::cout <<
" Eye-in-hand task control, articular velocity are computed"
213 std::cout <<
" Simulation " << std::endl ;
214 std::cout <<
" task : servo 4 points " << std::endl ;
215 std::cout <<
"----------------------------------------------" << std::endl ;
216 std::cout << std::endl ;
237 for (i = 0 ; i < 4 ; i++)
238 externalview.
insert(point[i]) ;
241 for (i = 0 ; i < 4 ; i++)
242 point[i].track(cMo) ;
246 for (i = 0 ; i < 4 ; i++)
274 for (i = 0 ; i < 4 ; i++)
283 unsigned int iter=0 ;
287 std::cout <<
"---------------------------------------------" << iter <<std::endl ;
301 for (i = 0 ; i < 4 ; i++)
303 point[i].
track(cMo) ;
328 std::cout <<
"|| s - s* || = " << ( task.
getError() ).sumSquare() <<std::endl ;
335 std::cout <<
"Final robot position with respect to the object frame:\n";
338 if (opt_display && opt_click_allowed) {
340 std::cout <<
"\n\nClick in the internal view window to end..." << std::endl;
346 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
355 std::cout <<
"You do not have X11, GTK, GDI or OpenCV display functionalities..." << std::endl;
Implementation of a matrix and operations on matrices.
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
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_)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, const unsigned int select=vpBasicFeature::FEATURE_ALL)
error that can be emited by ViSP classes.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
void track(const vpHomogeneousMatrix &cMo)
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that defines what is a point.
vpColVector getError() const
vpColVector computeControlLaw()
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Generic class defining intrinsic camera parameters.
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
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 buildFrom(const double x, const double y, const double Z)
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)
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)