51#include <visp3/core/vpConfig.h>
52#include <visp3/core/vpDebug.h>
54#if defined(VISP_HAVE_THREADS) && defined(VISP_HAVE_DISPLAY) \
55 && (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
64#include <visp3/core/vpCameraParameters.h>
65#include <visp3/core/vpHomogeneousMatrix.h>
66#include <visp3/core/vpImage.h>
67#include <visp3/core/vpImagePoint.h>
68#include <visp3/core/vpIoTools.h>
69#include <visp3/core/vpMath.h>
70#include <visp3/core/vpMeterPixelConversion.h>
71#include <visp3/gui/vpDisplayFactory.h>
72#include <visp3/io/vpParseArgv.h>
73#include <visp3/robot/vpSimulatorAfma6.h>
74#include <visp3/visual_features/vpFeatureBuilder.h>
75#include <visp3/visual_features/vpFeaturePoint.h>
76#include <visp3/vs/vpServo.h>
79#define GETOPTARGS "cdh"
81#ifdef ENABLE_VISP_NAMESPACE
85void usage(
const char *name,
const char *badparam);
86bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
96void usage(
const char *name,
const char *badparam)
99Tests a control law with the following characteristics:\n\
100 - eye-in-hand control\n\
101 - articular velocity are computed\n\
102 - servo on 4 points,\n\
103 - internal and external camera view displays.\n\
106 %s [-c] [-d] [-h]\n",
112 Disable the mouse click. Useful to automate the \n\
113 execution of this program without human intervention.\n\
116 Turn off the display.\n\
122 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
136bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
144 click_allowed =
false;
150 usage(argv[0],
nullptr);
154 usage(argv[0], optarg_);
159 if ((c == 1) || (c == -1)) {
161 usage(argv[0],
nullptr);
162 std::cerr <<
"ERROR: " << std::endl;
163 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
170int main(
int argc,
const char **argv)
172#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
173 std::shared_ptr<vpDisplay> displayInt;
178 bool opt_click_allowed =
true;
179 bool opt_display =
true;
182 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
192#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
201 std::cout << std::endl;
202 std::cout <<
"----------------------------------------------" << std::endl;
203 std::cout <<
" Test program for vpServo " << std::endl;
204 std::cout <<
" Eye-in-hand task control, articular velocity are computed" << std::endl;
205 std::cout <<
" Simulation " << std::endl;
206 std::cout <<
" task : servo 4 points " << std::endl;
207 std::cout <<
"----------------------------------------------" << std::endl;
208 std::cout << std::endl;
222 for (
unsigned int i = 0;
i < 4;
i++)
227 for (
unsigned int i = 0;
i < 4;
i++)
237 for (
unsigned int i = 0;
i < 4;
i++)
238 point[i].track(cdMo);
240 for (
unsigned int i = 0;
i < 4;
i++)
250 for (
unsigned int i = 0;
i < 4;
i++)
251 task.addFeature(p[i], pd[i]);
268 robot.initialiseObjectRelativeToCamera(cMo);
271 robot.setDesiredCameraPosition(cdMo);
275 robot.getCameraParameters(cam, Iint);
280 robot.getInternalView(Iint);
287 unsigned int iter = 0;
289 while (iter++ < 500) {
290 std::cout <<
"---------------------------------------------" <<
iter << std::endl;
297 cMo = robot.get_cMo();
300 std::cout <<
"Initial robot position with respect to the object frame:\n";
305 for (
unsigned int i = 0;
i < 4;
i++) {
314 robot.getInternalView(Iint);
318 if (opt_display && opt_click_allowed && iter == 1) {
320 std::cout <<
"Click in the internal view window to continue..." << std::endl;
325 v =
task.computeControlLaw();
330 std::cout <<
"|| s - s* || " << (
task.getError()).sumSquare() << std::endl;
339 std::cout <<
"Final robot position with respect to the object frame:\n";
342 if (opt_display && opt_click_allowed) {
344 std::cout <<
"Click in the internal view window to end..." << std::endl;
348#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
349 if (display !=
nullptr) {
356 std::cout <<
"Catch a ViSP exception: " <<
e << std::endl;
357#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
358 if (display !=
nullptr) {
364#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
365 if (display !=
nullptr) {
371#elif !(defined(VISP_HAVE_DISPLAY))
374 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface) of OpenCV functionalities to display images..."
376 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
377 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
378 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
379 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
382#elif !(defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
385 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
391 std::cout <<
"You do not have threading capabilities" << std::endl;
392 std::cout <<
"Tip:" << std::endl;
393 std::cout <<
"- Install pthread, configure again ViSP using cmake and build again this example" << std::endl;
Generic class defining intrinsic camera parameters.
@ perspectiveProjWithoutDistortion
Perspective projection without distortion model.
Implementation of column vector and the associated operations.
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)
error that can be emitted by ViSP classes.
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
void track(const vpHomogeneousMatrix &cMo)
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
static double rad(double deg)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
void setWorldCoordinates(double oX, double oY, double oZ)
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
Simulator of Irisa's gantry robot named Afma6.
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.
VISP_EXPORT double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)