44#include <visp3/core/vpConfig.h>
45#include <visp3/core/vpDebug.h>
47#if defined(VISP_HAVE_DISPLAY) && \
48 (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
53#include <visp3/core/vpCameraParameters.h>
54#include <visp3/core/vpCircle.h>
55#include <visp3/core/vpHomogeneousMatrix.h>
56#include <visp3/core/vpImage.h>
57#include <visp3/core/vpMath.h>
58#include <visp3/gui/vpDisplayFactory.h>
59#include <visp3/io/vpParseArgv.h>
60#include <visp3/robot/vpSimulatorCamera.h>
61#include <visp3/visual_features/vpFeatureBuilder.h>
62#include <visp3/visual_features/vpFeatureLine.h>
63#include <visp3/vs/vpServo.h>
64#include <visp3/vs/vpServoDisplay.h>
67#define GETOPTARGS "cdh"
69#ifdef ENABLE_VISP_NAMESPACE
73void usage(
const char *name,
const char *badparam);
74bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
84void usage(
const char *name,
const char *badparam)
87Simulation of a 2D visual servoing on a circle:\n\
88- eye-in-hand control law,\n\
89- velocity computed in the camera frame,\n\
90- display the camera view.\n\
100 Disable the mouse click. Useful to automate the \n\
101 execution of this program without human intervention.\n\
104 Turn off the display.\n\
110 fprintf(stderr,
"ERROR: \n");
111 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
127bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
135 click_allowed =
false;
141 usage(argv[0],
nullptr);
145 usage(argv[0], optarg_);
150 if ((c == 1) || (c == -1)) {
152 usage(argv[0],
nullptr);
153 std::cerr <<
"ERROR: " << std::endl;
154 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
161int main(
int argc,
const char **argv)
163#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
164 std::shared_ptr<vpDisplay> display;
169 bool opt_display =
true;
170 bool opt_click_allowed =
true;
173 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
174 return (EXIT_FAILURE);
181#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
195 double px = 600, py = 600;
196 double u0 = I.getWidth() / 2., v0 = I.getHeight() / 2.;
206 robot.getPosition(wMc);
232 task.addFeature(p, pd);
239 unsigned int iter = 0;
241 while (iter++ < 200) {
242 std::cout <<
"---------------------------------------------" <<
iter << std::endl;
246 robot.getPosition(wMc);
264 v =
task.computeControlLaw();
265 std::cout <<
"task rank: " <<
task.getTaskRank() << std::endl;
269 std::cout <<
"|| s - s* || = " << (
task.getError()).sumSquare() << std::endl;
275 if (opt_display && opt_click_allowed) {
280#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
281 if (display !=
nullptr) {
288 std::cout <<
"Catch a ViSP exception: " <<
e << std::endl;
289#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
290 if (display !=
nullptr) {
297#elif !(defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
300 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
306 std::cout <<
"You do not have X11, or GTK, or GDI (Graphical Device Interface) or OpenCV functionalities to display "
309 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
310 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
311 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
312 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
Generic class defining intrinsic camera parameters.
Class that defines a 3D circle in the object frame and allows forward projection of a 3D circle in th...
void setWorldCoordinates(const vpColVector &oP) VP_OVERRIDE
Implementation of column vector and the associated operations.
static const vpColor white
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 flush(const vpImage< unsigned char > &I)
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 2D ellipse visual feature.
virtual void print() const
void track(const vpHomogeneousMatrix &cMo)
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 bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static void display(const vpServo &s, const vpCameraParameters &cam, const vpImage< unsigned char > &I, vpColor currentColor=vpColor::green, vpColor desiredColor=vpColor::red, unsigned int thickness=1)
Class that defines the simplest robot: a free flying camera.
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.