54 #include <visp3/core/vpConfig.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/vpCylinder.h> 63 #include <visp3/core/vpHomogeneousMatrix.h> 64 #include <visp3/core/vpImage.h> 65 #include <visp3/core/vpMath.h> 66 #include <visp3/gui/vpDisplayGDI.h> 67 #include <visp3/gui/vpDisplayGTK.h> 68 #include <visp3/gui/vpDisplayOpenCV.h> 69 #include <visp3/gui/vpDisplayX.h> 70 #include <visp3/gui/vpProjectionDisplay.h> 71 #include <visp3/io/vpParseArgv.h> 72 #include <visp3/robot/vpSimulatorCamera.h> 73 #include <visp3/visual_features/vpFeatureBuilder.h> 74 #include <visp3/visual_features/vpFeatureLine.h> 75 #include <visp3/vs/vpServo.h> 76 #include <visp3/vs/vpServoDisplay.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 Simulation of a 2D visual servoing on a cylinder:\n\ 96 - eye-in-hand control law,\n\ 97 - velocity computed in the camera frame,\n\ 98 - display the camera view.\n\ 101 %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)
139 click_allowed =
false;
145 usage(argv[0], NULL);
150 usage(argv[0], optarg_);
156 if ((c == 1) || (c == -1)) {
158 usage(argv[0], NULL);
159 std::cerr <<
"ERROR: " << std::endl;
160 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
167 int main(
int argc,
const char **argv)
170 bool opt_display =
true;
171 bool opt_click_allowed =
true;
174 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
182 #if defined VISP_HAVE_X11 185 #elif defined VISP_HAVE_GTK 188 #elif defined VISP_HAVE_GDI 191 #elif defined VISP_HAVE_OPENCV 200 displayInt.
init(Iint, 100, 100,
"Internal view");
201 displayExt.
init(Iext, (
int)(130 + Iint.
getWidth()), 100,
"External view");
245 externalview.
insert(cylinder);
248 cylinder.track(cMod);
255 for (i = 0; i < 2; i++)
266 for (i = 0; i < 2; i++) {
300 if (opt_display && opt_click_allowed) {
301 std::cout <<
"\n\nClick in the internal camera view window to start..." << std::endl;
311 unsigned int iter = 0;
314 std::cout <<
"---------------------------------------------" << iter++ << std::endl;
330 for (i = 0; i < 2; i++) {
350 std::cout <<
"|| s - s* || = " << (task.
getError()).sumSquare() << std::endl;
351 }
while ((task.
getError()).sumSquare() > 1e-9);
371 double vitesse = 0.5;
372 unsigned int tempo = 800;
374 while (iter < tempo) {
383 for (i = 0; i < 2; i++) {
398 if (iter % tempo < 200 /*&& iter%tempo >= 0*/) {
400 e1[0] = fabs(vitesse);
402 rapport = vitesse / proj_e1[0];
407 if (iter % tempo < 400 && iter % tempo >= 200) {
409 e2[1] = fabs(vitesse);
411 rapport = vitesse / proj_e2[1];
416 if (iter % tempo < 600 && iter % tempo >= 400) {
418 e1[0] = -fabs(vitesse);
420 rapport = -vitesse / proj_e1[0];
425 if (iter % tempo < 800 && iter % tempo >= 600) {
427 e2[1] = -fabs(vitesse);
429 rapport = -vitesse / proj_e2[1];
436 std::cout <<
"|| s - s* || = " << (task.
getError()).sumSquare() << std::endl;
441 if (opt_display && opt_click_allowed) {
442 std::cout <<
"\nClick in the internal camera view window to end..." << std::endl;
451 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
459 int main() { std::cout <<
"You do not have X11, GTK, GDI or OpenCV display functionalities..." << std::endl; }
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).
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="")
vpHomogeneousMatrix inverse() const
vpHomogeneousMatrix getPosition() const
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
vpColVector secondaryTask(const vpColVector &de2dt, const bool &useLargeProjectionOperator=false)
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.
Class that defines a 2D line visual feature which is composed by two parameters that are and ...
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
void insert(vpForwardProjection &fp)
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
static double rad(double deg)
Class that defines what is a cylinder.
Implementation of column vector and the associated operations.
void print(const unsigned int select=FEATURE_ALL) const
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
vpColVector getError() const
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
interface with the image for feature display
unsigned int getWidth() const
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)