56 #include <visp3/core/vpConfig.h> 57 #include <visp3/core/vpDebug.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/core/vpHomogeneousMatrix.h> 66 #include <visp3/core/vpImage.h> 67 #include <visp3/core/vpImagePoint.h> 68 #include <visp3/core/vpIoTools.h> 69 #include <visp3/core/vpMath.h> 70 #include <visp3/core/vpMeterPixelConversion.h> 71 #include <visp3/gui/vpDisplayGDI.h> 72 #include <visp3/gui/vpDisplayGTK.h> 73 #include <visp3/gui/vpDisplayOpenCV.h> 74 #include <visp3/gui/vpDisplayX.h> 75 #include <visp3/gui/vpProjectionDisplay.h> 76 #include <visp3/io/vpParseArgv.h> 77 #include <visp3/robot/vpSimulatorCamera.h> 78 #include <visp3/visual_features/vpFeatureBuilder.h> 79 #include <visp3/visual_features/vpFeaturePointPolar.h> 80 #include <visp3/vs/vpServo.h> 81 #include <visp3/vs/vpServoDisplay.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)
144 click_allowed =
false;
150 usage(argv[0], NULL);
154 usage(argv[0], optarg_);
159 if ((c == 1) || (c == -1)) {
161 usage(argv[0], NULL);
162 std::cerr <<
"ERROR: " << std::endl;
163 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
170 int main(
int argc,
const char **argv)
179 std::string username;
184 std::string logdirname;
186 logdirname =
"C:/temp/" + username;
188 logdirname =
"/tmp/" + username;
197 std::cerr << std::endl <<
"ERROR:" << std::endl;
198 std::cerr <<
" Cannot create " << logdirname << std::endl;
202 std::string logfilename;
203 logfilename = logdirname +
"/log.dat";
206 std::ofstream flog(logfilename.c_str());
208 bool opt_click_allowed =
true;
209 bool opt_display =
true;
212 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
218 #if defined VISP_HAVE_X11 221 #elif defined VISP_HAVE_GTK 224 #elif defined VISP_HAVE_GDI 227 #elif defined VISP_HAVE_OPENCV 238 displayInt.
init(Iint, 0, 0,
"Internal view");
239 displayExt.
init(Iext, 330, 000,
"External view");
243 double px = 500, py = 500;
244 double u0 = 150, v0 = 160;
251 std::cout << std::endl;
252 std::cout <<
"----------------------------------------------" << std::endl;
253 std::cout <<
" Test program for vpServo " << std::endl;
254 std::cout <<
" Eye-in-hand task control, articular velocity are computed" << std::endl;
255 std::cout <<
" Simulation " << std::endl;
256 std::cout <<
" task : servo 4 points " << std::endl;
257 std::cout <<
"----------------------------------------------" << std::endl;
258 std::cout << std::endl;
267 #if defined(TRANS_Z_PURE) 272 #elif defined(TRANS_X_PURE) 278 #elif defined(ROT_Z_PURE) 284 #elif defined(ROT_X_PURE) 290 #elif defined(COMPLEX) 296 #elif defined(PROBLEM) 318 for (
unsigned int i = 0; i < 4; i++)
319 externalview.
insert(point[i]);
326 for (
unsigned int i = 0; i < 4; i++) {
327 point[i].
track(cMod);
335 for (
unsigned int i = 0; i < 4; i++)
340 for (
unsigned int i = 0; i < 4; i++) {
365 for (
unsigned int i = 0; i < 4; i++)
371 std::cout <<
"\nDisplay task information: " << std::endl;
374 unsigned int iter = 0;
376 while (iter++ < 200) {
377 std::cout <<
"---------------------------------------------" << iter << std::endl;
391 for (
unsigned int i = 0; i < 4; i++) {
411 std::cout <<
"Display task information: " << std::endl;
423 flog << v[0] <<
" " << v[1] <<
" " << v[2] <<
" " << v[3] <<
" " << v[4] <<
" " << v[5] <<
" ";
425 std::cout <<
"v: " << v.
t() << std::endl;
427 std::cout <<
"|| s - s* || = " << (task.
getError()).sumSquare() << std::endl;
432 flog << (task.
getError()).t() <<
" ";
433 std::cout <<
"|| s - s* || = " << (task.
getError()).sumSquare() << std::endl;
436 for (
unsigned int i = 0; i < 4; i++) {
440 for (
unsigned int i = 0; i < 4; i++) {
441 flog << point[i].
get_x() <<
" " << point[i].
get_y() <<
" ";
450 std::cout <<
"\nClick in the internal camera view to continue..." << std::endl;
464 std::cout <<
"Final robot position with respect to the object frame:\n";
467 if (opt_display && opt_click_allowed) {
474 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
481 std::cout <<
"You do not have X11, or GTK, or GDI (Graphical Device Interface) functionalities to display images..." << std::endl;
482 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
483 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
484 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
485 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
Implementation of a matrix and operations on matrices.
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 setWorldCoordinates(double oX, double oY, double oZ)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines the simplest robot: a free flying camera.
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
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)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
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)
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 a 3D point in the object frame and allows forward projection of a 3D point in the ...
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...
double get_x() const
Get the point x coordinate in the image plane.
void insert(vpForwardProjection &fp)
vpHomogeneousMatrix getPosition() const
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
static double rad(double deg)
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)
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
static const vpColor white
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)