55 #include <visp3/core/vpCameraParameters.h>
56 #include <visp3/core/vpConfig.h>
57 #include <visp3/core/vpCylinder.h>
58 #include <visp3/core/vpHomogeneousMatrix.h>
59 #include <visp3/core/vpImage.h>
60 #include <visp3/core/vpMath.h>
61 #include <visp3/gui/vpDisplayD3D.h>
62 #include <visp3/gui/vpDisplayGDI.h>
63 #include <visp3/gui/vpDisplayGTK.h>
64 #include <visp3/gui/vpDisplayOpenCV.h>
65 #include <visp3/gui/vpDisplayX.h>
66 #include <visp3/gui/vpProjectionDisplay.h>
67 #include <visp3/io/vpParseArgv.h>
68 #include <visp3/robot/vpSimulatorCamera.h>
69 #include <visp3/visual_features/vpFeatureBuilder.h>
70 #include <visp3/visual_features/vpFeatureLine.h>
71 #include <visp3/vs/vpServo.h>
72 #include <visp3/vs/vpServoDisplay.h>
75 #define GETOPTARGS "cdho"
77 #ifdef ENABLE_VISP_NAMESPACE
81 void usage(
const char *name,
const char *badparam);
82 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
92 void usage(
const char *name,
const char *badparam)
95 Simulation of a 2D visual servoing on a cylinder:\n\
96 - eye-in-hand control law,\n\
97 - velocity computed in the camera frame,\n\
98 - display the camera view.\n\
101 %s [-c] [-d] [-o] [-h]\n",
108 Disable the mouse click. Useful to automate the \n\
109 execution of this program without human intervention.\n\
112 Turn off the display.\n\
115 Disable new projection operator usage for secondary task.\n\
121 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
136 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display,
bool &new_proj_operator)
144 click_allowed =
false;
150 new_proj_operator =
false;
153 usage(argv[0],
nullptr);
157 usage(argv[0], optarg_);
162 if ((c == 1) || (c == -1)) {
164 usage(argv[0],
nullptr);
165 std::cerr <<
"ERROR: " << std::endl;
166 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
173 int main(
int argc,
const char **argv)
175 #if (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
177 bool opt_display =
true;
178 bool opt_click_allowed =
true;
179 bool opt_new_proj_operator =
true;
182 if (getOptions(argc, argv, opt_click_allowed, opt_display, opt_new_proj_operator) ==
false) {
190 #ifdef VISP_HAVE_DISPLAY
191 #if defined(VISP_HAVE_X11)
192 vpDisplayX displayInt;
193 vpDisplayX displayExt;
194 #elif defined(VISP_HAVE_GTK)
197 #elif defined(VISP_HAVE_GDI)
200 #elif defined(HAVE_OPENCV_HIGHGUI)
203 #elif defined(VISP_HAVE_D3D9)
210 #ifdef VISP_HAVE_DISPLAY
213 displayInt.
init(Iint, 100, 100,
"Internal view");
214 displayExt.init(Iext, 130 +
static_cast<int>(Iint.getWidth()), 100,
"External view");
227 #ifdef VISP_HAVE_DISPLAY
246 robot.getPosition(wMc);
257 #ifdef VISP_HAVE_DISPLAY
258 externalview.
insert(cylinder);
261 cylinder.track(cMod);
267 for (
unsigned int i = 0; i < 2; i++)
278 for (
unsigned int i = 0; i < 2; i++) {
305 #ifdef VISP_HAVE_DISPLAY
314 if (opt_display && opt_click_allowed) {
326 unsigned int iter = 0;
328 bool start_secondary_task =
false;
331 std::cout <<
"---------------------------------------------" << iter++ << std::endl;
334 robot.getPosition(wMc);
346 for (
unsigned int i = 0; i < 2; i++) {
355 #ifdef VISP_HAVE_DISPLAY
365 start_secondary_task =
true;
368 if (start_secondary_task) {
382 static unsigned int iter_sec = 0;
384 double vitesse = 0.5;
385 unsigned int tempo = 800;
387 if (iter_sec > tempo) {
391 if (iter_sec % tempo < 200) {
393 e1[0] = fabs(vitesse);
395 rapport = vitesse / proj_e1[0];
400 if (iter_sec % tempo < 400 && iter_sec % tempo >= 200) {
402 e2[1] = fabs(vitesse);
404 rapport = vitesse / proj_e2[1];
409 if (iter_sec % tempo < 600 && iter_sec % tempo >= 400) {
411 e1[0] = -fabs(vitesse);
413 rapport = -vitesse / proj_e1[0];
418 if (iter_sec % tempo < 800 && iter_sec % tempo >= 600) {
420 e2[1] = -fabs(vitesse);
422 rapport = -vitesse / proj_e2[1];
427 if (opt_display && opt_click_allowed) {
428 std::stringstream ss;
429 ss << std::string(
"New projection operator: ") +
430 (opt_new_proj_operator ? std::string(
"yes (use option -o to use old one)") : std::string(
"no"));
438 if (opt_display && opt_click_allowed) {
446 std::cout <<
"|| s - s* || = " << (task.
getError()).sumSquare() << std::endl;
460 if (opt_display && opt_click_allowed) {
473 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
479 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...
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="") VP_OVERRIDE
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 vpImagePoint &t)
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
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)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE
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)
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 print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
vpColVector secondaryTask(const vpColVector &de2dt, const bool &useLargeProjectionOperator=false)
void setServo(const vpServoType &servo_type)
vpColVector getError() const
vpColVector computeControlLaw()
Class that defines the simplest robot: a free flying camera.