51 #include <visp/vpCameraParameters.h>
52 #include <visp/vpCylinder.h>
53 #include <visp/vpDisplayOpenCV.h>
54 #include <visp/vpDisplayX.h>
55 #include <visp/vpDisplayGTK.h>
56 #include <visp/vpDisplayGDI.h>
57 #include <visp/vpDisplayD3D.h>
58 #include <visp/vpFeatureBuilder.h>
59 #include <visp/vpHomogeneousMatrix.h>
60 #include <visp/vpImage.h>
61 #include <visp/vpImageIo.h>
62 #include <visp/vpIoTools.h>
63 #include <visp/vpMath.h>
64 #include <visp/vpParseArgv.h>
65 #include <visp/vpRobotCamera.h>
66 #include <visp/vpServo.h>
67 #include <visp/vpTime.h>
68 #include <visp/vpVelocityTwistMatrix.h>
69 #include <visp/vpWireFrameSimulator.h>
71 #define GETOPTARGS "dh"
73 #ifdef VISP_HAVE_DISPLAY
74 void usage(
const char *name,
const char *badparam);
75 bool getOptions(
int argc,
const char **argv,
bool &display);
85 void usage(
const char *name,
const char *badparam)
88 Demonstration of the wireframe simulator with a simple visual servoing.\n\
90 The visual servoing consists in bringing the camera at a desired position\n\
93 The visual features used to compute the pose of the camera and \n\
94 thus the control law are two lines. These features are computed thanks \n\
95 to the equation of a cylinder.\n\
97 This demonstration explains also how to move the object around a world \n\
98 reference frame. Here, the movment is a rotation around the x and y axis \n\
99 at a given distance from the world frame. In fact the object trajectory \n\
100 is on a sphere whose center is the origin of the world frame.\n\
103 %s [-d] [-h]\n", name);
108 Turn off the display.\n\
114 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
129 bool getOptions(
int argc,
const char **argv,
bool &display)
136 case 'd': display =
false;
break;
137 case 'h': usage(argv[0], NULL);
return false;
break;
140 usage(argv[0], optarg_);
145 if ((c == 1) || (c == -1)) {
147 usage(argv[0], NULL);
148 std::cerr <<
"ERROR: " << std::endl;
149 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
158 main(
int argc,
const char ** argv)
161 bool opt_display =
true;
164 if (getOptions(argc, argv, opt_display) ==
false) {
171 #if defined VISP_HAVE_X11
173 #elif defined VISP_HAVE_OPENCV
175 #elif defined VISP_HAVE_GDI
177 #elif defined VISP_HAVE_D3D9
179 #elif defined VISP_HAVE_GTK
186 display[0].
init(Iint, 100, 100,
"The internal view") ;
187 display[1].
init(Iext, 100, 100,
"The first external view") ;
198 float sampling_time = 0.040f;
224 cylinder.track(cdMo);
241 for (
int i = 0 ; i < 2 ; i++)
287 std::cout <<
"Click on a display" << std::endl;
306 double vitesse = 0.3;
325 cylinder.track(cMo) ;
332 if ( iter%tempo < 200 && iter%tempo >= 0)
335 e1[0] = -fabs(vitesse) ;
337 rapport = -vitesse/proj_e1[0];
342 if ( iter%tempo < 300 && iter%tempo >= 200)
345 e2[1] = -fabs(vitesse) ;
347 rapport = -vitesse/proj_e2[1];
352 if ( iter%tempo < 500 && iter%tempo >= 300)
355 e1[0] = -fabs(vitesse) ;
357 rapport = vitesse/proj_e1[0];
362 if ( iter%tempo < 600 && iter%tempo >= 500)
365 e2[1] = -fabs(vitesse) ;
367 rapport = vitesse/proj_e2[1];
399 std::cout <<
"|| s - s* || = " << (task.
getError() ).sumSquare() <<std::endl ;
408 std::cout <<
"Catch an exception: " << e << std::endl;
416 vpERROR_TRACE(
"You do not have X11, OpenCV, GDI, D3D9 or GTK display functionalities...");
The object displayed at the desired position is the same than the scene object defined in vpSceneObje...
Definition of the vpMatrix class.
A cylinder of 80cm length and 10cm radius.
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
void setPosition(const vpHomogeneousMatrix &cMw)
void set_fMo(const vpHomogeneousMatrix &fMo_)
Display for windows using GDI (available on any windows 32 platform).
void set_eJe(const vpMatrix &eJe_)
Define the X11 console to display images.
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, const unsigned int select=vpBasicFeature::FEATURE_ALL)
static const vpColor none
error that can be emited by ViSP classes.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void setExternalCameraPosition(const vpHomogeneousMatrix &cam_Mf)
static double measureTimeMs()
static int wait(double t0, double t)
void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_)
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)
virtual void setSamplingTime(const double &delta_t)
Display for windows using Direct3D.
vpColVector getError() const
vpHomogeneousMatrix get_fMo() const
vpColVector computeControlLaw()
virtual void setWindowPosition(int winx, int winy)=0
Class that defines the simplest robot: a free flying camera.
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
Generic class defining intrinsic camera parameters.
Class that defines a 2D line visual feature which is composed by two parameters that are and ...
void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject)
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1)
Class that consider the particular case of twist transformation matrix that allows to transform a vel...
void getExternalImage(vpImage< unsigned char > &I)
Implementation of a wire frame simulator. Compared to the vpSimulator class, it does not require thir...
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
static double rad(double deg)
void setExternalCameraParameters(const vpCameraParameters &cam)
void setCameraPositionRelObj(const vpHomogeneousMatrix &cMo_)
void getInternalImage(vpImage< unsigned char > &I)
void getPosition(vpHomogeneousMatrix &cMw) const
Class that defines what is a cylinder.
Class that provides a data structure for the column vectors as well as a set of operations on these v...
void get_eJe(vpMatrix &eJe)
void set_cVe(const vpVelocityTwistMatrix &cVe_)
vpHomogeneousMatrix inverse() const
void setInternalCameraParameters(const vpCameraParameters &cam)
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
virtual bool getClick(bool blocking=true)=0
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
void setServo(const vpServoType &servo_type)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &v)
vpHomogeneousMatrix getExternalCameraPosition() const