48 #include <visp3/core/vpCameraParameters.h>
49 #include <visp3/gui/vpDisplayOpenCV.h>
50 #include <visp3/gui/vpDisplayX.h>
51 #include <visp3/gui/vpDisplayGTK.h>
52 #include <visp3/gui/vpDisplayGDI.h>
53 #include <visp3/gui/vpDisplayD3D.h>
54 #include <visp3/visual_features/vpFeatureBuilder.h>
55 #include <visp3/visual_features/vpGenericFeature.h>
56 #include <visp3/core/vpHomogeneousMatrix.h>
57 #include <visp3/core/vpImage.h>
58 #include <visp3/io/vpImageIo.h>
59 #include <visp3/core/vpIoTools.h>
60 #include <visp3/core/vpMath.h>
61 #include <visp3/io/vpParseArgv.h>
62 #include <visp3/robot/vpSimulatorCamera.h>
63 #include <visp3/vs/vpServo.h>
64 #include <visp3/core/vpSphere.h>
65 #include <visp3/core/vpTime.h>
66 #include <visp3/core/vpVelocityTwistMatrix.h>
67 #include <visp3/robot/vpWireFrameSimulator.h>
69 #define GETOPTARGS "dh"
71 #ifdef VISP_HAVE_DISPLAY
73 void usage(
const char *name,
const char *badparam);
74 bool getOptions(
int argc,
const char **argv,
bool &display);
86 void usage(
const char *name,
const char *badparam)
89 Demonstration of the wireframe simulator with a simple visual servoing.\n\
91 The visual servoing consists in bringing the camera at a desired position from the object.\n\
93 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\
96 %s [-d] [-h]\n", name);
101 Turn off the display.\n\
107 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
121 bool getOptions(
int argc,
const char **argv,
bool &display)
128 case 'd': display =
false;
break;
129 case 'h': usage(argv[0], NULL);
return false;
break;
132 usage(argv[0], optarg_);
137 if ((c == 1) || (c == -1)) {
139 usage(argv[0], NULL);
140 std::cerr <<
"ERROR: " << std::endl;
141 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
163 double gx = sphere.
get_x();
164 double gy = sphere.
get_y();
170 if (std::fabs(gx) > std::numeric_limits<double>::epsilon() || std::fabs(gy) > std::numeric_limits<double>::epsilon())
175 double sx = gx*h2/(sqrt(h2+1));
176 double sy = gy*h2/(sqrt(h2+1));
177 double sz = sqrt(h2+1);
192 L[0][0] = -1/sphere.
getR();
193 L[1][1] = -1/sphere.
getR();
194 L[2][2] = -1/sphere.
getR();
203 for(
unsigned int i = 0; i < 3; i++)
204 for(
unsigned int j = 0; j < 3; j++)
205 L[i][j+3] = sk[i][j];
210 main(
int argc,
const char ** argv)
213 bool opt_display =
true;
216 if (getOptions(argc, argv, opt_display) ==
false) {
224 #if defined VISP_HAVE_X11
226 #elif defined VISP_HAVE_OPENCV
228 #elif defined VISP_HAVE_GDI
230 #elif defined VISP_HAVE_D3D9
232 #elif defined VISP_HAVE_GTK
239 display[0].
init(Iint, 100, 100,
"The internal view") ;
240 display[1].
init(Iext1, 100, 100,
"The first external view") ;
241 display[2].
init(Iext2, 100, 100,
"The second external view") ;
255 float sampling_time = 0.040f;
282 computeVisualFeatures(sphere, s);
288 computeVisualFeatures(sphere, sd);
291 computeInteractionMatrix(sd,sphere,L);
292 sd.setInteractionMatrix(L);
359 std::cout <<
"Click on a display" << std::endl;
389 computeVisualFeatures(sphere, s);
426 std::cout <<
"|| s - s* || = " << ( task.
getError() ).sumSquare() <<std::endl ;
434 std::cout <<
"Catch an exception: " << e << std::endl;
442 vpERROR_TRACE(
"You do not have X11, OpenCV, GDI, D3D9 or GTK display functionalities...");
void setPosition(const vpHomogeneousMatrix &wMc)
The object displayed at the desired position is the same than the scene object defined in vpSceneObje...
Implementation of a matrix and operations on matrices.
VISP_EXPORT int wait(double t0, double t)
void set_s(const vpColVector &s)
set the value of all the features.
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
void setMaxTranslationVelocity(const double maxVt)
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines the simplest robot: a free flying camera.
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)
Class that defines what is a sphere.
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)
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)
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.
vpHomogeneousMatrix getPosition() const
Implementation of a velocity twist matrix and operations on such kind of matrices.
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_)
VISP_EXPORT double measureTimeMs()
void setMaxRotationVelocity(const double maxVr)
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, vpImagePoint offset=vpImagePoint(0, 0))
void getInternalImage(vpImage< unsigned char > &I)
Implementation of column vector and the associated operations.
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 get_eJe(vpMatrix &eJe)
void setServo(const vpServoType &servo_type)
Class that consider the case of a translation vector.
vpHomogeneousMatrix getExternalCameraPosition() const