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
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 from the object.\n\
92 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\
95 %s [-d] [-h]\n", name);
100 Turn off the display.\n\
106 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
120 bool getOptions(
int argc,
const char **argv,
bool &display)
127 case 'd': display =
false;
break;
128 case 'h': usage(argv[0], NULL);
return false;
break;
131 usage(argv[0], optarg);
136 if ((c == 1) || (c == -1)) {
138 usage(argv[0], NULL);
139 std::cerr <<
"ERROR: " << std::endl;
140 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
162 double gx = sphere.
get_x();
163 double gy = sphere.
get_y();
169 if (std::fabs(gx) > std::numeric_limits<double>::epsilon() || std::fabs(gy) > std::numeric_limits<double>::epsilon())
174 double sx = gx*h2/(sqrt(h2+1));
175 double sy = gy*h2/(sqrt(h2+1));
176 double sz = sqrt(h2+1);
191 L[0][0] = -1/sphere.
getR();
192 L[1][1] = -1/sphere.
getR();
193 L[2][2] = -1/sphere.
getR();
202 for(
unsigned int i = 0; i < 3; i++)
203 for(
unsigned int j = 0; j < 3; j++)
204 L[i][j+3] = sk[i][j];
209 main(
int argc,
const char ** argv)
211 bool opt_display =
true;
214 if (getOptions(argc, argv, opt_display) ==
false) {
222 #if defined VISP_HAVE_X11
224 #elif defined VISP_HAVE_OPENCV
226 #elif defined VISP_HAVE_GDI
228 #elif defined VISP_HAVE_D3D9
230 #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") ;
261 float sampling_time = 0.040f;
289 computeVisualFeatures(sphere, s);
295 computeVisualFeatures(sphere, sd);
298 computeInteractionMatrix(sd,sphere,L);
299 sd.setInteractionMatrix(L);
366 std::cout <<
"Click on a display" << std::endl;
396 computeVisualFeatures(sphere, s);
433 std::cout <<
"|| s - s* || = " << ( task.
getError() ).sumSquare() <<std::endl ;
445 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)
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 init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void track(const vpHomogeneousMatrix &cMo)
static double measureTimeMs()
Class that defines what is a sphere.
static int wait(double t0, double t)
void setCameraPositionRelObj(const vpHomogeneousMatrix &cMo)
void set_cVe(vpVelocityTwistMatrix &_cVe)
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 setExternalCameraPosition(const vpHomogeneousMatrix &camMf)
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.
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
static double sqr(double x)
Class that defines the simplest robot: a free flying camera.
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.
void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject)
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
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...
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)
void setExternalCameraParameters(const vpCameraParameters &cam)
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 setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo)
void get_eJe(vpMatrix &eJe)
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...
Class required to compute the visual servoing control law descbribed in and .
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &v)
Class that consider the case of a translation vector.
void setServo(vpServoType _servo_type)
Choice of the visual servoing control law.
void set_fMo(const vpHomogeneousMatrix &fMo)
vpHomogeneousMatrix getExternalCameraPosition() const