55 #include <visp/vpImage.h>
56 #include <visp/vpImageIo.h>
57 #include <visp/vpDisplayOpenCV.h>
58 #include <visp/vpDisplayX.h>
59 #include <visp/vpDisplayGTK.h>
60 #include <visp/vpDisplayGDI.h>
61 #include <visp/vpDisplayD3D.h>
62 #include <visp/vpCameraParameters.h>
63 #include <visp/vpTime.h>
65 #include <visp/vpMath.h>
66 #include <visp/vpHomogeneousMatrix.h>
67 #include <visp/vpSphere.h>
68 #include <visp/vpGenericFeature.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/vpTranslationVector.h>
76 #include <visp/vpWireFrameSimulator.h>
80 #define GETOPTARGS "dh"
82 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_GTK))
92 void usage(
const char *name,
const char *badparam)
95 Demonstration of the wireframe simulator with a simple visual servoing.\n\
97 The visual servoing consists in bringing the camera at a desired position from the object.\n\
99 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\
102 %s [-d] [-h]\n", name);
107 Turn off the display.\n\
113 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
127 bool getOptions(
int argc,
const char **argv,
bool &display)
134 case 'd': display =
false;
break;
135 case 'h': usage(argv[0], NULL);
return false;
break;
138 usage(argv[0], optarg);
143 if ((c == 1) || (c == -1)) {
145 usage(argv[0], NULL);
146 std::cerr <<
"ERROR: " << std::endl;
147 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
169 double gx = sphere.
get_x();
170 double gy = sphere.
get_y();
176 if (std::fabs(gx) > std::numeric_limits<double>::epsilon() || std::fabs(gy) > std::numeric_limits<double>::epsilon())
181 double sx = gx*h2/(sqrt(h2+1));
182 double sy = gy*h2/(sqrt(h2+1));
183 double sz = sqrt(h2+1);
200 L[0][0] = -1/sphere.
getR();
201 L[1][1] = -1/sphere.
getR();
202 L[2][2] = -1/sphere.
getR();
211 for(
unsigned int i = 0; i < 3; i++)
212 for(
unsigned int j = 0; j < 3; j++)
213 L[i][j+3] = sk[i][j];
218 main(
int argc,
const char ** argv)
220 bool opt_display =
true;
223 if (getOptions(argc, argv, opt_display) ==
false) {
231 #if defined VISP_HAVE_X11
233 #elif defined VISP_HAVE_OPENCV
235 #elif defined VISP_HAVE_GDI
237 #elif defined VISP_HAVE_D3D9
239 #elif defined VISP_HAVE_GTK
248 display[0].
init(Iint, 100, 100,
"The internal view") ;
249 display[1].
init(Iext1, 100, 100,
"The first external view") ;
250 display[2].
init(Iext2, 100, 100,
"The second external view") ;
270 float sampling_time = 0.040f;
287 computeVisualFeatures(sphere, s);
296 computeVisualFeatures(sphere, sd);
299 computeInteractionMatrix(sd,sphere,L);
300 sd.setInteractionMatrix(L);
372 std::cout <<
"Click on a display" << std::endl;
401 computeVisualFeatures(sphere, s);
443 vpTRACE(
"\t\t || s - s* || ") ;
444 std::cout << ( task.
getError() ).sumSquare() <<std::endl ;
456 vpERROR_TRACE(
"You do not have X11, OpenCV, GDI, D3D9 or GTK display functionalities...");
Definition of the vpMatrix class.
void set_s(const vpColVector &s)
set the value of all the features.
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 track(const vpHomogeneousMatrix &cMo)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
static double measureTimeMs()
Class that defines what is a sphere.
static int wait(double t0, double t)
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)
The vpRotationMatrix considers the particular case of a rotation matrix.
void get_s(vpColVector &s) const
get the value of all the features.
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
static double sqr(double x)
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.
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 buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
Construction from translation vector and rotation matrix.
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 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
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
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.
void getExternalImage(vpImage< vpRGBa > &I)
void setExternalCameraParameters(const vpCameraParameters cam)
Class that consider the case of a translation vector.
void setServo(vpServoType _servo_type)
Choice of the visual servoing control law.
vpHomogeneousMatrix getExternalCameraPosition() const