47#include <visp3/core/vpConfig.h>
48#include <visp3/core/vpHomogeneousMatrix.h>
49#include <visp3/core/vpMath.h>
50#include <visp3/core/vpSphere.h>
51#include <visp3/gui/vpDisplayFactory.h>
52#include <visp3/gui/vpProjectionDisplay.h>
53#include <visp3/io/vpParseArgv.h>
54#include <visp3/robot/vpSimulatorCamera.h>
55#include <visp3/visual_features/vpFeatureBuilder.h>
56#include <visp3/visual_features/vpFeatureEllipse.h>
57#include <visp3/vs/vpServo.h>
58#include <visp3/vs/vpServoDisplay.h>
61#define GETOPTARGS "cdho"
63#ifdef ENABLE_VISP_NAMESPACE
67void usage(
const char *name,
const char *badparam);
68bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
78void usage(
const char *name,
const char *badparam)
81Simulation of a 2D visual servoing on a sphere:\n\
82- eye-in-hand control law,\n\
83- velocity computed in the camera frame,\n\
84- display the camera view,\n\
85- a secondary task is the added.\n\
88 %s [-c] [-d] [-o] [-h]\n",
95 Disable the mouse click. Useful to automate the \n\
96 execution of this program without human intervention.\n\
99 Turn off the display.\n\
102 Disable new projection operator usage for secondary task.\n\
108 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
124bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display,
bool &new_proj_operator)
132 click_allowed =
false;
138 new_proj_operator =
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 (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
164#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
165 std::shared_ptr<vpDisplay> displayI;
166 std::shared_ptr<vpDisplay> displayExt;
172 bool opt_display =
true;
173 bool opt_click_allowed =
true;
174 bool opt_new_proj_operator =
true;
177 if (getOptions(argc, argv, opt_click_allowed, opt_display, opt_new_proj_operator) ==
false) {
178 return (EXIT_FAILURE);
185#if defined(VISP_HAVE_DISPLAY)
187#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
206#ifdef VISP_HAVE_DISPLAY
210 double px = 600, py = 600;
211 double u0 = I.getWidth() / 2., v0 = I.getHeight() / 2.;
225 robot.getPosition(wMc);
237#ifdef VISP_HAVE_DISPLAY
238 externalview.
insert(sphere);
257 std::cout << std::endl;
258 task.addFeature(p, pd);
268#ifdef VISP_HAVE_DISPLAY
277 if (opt_display && opt_click_allowed) {
283 unsigned int iter = 0;
285 bool start_secondary_task =
false;
288 while (iter++ < 2000 && !stop) {
289 std::cout <<
"---------------------------------------------" <<
iter << std::endl;
292 robot.getPosition(wMc);
304#ifdef VISP_HAVE_DISPLAY
313 if (
task.getError().sumSquare() < 1e-6) {
314 start_secondary_task =
true;
317 if (start_secondary_task) {
327 std::cout <<
"de2dt :" << de2dt.t() << std::endl;
329 std::cout <<
"(I-WpW)de2dt :" << sec.
t() << std::endl;
333 if (opt_display && opt_click_allowed) {
334 std::stringstream ss;
335 ss << std::string(
"New projection operator: ") +
336 (opt_new_proj_operator ? std::string(
"yes (use option -o to use old one)") : std::string(
"no"));
342 if (opt_display && opt_click_allowed) {
350 std::cout <<
"|| s - s* || = " << (
task.getError()).sumSquare() << std::endl;
362 if (opt_display && opt_click_allowed) {
372#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
373 if (displayI !=
nullptr) {
376 if (displayExt !=
nullptr) {
383 std::cout <<
"Catch a ViSP exception: " <<
e << std::endl;
384#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
385 if (displayI !=
nullptr) {
388 if (displayExt !=
nullptr) {
397 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
Generic class defining intrinsic camera parameters.
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.
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)
interface with the image for feature display
void insert(vpForwardProjection &fp)
void display(vpImage< unsigned char > &I, const vpHomogeneousMatrix &cextMo, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &color, const bool &displayTraj=false, unsigned int thickness=1)
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.
Class that defines a 3D sphere in the object frame and allows forward projection of a 3D sphere in th...
void setWorldCoordinates(const vpColVector &oP) VP_OVERRIDE
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.