56 #include <visp/vpImage.h>
57 #include <visp/vpImageIo.h>
58 #include <visp/vpDisplayOpenCV.h>
59 #include <visp/vpDisplayX.h>
60 #include <visp/vpDisplayGTK.h>
61 #include <visp/vpDisplayGDI.h>
62 #include <visp/vpDisplayD3D.h>
63 #include <visp/vpCameraParameters.h>
64 #include <visp/vpTime.h>
66 #include <visp/vpMath.h>
67 #include <visp/vpHomogeneousMatrix.h>
68 #include <visp/vpFeaturePoint.h>
69 #include <visp/vpServo.h>
70 #include <visp/vpRobotCamera.h>
71 #include <visp/vpFeatureBuilder.h>
72 #include <visp/vpParseArgv.h>
73 #include <visp/vpIoTools.h>
74 #include <visp/vpVelocityTwistMatrix.h>
75 #include <visp/vpWireFrameSimulator.h>
76 #include <visp/vpCylinder.h>
78 #define GETOPTARGS "dh"
80 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_GTK))
90 void usage(
const char *name,
const char *badparam)
93 Demonstration of the wireframe simulator with a simple visual servoing.\n\
95 The visual servoing consists in bringing the camera at a desired position\n\
98 The visual features used to compute the pose of the camera and \n\
99 thus the control law are two lines. These features are computed thanks \n\
100 to the equation of a cylinder.\n\
102 This demonstration explains also how to move the object around a world \n\
103 reference frame. Here, the movment is a rotation around the x and y axis \n\
104 at a given distance from the world frame. In fact the object trajectory \n\
105 is on a sphere whose center is the origin of the world frame.\n\
108 %s [-d] [-h]\n", name);
113 Turn off the display.\n\
119 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
134 bool getOptions(
int argc,
const char **argv,
bool &display)
141 case 'd': display =
false;
break;
142 case 'h': usage(argv[0], NULL);
return false;
break;
145 usage(argv[0], optarg);
150 if ((c == 1) || (c == -1)) {
152 usage(argv[0], NULL);
153 std::cerr <<
"ERROR: " << std::endl;
154 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
163 main(
int argc,
const char ** argv)
165 bool opt_display =
true;
168 if (getOptions(argc, argv, opt_display) ==
false) {
175 #if defined VISP_HAVE_X11
177 #elif defined VISP_HAVE_OPENCV
179 #elif defined VISP_HAVE_GDI
181 #elif defined VISP_HAVE_D3D9
183 #elif defined VISP_HAVE_GTK
192 display[0].
init(Iint, 100, 100,
"The internal view") ;
193 display[1].
init(Iext, 100, 100,
"The first external view") ;
210 float sampling_time = 0.040f;
233 cylinder.track(cdMo);
250 for (
int i = 0 ; i < 2 ; i++)
299 std::cout <<
"Click on a display" << std::endl;
318 double vitesse = 0.3;
336 cylinder.track(cMo) ;
343 if ( iter%tempo < 200 && iter%tempo >= 0)
346 e1[0] = -fabs(vitesse) ;
348 rapport = -vitesse/proj_e1[0];
353 if ( iter%tempo < 300 && iter%tempo >= 200)
356 e2[1] = -fabs(vitesse) ;
358 rapport = -vitesse/proj_e2[1];
363 if ( iter%tempo < 500 && iter%tempo >= 300)
366 e1[0] = -fabs(vitesse) ;
368 rapport = vitesse/proj_e1[0];
373 if ( iter%tempo < 600 && iter%tempo >= 500)
376 e2[1] = -fabs(vitesse) ;
378 rapport = vitesse/proj_e2[1];
424 vpTRACE(
"\t\t || s - s* || ") ;
425 std::cout << (task.
getError() ).sumSquare() <<std::endl ;
437 vpERROR_TRACE(
"You do not have X11, OpenCV, GDI, D3D9 or GTK display functionalities...");
Definition of the vpMatrix class.
void setSamplingTime(const double &delta_t)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
Display for windows using GDI (available on any windows 32 platform).
Define the X11 console to display images.
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, const unsigned int select=vpBasicFeature::FEATURE_ALL)
create a new ste of two visual features
static const vpColor none
void setLambda(double _lambda)
set the gain lambda
void setCameraPositionRelObj(const vpHomogeneousMatrix cMo)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
static double measureTimeMs()
vpColVector secondaryTask(vpColVector &de2dt)
Add a secondary task.
static int wait(double t0, double t)
void set_cVe(vpVelocityTwistMatrix &_cVe)
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Display for windows using Direct3D.
void setExternalCameraPosition(const vpHomogeneousMatrix camMf)
void kill()
destruction (memory deallocation if required)
vpColVector getError() const
vpHomogeneousMatrix get_fMo() const
vpColVector computeControlLaw()
compute the desired control law
virtual void setWindowPosition(int winx, int winy)=0
Class that defines the simplest robot: a free flying camera.
void getInternalImage(vpImage< vpRGBa > &I)
static void display(const vpImage< unsigned char > &I)
void set_eJe(vpMatrix &_eJe)
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 ...
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void setDesiredCameraPosition(const vpHomogeneousMatrix cdMo)
void getPosition(vpColVector &q)
Class that consider the particular case of twist transformation matrix that allows to transform a vel...
void setPosition(const vpRobot::vpControlFrameType, const vpColVector &)
Set a displacement (frame has to be specified) in position control.
Implementation of a wire frame simulator. Compared to the vpSimulator class, it does not require thir...
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness=1)
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
Set the type of the interaction matrix (current, mean, desired, user).
static double rad(double deg)
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...
The pose is a complete representation of every rigid motion in the euclidian space.
vpHomogeneousMatrix inverse() const
vpHomogeneousMatrix get_cMo() const
void initScene(vpSceneObject obj, vpSceneDesiredObject desiredObject)
void get_eJe(vpMatrix &_eJe)
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
void setInternalCameraParameters(const vpCameraParameters cam)
virtual bool getClick(bool blocking=true)=0
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Class required to compute the visual servoing control law.
void getExternalImage(vpImage< vpRGBa > &I)
void setExternalCameraParameters(const vpCameraParameters cam)
void setServo(vpServoType _servo_type)
Choice of the visual servoing control law.
void set_fMo(const vpHomogeneousMatrix &fMo)
vpHomogeneousMatrix getExternalCameraPosition() const