#include <stdio.h>
#include <stdlib.h>
#include <visp3/core/vpHomogeneousMatrix.h>
#include <visp3/core/vpMath.h>
#include <visp3/core/vpSphere.h>
#include <visp3/gui/vpDisplayD3D.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayGTK.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/gui/vpProjectionDisplay.h>
#include <visp3/io/vpParseArgv.h>
#include <visp3/robot/vpSimulatorCamera.h>
#include <visp3/visual_features/vpFeatureBuilder.h>
#include <visp3/visual_features/vpFeatureEllipse.h>
#include <visp3/vs/vpServo.h>
#include <visp3/vs/vpServoDisplay.h>
#define GETOPTARGS "cdho"
void usage(const char *name, const char *badparam);
bool getOptions(int argc, const char **argv, bool &click_allowed, bool &display);
void usage(const char *name, const char *badparam)
{
fprintf(stdout, "\n\
Simulation of a 2D visual servoing on a sphere:\n\
- eye-in-hand control law,\n\
- velocity computed in the camera frame,\n\
- display the camera view,\n\
- a secondary task is the added.\n\
\n\
SYNOPSIS\n\
%s [-c] [-d] [-o] [-h]\n", name);
fprintf(stdout, "\n\
OPTIONS: Default\n\
\n\
-c\n\
Disable the mouse click. Useful to automaze the \n\
execution of this program without humain intervention.\n\
\n\
-d \n\
Turn off the display.\n\
\n\
-o \n\
Disable new projection operator usage for secondary task.\n\
\n\
-h\n\
Print the help.\n");
if (badparam)
fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
}
bool getOptions(int argc, const char **argv, bool &click_allowed, bool &display, bool &new_proj_operator)
{
const char *optarg_;
int c;
switch (c) {
case 'c':
click_allowed = false;
break;
case 'd':
display = false;
break;
case 'o':
new_proj_operator = false;
break;
case 'h':
usage(argv[0], NULL);
return false;
default:
usage(argv[0], optarg_);
return false;
}
}
if ((c == 1) || (c == -1)) {
usage(argv[0], NULL);
std::cerr << "ERROR: " << std::endl;
std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
return false;
}
return true;
}
int main(int argc, const char **argv)
{
#if (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
try {
bool opt_display = true;
bool opt_click_allowed = true;
bool opt_new_proj_operator = true;
if (getOptions(argc, argv, opt_click_allowed, opt_display, opt_new_proj_operator) == false) {
return(EXIT_FAILURE);
}
#ifdef VISP_HAVE_DISPLAY
# if defined VISP_HAVE_X11
# elif defined VISP_HAVE_GTK
# elif defined VISP_HAVE_GDI
# elif defined VISP_HAVE_OPENCV
# elif defined VISP_HAVE_D3D9
# endif
#endif
if (opt_display) {
#if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)
displayI.
init(I, 100, 100,
"Camera view...");
displayExt.
init(Iext, 130 + static_cast<int>(I.
getWidth()), 100,
"External view");
#endif
}
#ifdef VISP_HAVE_DISPLAY
#endif
double px = 600, py = 600;
cMo[0][3] = 0.1;
cMo[1][3] = 0.2;
cMo[2][3] = 2;
wMo = wMc * cMo;
cMod[0][3] = 0;
cMod[1][3] = 0;
cMod[2][3] = 1;
#ifdef VISP_HAVE_DISPLAY
#endif
std::cout << std::endl;
#ifdef VISP_HAVE_DISPLAY
#endif
if (opt_display && opt_click_allowed) {
}
unsigned int iter = 0;
bool stop = false;
bool start_secondary_task = false;
while (iter++ < 2000 && !stop) {
std::cout << "---------------------------------------------" << iter << std::endl;
if (opt_display) {
#ifdef VISP_HAVE_DISPLAY
#endif
}
start_secondary_task = true;
}
if (start_secondary_task) {
de2dt[0] = 0.50;
de2dt[1] = 0.25;
de2dt[2] = 1;
std::cout << "de2dt :" << de2dt.t() << std::endl;
std::cout <<
"(I-WpW)de2dt :" << sec.
t() << std::endl;
v += sec;
if (opt_display && opt_click_allowed) {
std::stringstream ss;
ss << std::string(
"New projection operator: ") + (opt_new_proj_operator ? std::string(
"yes (use option -o to use old one)") :
std::string(
"no"));
}
}
else {
if (opt_display && opt_click_allowed) {
}
}
std::cout <<
"|| s - s* || = " << (task.
getError()).sumSquare() << std::endl;
if (opt_display) {
stop = true;
}
}
}
if (opt_display && opt_click_allowed) {
}
return EXIT_SUCCESS;
std::cout << "Catch a ViSP exception: " << e << std::endl;
return EXIT_FAILURE;
}
#else
(void)argc;
(void)argv;
std::cout << "Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
return EXIT_SUCCESS;
#endif
}