44 #include <visp3/core/vpCameraParameters.h>
45 #include <visp3/core/vpCylinder.h>
46 #include <visp3/core/vpHomogeneousMatrix.h>
47 #include <visp3/core/vpImage.h>
48 #include <visp3/core/vpIoTools.h>
49 #include <visp3/core/vpMath.h>
50 #include <visp3/core/vpTime.h>
51 #include <visp3/core/vpVelocityTwistMatrix.h>
52 #include <visp3/gui/vpDisplayD3D.h>
53 #include <visp3/gui/vpDisplayGDI.h>
54 #include <visp3/gui/vpDisplayGTK.h>
55 #include <visp3/gui/vpDisplayOpenCV.h>
56 #include <visp3/gui/vpDisplayX.h>
57 #include <visp3/gui/vpPlot.h>
58 #include <visp3/io/vpImageIo.h>
59 #include <visp3/io/vpParseArgv.h>
60 #include <visp3/robot/vpSimulatorCamera.h>
61 #include <visp3/robot/vpWireFrameSimulator.h>
62 #include <visp3/visual_features/vpFeatureBuilder.h>
63 #include <visp3/vs/vpServo.h>
65 #define GETOPTARGS "dhp"
67 #if defined(VISP_HAVE_DISPLAY) && (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
69 #if defined(ENABLE_VISP_NAMESPACE)
81 void usage(
const char *name,
const char *badparam)
84 Demonstration of the wireframe simulator with a simple visual servoing.\n\
86 The visual servoing consists in bringing the camera at a desired position\n\
89 The visual features used to compute the pose of the camera and \n\
90 thus the control law are two lines. These features are computed thanks \n\
91 to the equation of a cylinder.\n\
93 This demonstration explains also how to move the object around a world \n\
94 reference frame. Here, the movment is a rotation around the x and y axis \n\
95 at a given distance from the world frame. In fact the object trajectory \n\
96 is on a sphere whose center is the origin of the world frame.\n\
105 Turn off the display.\n\
108 Turn off the plotter.\n\
114 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
129 bool getOptions(
int argc,
const char **argv,
bool &display,
bool &plot)
143 usage(argv[0],
nullptr);
147 usage(argv[0], optarg_);
152 if ((c == 1) || (c == -1)) {
154 usage(argv[0],
nullptr);
155 std::cerr <<
"ERROR: " << std::endl;
156 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
163 int main(
int argc,
const char **argv)
166 bool opt_display =
true;
167 bool opt_plot =
true;
170 if (getOptions(argc, argv, opt_display, opt_plot) ==
false) {
177 #if defined(VISP_HAVE_X11)
179 #elif defined(HAVE_OPENCV_HIGHGUI)
181 #elif defined(VISP_HAVE_GDI)
183 #elif defined(VISP_HAVE_D3D9)
185 #elif defined(VISP_HAVE_GTK)
191 display[0].init(Iint, 100, 100,
"The internal view");
192 display[1].init(Iext, 100, 100,
"The first external view");
201 vpPlot *plotter =
nullptr;
205 float sampling_time = 0.020f;
206 robot.setSamplingTime(sampling_time);
230 cylinder.track(cdMo);
247 for (
int i = 0; i < 2; i++)
251 plotter =
new vpPlot(2, 480, 640, 750, 550,
"Real time curves plotter");
252 plotter->
setTitle(0,
"Visual features error");
253 plotter->
setTitle(1,
"Camera velocities");
256 plotter->
setLegend(0, 0,
"error_feat_l1_rho");
257 plotter->
setLegend(0, 1,
"error_feat_l1_theta");
258 plotter->
setLegend(0, 2,
"error_feat_l2_rho");
259 plotter->
setLegend(0, 3,
"error_feat_l2_theta");
313 std::cout <<
"Click on a display" << std::endl;
318 robot.setPosition(wMc);
333 double vitesse = 0.3;
338 while (iter++ < max_iter && !stop) {
350 wMc = robot.getPosition();
360 if (iter % tempo < 200 && iter % tempo >= 0) {
362 e1[0] = -fabs(vitesse);
364 rapport = -vitesse / proj_e1[0];
369 else if (iter % tempo < 300 && iter % tempo >= 200) {
371 e2[1] = -fabs(vitesse);
373 rapport = -vitesse / proj_e2[1];
378 else if (iter % tempo < 500 && iter % tempo >= 300) {
380 e1[0] = -fabs(vitesse);
382 rapport = vitesse / proj_e1[0];
387 else if (iter % tempo < 600 && iter % tempo >= 500) {
389 e2[1] = -fabs(vitesse);
391 rapport = vitesse / proj_e2[1];
405 plotter->
plot(1, iter, v);
426 std::stringstream ss;
427 ss <<
"Loop time: " << t - t_prev <<
" ms";
440 std::cout <<
"|| s - s* || = " << (task.
getError()).sumSquare() << std::endl;
443 if (opt_plot && plotter !=
nullptr) {
462 std::cout <<
"Catch an exception: " << e << std::endl;
466 #elif !(defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
469 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
475 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface), or GTK functionalities to display images..."
477 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
478 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
479 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
480 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
static const vpColor none
Class that defines a 3D cylinder in the object frame and allows forward projection of a 3D cylinder i...
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
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, const vpImagePoint &offset=vpImagePoint(0, 0), const std::string &frameName="", const vpColor &textColor=vpColor::black, const vpImagePoint &textOffset=vpImagePoint(15, 15))
static void flush(const vpImage< unsigned char > &I)
static void setWindowPosition(const vpImage< unsigned char > &I, int winx, int winy)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Class that defines a 2D line visual feature which is composed by two parameters that are and ,...
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
static double rad(double deg)
Implementation of a matrix and operations on matrices.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
void initGraph(unsigned int graphNum, unsigned int curveNbr)
void setLegend(unsigned int graphNum, unsigned int curveNum, const std::string &legend)
void plot(unsigned int graphNum, unsigned int curveNum, double x, double y)
void setTitle(unsigned int graphNum, const std::string &title)
void get_eJe(vpMatrix &eJe) VP_OVERRIDE
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
unsigned int getDimension() const
void addFeature(vpBasicFeature &s_cur, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
void set_cVe(const vpVelocityTwistMatrix &cVe_)
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
void set_eJe(const vpMatrix &eJe_)
vpColVector secondaryTask(const vpColVector &de2dt, const bool &useLargeProjectionOperator=false)
void setServo(const vpServoType &servo_type)
vpColVector getError() const
vpColVector computeControlLaw()
Class that defines the simplest robot: a free flying camera.
Implementation of a wire frame simulator. Compared to the vpSimulator class, it does not require thir...
vpHomogeneousMatrix getExternalCameraPosition() const
void setCameraPositionRelObj(const vpHomogeneousMatrix &cMo_)
void getInternalImage(vpImage< unsigned char > &I)
void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject)
void setExternalCameraPosition(const vpHomogeneousMatrix &cam_Mf)
void set_fMo(const vpHomogeneousMatrix &fMo_)
vpHomogeneousMatrix get_fMo() const
void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_)
void setInternalCameraParameters(const vpCameraParameters &cam)
void setExternalCameraParameters(const vpCameraParameters &cam)
@ CYLINDER
A cylinder of 80cm length and 10cm radius.
void getExternalImage(vpImage< unsigned char > &I)
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()