44 #include <visp3/core/vpConfig.h>
45 #include <visp3/core/vpCameraParameters.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/vpDisplayFactory.h>
53 #include <visp3/gui/vpPlot.h>
54 #include <visp3/io/vpImageIo.h>
55 #include <visp3/io/vpParseArgv.h>
56 #include <visp3/robot/vpSimulatorCamera.h>
57 #include <visp3/robot/vpWireFrameSimulator.h>
58 #include <visp3/visual_features/vpFeatureBuilder.h>
59 #include <visp3/visual_features/vpFeaturePoint.h>
60 #include <visp3/vs/vpServo.h>
62 #define GETOPTARGS "dhp"
64 #if defined(VISP_HAVE_DISPLAY) && (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
66 #if defined(ENABLE_VISP_NAMESPACE)
78 void usage(
const char *name,
const char *badparam)
81 Demonstration of the wireframe simulator with a simple visual servoing.\n\
83 The visual servoing consists in bringing the camera at a desired \n\
84 position from the object.\n\
86 The visual features used to compute the pose of the camera and \n\
87 thus the control law are four points.\n\
89 This demonstration explains also how to move the object around a world\n\
90 reference frame. Here, the movement is a rotation around the x and y axis\n\
91 at a given distance from the world frame. In fact the object trajectory\n\
92 is on a sphere whose center is the origin of the world frame.\n\
101 Turn off the display.\n\
104 Turn off the plotter.\n\
110 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
125 bool getOptions(
int argc,
const char **argv,
bool &display,
bool &plot)
139 usage(argv[0],
nullptr);
143 usage(argv[0], optarg_);
148 if ((c == 1) || (c == -1)) {
150 usage(argv[0],
nullptr);
151 std::cerr <<
"ERROR: " << std::endl;
152 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
159 int main(
int argc,
const char **argv)
161 const unsigned int NB_DISPLAYS = 3;
162 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
163 std::shared_ptr<vpDisplay> display[NB_DISPLAYS];
164 for (
unsigned int i = 0; i < NB_DISPLAYS; ++i) {
169 for (
unsigned int i = 0; i < NB_DISPLAYS; ++i) {
173 unsigned int exit_status = EXIT_SUCCESS;
175 bool opt_display =
true;
176 bool opt_plot =
true;
178 std::cout <<
"Read " << filename << std::endl;
181 if (getOptions(argc, argv, opt_display, opt_plot) ==
false) {
191 display[0]->init(Iint, 100, 100,
"The internal view");
192 display[1]->init(Iext1, 100, 100,
"The first external view");
193 display[2]->init(Iext2, 100, 100,
"The second external view");
205 vpPlot *plotter =
nullptr;
208 plotter =
new vpPlot(2, 480, 640, 750, 550,
"Real time curves plotter");
209 plotter->
setTitle(0,
"Visual features error");
210 plotter->
setTitle(1,
"Camera velocities");
213 plotter->
setLegend(0, 0,
"error_feat_p1_x");
214 plotter->
setLegend(0, 1,
"error_feat_p1_y");
215 plotter->
setLegend(0, 2,
"error_feat_p2_x");
216 plotter->
setLegend(0, 3,
"error_feat_p2_y");
217 plotter->
setLegend(0, 4,
"error_feat_p3_x");
218 plotter->
setLegend(0, 5,
"error_feat_p3_y");
219 plotter->
setLegend(0, 6,
"error_feat_p4_x");
220 plotter->
setLegend(0, 7,
"error_feat_p4_y");
231 float sampling_time = 0.020f;
232 robot.setSamplingTime(sampling_time);
257 for (
int i = 0; i < 4; i++)
262 for (
int i = 0; i < 4; i++)
266 for (
int i = 0; i < 4; i++)
267 point[i].track(cdMo);
270 for (
int i = 0; i < 4; i++)
284 for (
int i = 0; i < 4; i++)
289 std::list<vpImageSimulator> list;
293 for (
int i = 0; i < 4; i++)
311 imsim.
init(filename.c_str(), X);
313 list.push_back(imsim);
368 std::cout <<
"Click on a display" << std::endl;
375 robot.setPosition(wMc);
385 while (iter++ < max_iter && !stop) {
398 wMc = robot.getPosition();
400 for (
int i = 0; i < 4; i++) {
421 camoMf.buildFrom(0, 0.0, 1.5, 0,
vpMath::rad(150), 0);
426 plotter->
plot(1, iter, v);
452 std::stringstream ss;
453 ss <<
"Loop time: " << t - t_prev <<
" ms";
466 std::cout <<
"|| s - s* || = " << (task.
getError()).sumSquare() << std::endl;
469 if (opt_plot && plotter !=
nullptr) {
485 exit_status = EXIT_SUCCESS;
488 std::cout <<
"Catch an exception: " << e << std::endl;
489 exit_status = EXIT_FAILURE;
491 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
492 for (
unsigned int i = 0; i < NB_DISPLAYS; ++i) {
498 #elif !(defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
501 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
507 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface), or GTK functionalities to display images..."
509 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
510 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
511 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
512 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 generic functionalities for display.
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 point visual feature which is composed by two parameters that are the cartes...
void track(const vpHomogeneousMatrix &cMo)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
Class which enables to project an image in the 3D space and get the view of a virtual camera.
void init(const vpImage< unsigned char > &I, vpColVector *X)
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)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
void setWorldCoordinates(double oX, double oY, double oZ)
void get_eJe(vpMatrix &eJe) VP_OVERRIDE
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE
void setMaxRotationVelocity(double maxVr)
void setMaxTranslationVelocity(double maxVt)
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
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_)
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)
void getExternalImage(vpImage< unsigned char > &I)
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()