44#include <visp3/core/vpCameraParameters.h>
45#include <visp3/core/vpConfig.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/vpSphere.h>
51#include <visp3/core/vpTime.h>
52#include <visp3/core/vpVelocityTwistMatrix.h>
53#include <visp3/gui/vpDisplayFactory.h>
54#include <visp3/gui/vpPlot.h>
55#include <visp3/io/vpImageIo.h>
56#include <visp3/io/vpParseArgv.h>
57#include <visp3/robot/vpSimulatorCamera.h>
58#include <visp3/robot/vpWireFrameSimulator.h>
59#include <visp3/visual_features/vpFeatureBuilder.h>
60#include <visp3/visual_features/vpGenericFeature.h>
61#include <visp3/vs/vpServo.h>
63#define GETOPTARGS "dhp"
65#if defined(VISP_HAVE_DISPLAY) && (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
67#if defined(ENABLE_VISP_NAMESPACE)
79void usage(
const char *name,
const char *badparam)
82Demonstration of the wireframe simulator with a simple visual servoing.\n\
84The visual servoing consists in bringing the camera at a desired position from the object.\n\
86The 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 Turn off the display.\n\
98 Turn off the plotter.\n\
104 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
119bool getOptions(
int argc,
const char **argv,
bool &display,
bool &plot)
133 usage(argv[0],
nullptr);
137 usage(argv[0], optarg_);
142 if ((c == 1) || (c == -1)) {
144 usage(argv[0],
nullptr);
145 std::cerr <<
"ERROR: " << std::endl;
146 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
167 double gx = sphere.
get_x();
168 double gy = sphere.
get_y();
174 if (std::fabs(gx) > std::numeric_limits<double>::epsilon() || std::fabs(gy) > std::numeric_limits<double>::epsilon())
180 double sx = gx * h2 / (sqrt(h2 + 1));
181 double sy = gy * h2 / (sqrt(h2 + 1));
182 double sz = sqrt(h2 + 1);
197 L[0][0] = -1 / sphere.
getR();
198 L[1][1] = -1 / sphere.
getR();
199 L[2][2] = -1 / sphere.
getR();
208 for (
unsigned int i = 0;
i < 3;
i++)
209 for (
unsigned int j = 0;
j < 3;
j++)
210 L[i][j + 3] = sk[i][j];
213int main(
int argc,
const char **argv)
215 const unsigned int NB_DISPLAYS = 3;
216#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
217 std::shared_ptr<vpDisplay> display[NB_DISPLAYS];
218 for (
unsigned int i = 0;
i < NB_DISPLAYS; ++
i) {
223 for (
unsigned int i = 0;
i < NB_DISPLAYS; ++
i) {
227 unsigned int exit_status = EXIT_SUCCESS;
229 bool opt_display =
true;
230 bool opt_plot =
true;
233 if (getOptions(argc, argv, opt_display, opt_plot) ==
false) {
243 display[0]->init(Iint, 100, 100,
"The internal view");
244 display[1]->init(Iext1, 100, 100,
"The first external view");
245 display[2]->init(Iext2, 100, 100,
"The second external view");
261 float sampling_time = 0.020f;
266 robot.setMaxTranslationVelocity(10);
277 wMc = wMo *
cMo.inverse();
279 robot.setPosition(wMc);
289 computeVisualFeatures(sphere, s);
295 computeVisualFeatures(sphere, sd);
298 computeInteractionMatrix(sd, sphere, L);
299 sd.setInteractionMatrix(L);
312 task.addFeature(s, sd);
317 plotter =
new vpPlot(2, 480, 640, 750, 550,
"Real time curves plotter");
318 plotter->setTitle(0,
"Visual features error");
319 plotter->setTitle(1,
"Camera velocities");
322 plotter->setLegend(0, 0,
"error_feat_sx");
323 plotter->setLegend(0, 1,
"error_feat_sy");
324 plotter->setLegend(0, 2,
"error_feat_sz");
325 plotter->setLegend(1, 0,
"vc_x");
326 plotter->setLegend(1, 1,
"vc_y");
327 plotter->setLegend(1, 2,
"vc_z");
328 plotter->setLegend(1, 3,
"wc_x");
329 plotter->setLegend(1, 4,
"wc_y");
330 plotter->setLegend(1, 5,
"wc_z");
349 camoMf = camoMf * (sim.
get_fMo().inverse());
385 std::cout <<
"Click on a display" << std::endl;
400 while (iter++ < max_iter && !stop) {
413 wMc = robot.getPosition();
419 computeVisualFeatures(sphere, s);
421 v =
task.computeControlLaw();
426 camoMf.buildFrom(0, 0.0, 2.5, 0,
vpMath::rad(150), 0);
427 camoMf = camoMf * (sim.
get_fMo().inverse());
457 std::stringstream ss;
458 ss <<
"Loop time: " <<
t - t_prev <<
" ms";
472 std::cout <<
"|| s - s* || = " << (
task.getError()).sumSquare() << std::endl;
475 if (opt_plot && plotter !=
nullptr) {
490 exit_status = EXIT_SUCCESS;
493 std::cout <<
"Catch an exception: " <<
e << std::endl;
494 exit_status = EXIT_FAILURE;
497#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
498 for (
unsigned int i = 0;
i < NB_DISPLAYS; ++
i) {
505#elif !(defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
508 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
514 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface), or GTK functionalities to display images..."
516 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
517 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
518 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
519 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.
void track(const vpHomogeneousMatrix &cMo)
Class that enables to define a feature or a set of features which are not implemented in ViSP as a sp...
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
Definition of the vpImage class member functions.
static double rad(double deg)
static double sqr(double x)
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...
virtual void setSamplingTime(const double &delta_t)
Class that defines the simplest robot: a free flying camera.
Class that defines a 3D sphere in the object frame and allows forward projection of a 3D sphere in th...
Class that consider the case of a translation vector.
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)
@ SPHERE
A 15cm radius sphere.
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 double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)