53#include <visp3/core/vpCameraParameters.h>
54#include <visp3/core/vpConfig.h>
55#include <visp3/core/vpCylinder.h>
56#include <visp3/core/vpHomogeneousMatrix.h>
57#include <visp3/core/vpImage.h>
58#include <visp3/core/vpMath.h>
59#include <visp3/gui/vpDisplayFactory.h>
60#include <visp3/gui/vpProjectionDisplay.h>
61#include <visp3/io/vpParseArgv.h>
62#include <visp3/robot/vpSimulatorCamera.h>
63#include <visp3/visual_features/vpFeatureBuilder.h>
64#include <visp3/visual_features/vpFeatureLine.h>
65#include <visp3/vs/vpServo.h>
66#include <visp3/vs/vpServoDisplay.h>
69#define GETOPTARGS "cdho"
71#ifdef ENABLE_VISP_NAMESPACE
75void usage(
const char *name,
const char *badparam);
76bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
86void usage(
const char *name,
const char *badparam)
89Simulation of a 2D visual servoing on a cylinder:\n\
90- eye-in-hand control law,\n\
91- velocity computed in the camera frame,\n\
92- display the camera view.\n\
95 %s [-c] [-d] [-o] [-h]\n",
102 Disable the mouse click. Useful to automate the \n\
103 execution of this program without human intervention.\n\
106 Turn off the display.\n\
109 Disable new projection operator usage for secondary task.\n\
115 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
130bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display,
bool &new_proj_operator)
138 click_allowed =
false;
144 new_proj_operator =
false;
147 usage(argv[0],
nullptr);
151 usage(argv[0], optarg_);
156 if ((c == 1) || (c == -1)) {
158 usage(argv[0],
nullptr);
159 std::cerr <<
"ERROR: " << std::endl;
160 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
167int main(
int argc,
const char **argv)
170#ifdef VISP_HAVE_DISPLAY
171#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
172 std::shared_ptr<vpDisplay> displayInt;
173 std::shared_ptr<vpDisplay> displayExt;
179#if (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
181 bool opt_display =
true;
182 bool opt_click_allowed =
true;
183 bool opt_new_proj_operator =
true;
186 if (getOptions(argc, argv, opt_click_allowed, opt_display, opt_new_proj_operator) ==
false) {
194#ifdef VISP_HAVE_DISPLAY
197#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
216#ifdef VISP_HAVE_DISPLAY
235 robot.getPosition(wMc);
246#ifdef VISP_HAVE_DISPLAY
247 externalview.
insert(cylinder);
250 cylinder.track(cMod);
256 for (
unsigned int i = 0;
i < 2;
i++)
267 for (
unsigned int i = 0;
i < 2;
i++) {
286 task.addFeature(l[0], ld[0]);
287 task.addFeature(l[1], ld[1]);
294#ifdef VISP_HAVE_DISPLAY
303 if (opt_display && opt_click_allowed) {
315 unsigned int iter = 0;
317 bool start_secondary_task =
false;
320 std::cout <<
"---------------------------------------------" <<
iter++ << std::endl;
323 robot.getPosition(wMc);
335 for (
unsigned int i = 0;
i < 2;
i++) {
344#ifdef VISP_HAVE_DISPLAY
353 if (
task.getError().sumSquare() < 1e-6) {
354 start_secondary_task =
true;
357 if (start_secondary_task) {
371 static unsigned int iter_sec = 0;
373 double vitesse = 0.5;
374 unsigned int tempo = 800;
376 if (iter_sec > tempo) {
380 if (iter_sec % tempo < 200) {
382 e1[0] = fabs(vitesse);
383 proj_e1 =
task.secondaryTask(e1, opt_new_proj_operator);
384 rapport = vitesse / proj_e1[0];
389 if (iter_sec % tempo < 400 && iter_sec % tempo >= 200) {
391 e2[1] = fabs(vitesse);
392 proj_e2 =
task.secondaryTask(e2, opt_new_proj_operator);
393 rapport = vitesse / proj_e2[1];
398 if (iter_sec % tempo < 600 && iter_sec % tempo >= 400) {
400 e1[0] = -fabs(vitesse);
401 proj_e1 =
task.secondaryTask(e1, opt_new_proj_operator);
402 rapport = -vitesse / proj_e1[0];
407 if (iter_sec % tempo < 800 && iter_sec % tempo >= 600) {
409 e2[1] = -fabs(vitesse);
410 proj_e2 =
task.secondaryTask(e2, opt_new_proj_operator);
411 rapport = -vitesse / proj_e2[1];
416 if (opt_display && opt_click_allowed) {
417 std::stringstream ss;
418 ss << std::string(
"New projection operator: ") +
419 (opt_new_proj_operator ? std::string(
"yes (use option -o to use old one)") : std::string(
"no"));
427 if (opt_display && opt_click_allowed) {
435 std::cout <<
"|| s - s* || = " << (
task.getError()).sumSquare() << std::endl;
449 if (opt_display && opt_click_allowed) {
459#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11) && defined(VISP_HAVE_DISPLAY)
460 if (displayInt !=
nullptr) {
463 if (displayExt !=
nullptr) {
470 std::cout <<
"Catch a ViSP exception: " <<
e << std::endl;
471#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11) && defined(VISP_HAVE_DISPLAY)
472 if (displayInt !=
nullptr) {
475 if (displayExt !=
nullptr) {
484 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 a 3D cylinder in the object frame and allows forward projection of a 3D cylinder i...
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 a 2D line visual feature which is composed by two parameters that are and ,...
void print(unsigned int select=FEATURE_ALL) const VP_OVERRIDE
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.
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.