52 #include <visp/vpCameraParameters.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/vpGenericFeature.h>
60 #include <visp/vpHomogeneousMatrix.h>
61 #include <visp/vpImage.h>
62 #include <visp/vpImageIo.h>
63 #include <visp/vpIoTools.h>
64 #include <visp/vpMath.h>
65 #include <visp/vpParseArgv.h>
66 #include <visp/vpRobotCamera.h>
67 #include <visp/vpServo.h>
68 #include <visp/vpSphere.h>
69 #include <visp/vpTime.h>
70 #include <visp/vpVelocityTwistMatrix.h>
71 #include <visp/vpWireFrameSimulator.h>
73 #define GETOPTARGS "dh"
75 #ifdef VISP_HAVE_DISPLAY
77 void usage(
const char *name,
const char *badparam);
78 bool getOptions(
int argc,
const char **argv,
bool &display);
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 from the object.\n\
97 The visual features used to compute the pose of the camera and thus the control law are special moments computed with the sphere's parameters.\n\
100 %s [-d] [-h]\n", name);
105 Turn off the display.\n\
111 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
125 bool getOptions(
int argc,
const char **argv,
bool &display)
132 case 'd': display =
false;
break;
133 case 'h': usage(argv[0], NULL);
return false;
break;
136 usage(argv[0], optarg_);
141 if ((c == 1) || (c == -1)) {
143 usage(argv[0], NULL);
144 std::cerr <<
"ERROR: " << std::endl;
145 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
167 double gx = sphere.
get_x();
168 double gy = sphere.
get_y();
174 if (std::fabs(gx) > std::numeric_limits<double>::epsilon() || std::fabs(gy) > std::numeric_limits<double>::epsilon())
179 double sx = gx*h2/(sqrt(h2+1));
180 double sy = gy*h2/(sqrt(h2+1));
181 double sz = sqrt(h2+1);
196 L[0][0] = -1/sphere.
getR();
197 L[1][1] = -1/sphere.
getR();
198 L[2][2] = -1/sphere.
getR();
207 for(
unsigned int i = 0; i < 3; i++)
208 for(
unsigned int j = 0; j < 3; j++)
209 L[i][j+3] = sk[i][j];
214 main(
int argc,
const char ** argv)
217 bool opt_display =
true;
220 if (getOptions(argc, argv, opt_display) ==
false) {
228 #if defined VISP_HAVE_X11
230 #elif defined VISP_HAVE_OPENCV
232 #elif defined VISP_HAVE_GDI
234 #elif defined VISP_HAVE_D3D9
236 #elif defined VISP_HAVE_GTK
243 display[0].
init(Iint, 100, 100,
"The internal view") ;
244 display[1].
init(Iext1, 100, 100,
"The first external view") ;
245 display[2].
init(Iext2, 100, 100,
"The second external view") ;
259 float sampling_time = 0.040f;
287 computeVisualFeatures(sphere, s);
293 computeVisualFeatures(sphere, sd);
296 computeInteractionMatrix(sd,sphere,L);
297 sd.setInteractionMatrix(L);
364 std::cout <<
"Click on a display" << std::endl;
394 computeVisualFeatures(sphere, s);
431 std::cout <<
"|| s - s* || = " << ( task.
getError() ).sumSquare() <<std::endl ;
439 std::cout <<
"Catch an exception: " << e << std::endl;
447 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.
void set_s(const vpColVector &s)
set the value of all the features.
void setMaxTranslationVelocity(const double maxVt)
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 track(const vpHomogeneousMatrix &cMo)
void setExternalCameraPosition(const vpHomogeneousMatrix &cam_Mf)
static double measureTimeMs()
Class that defines what is a sphere.
static int wait(double t0, double t)
void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_)
static void flush(const vpImage< unsigned char > &I)
void skew(const vpTranslationVector &t, vpMatrix &M)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void get_s(vpColVector &s) const
get the value of all the features.
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
static double sqr(double x)
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.
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 setMaxRotationVelocity(const double maxVr)
void getInternalImage(vpImage< unsigned char > &I)
void getPosition(vpHomogeneousMatrix &cMw) const
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
Class that enables to define a feature or a set of features which are not implemented in ViSP as a sp...
void setServo(const vpServoType &servo_type)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &v)
Class that consider the case of a translation vector.
vpHomogeneousMatrix getExternalCameraPosition() const