53 #include <visp3/core/vpConfig.h>
54 #include <visp3/core/vpDebug.h>
56 #if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
61 #include <visp3/core/vpCameraParameters.h>
62 #include <visp3/core/vpHomogeneousMatrix.h>
63 #include <visp3/core/vpImage.h>
64 #include <visp3/core/vpImagePoint.h>
65 #include <visp3/core/vpIoTools.h>
66 #include <visp3/core/vpMath.h>
67 #include <visp3/core/vpMeterPixelConversion.h>
68 #include <visp3/gui/vpDisplayGDI.h>
69 #include <visp3/gui/vpDisplayGTK.h>
70 #include <visp3/gui/vpDisplayOpenCV.h>
71 #include <visp3/gui/vpDisplayX.h>
72 #include <visp3/gui/vpProjectionDisplay.h>
73 #include <visp3/io/vpParseArgv.h>
74 #include <visp3/robot/vpSimulatorCamera.h>
75 #include <visp3/visual_features/vpFeatureBuilder.h>
76 #include <visp3/visual_features/vpFeaturePointPolar.h>
77 #include <visp3/vs/vpServo.h>
78 #include <visp3/vs/vpServoDisplay.h>
81 #define GETOPTARGS "cdh"
83 #ifdef ENABLE_VISP_NAMESPACE
87 void usage(
const char *name,
const char *badparam);
88 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
98 void usage(
const char *name,
const char *badparam)
101 Tests a control law with the following characteristics:\n\
102 - eye-in-hand control\n\
103 - articular velocity are computed\n\
104 - servo on 4 points,\n\
105 - internal and external camera view displays.\n\
108 %s [-c] [-d] [-h]\n",
114 Disable the mouse click. Useful to automate the \n\
115 execution of this program without human intervention.\n\
118 Turn off the display.\n\
124 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
138 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
146 click_allowed =
false;
152 usage(argv[0],
nullptr);
156 usage(argv[0], optarg_);
161 if ((c == 1) || (c == -1)) {
163 usage(argv[0],
nullptr);
164 std::cerr <<
"ERROR: " << std::endl;
165 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
172 int main(
int argc,
const char **argv)
181 std::string username;
186 std::string logdirname;
188 logdirname =
"C:/temp/" + username;
190 logdirname =
"/tmp/" + username;
200 std::cerr << std::endl <<
"ERROR:" << std::endl;
201 std::cerr <<
" Cannot create " << logdirname << std::endl;
205 std::string logfilename;
206 logfilename = logdirname +
"/log.dat";
209 std::ofstream flog(logfilename.c_str());
211 bool opt_click_allowed =
true;
212 bool opt_display =
true;
215 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
221 #if defined(VISP_HAVE_X11)
222 vpDisplayX displayInt;
223 vpDisplayX displayExt;
224 #elif defined(VISP_HAVE_GTK)
227 #elif defined(VISP_HAVE_GDI)
230 #elif defined(HAVE_OPENCV_HIGHGUI)
241 displayInt.init(Iint, 0, 0,
"Internal view");
242 displayExt.init(Iext, 330, 000,
"External view");
246 double px = 500, py = 500;
247 double u0 = 150, v0 = 160;
254 std::cout << std::endl;
255 std::cout <<
"----------------------------------------------" << std::endl;
256 std::cout <<
" Test program for vpServo " << std::endl;
257 std::cout <<
" Eye-in-hand task control, articular velocity are computed" << std::endl;
258 std::cout <<
" Simulation " << std::endl;
259 std::cout <<
" task : servo 4 points " << std::endl;
260 std::cout <<
"----------------------------------------------" << std::endl;
261 std::cout << std::endl;
270 #if defined(TRANS_Z_PURE)
275 #elif defined(TRANS_X_PURE)
281 #elif defined(ROT_Z_PURE)
287 #elif defined(ROT_X_PURE)
293 #elif defined(COMPLEX)
299 #elif defined(PROBLEM)
309 robot.getPosition(wMc);
321 for (
unsigned int i = 0; i < 4; i++)
322 externalview.
insert(point[i]);
329 for (
unsigned int i = 0; i < 4; i++) {
330 point[i].
track(cMod);
338 for (
unsigned int i = 0; i < 4; i++)
343 for (
unsigned int i = 0; i < 4; i++) {
368 for (
unsigned int i = 0; i < 4; i++)
374 std::cout <<
"\nDisplay task information: " << std::endl;
377 unsigned int iter = 0;
379 while (iter++ < 200) {
380 std::cout <<
"---------------------------------------------" << iter << std::endl;
389 robot.getPosition(wMc);
394 for (
unsigned int i = 0; i < 4; i++) {
414 std::cout <<
"Display task information: " << std::endl;
426 flog << v[0] <<
" " << v[1] <<
" " << v[2] <<
" " << v[3] <<
" " << v[4] <<
" " << v[5] <<
" ";
428 std::cout <<
"v: " << v.
t() << std::endl;
430 std::cout <<
"|| s - s* || = " << (task.
getError()).sumSquare() << std::endl;
435 flog << (task.
getError()).t() <<
" ";
436 std::cout <<
"|| s - s* || = " << (task.
getError()).sumSquare() << std::endl;
439 for (
unsigned int i = 0; i < 4; i++) {
443 for (
unsigned int i = 0; i < 4; i++) {
444 flog << point[i].
get_x() <<
" " << point[i].
get_y() <<
" ";
453 std::cout <<
"\nClick in the internal camera view to continue..." << std::endl;
467 std::cout <<
"Final robot position with respect to the object frame:\n";
470 if (opt_display && opt_click_allowed) {
478 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
485 std::cout <<
"You do not have X11, or GTK, or GDI (Graphical Device Interface) functionalities to display images..."
487 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
488 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
489 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
490 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
static const vpColor white
static const vpColor green
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpImagePoint &t)
Class that defines 2D image point visual feature with polar coordinates described in .
void track(const vpHomogeneousMatrix &cMo)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static double rad(double deg)
Implementation of a matrix and operations on matrices.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
double get_y() const
Get the point y coordinate in the image plane.
double get_x() const
Get the point x coordinate in the image plane.
void setWorldCoordinates(double oX, double oY, double oZ)
interface with the image for feature display
void insert(vpForwardProjection &fp)
void display(vpImage< unsigned char > &I, const vpHomogeneousMatrix &cextMo, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &color, const bool &displayTraj=false, unsigned int thickness=1)
void get_eJe(vpMatrix &eJe) VP_OVERRIDE
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE
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 setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
void addFeature(vpBasicFeature &s_cur, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
void set_cVe(const vpVelocityTwistMatrix &cVe_)
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
void set_eJe(const vpMatrix &eJe_)
void setServo(const vpServoType &servo_type)
vpColVector getError() const
vpColVector computeControlLaw()
@ FEATURE_CURRENT
Print the current features .
@ FEATURE_DESIRED
Print the desired features .
Class that defines the simplest robot: a free flying camera.