53 #include <visp3/core/vpConfig.h>
54 #include <visp3/core/vpDebug.h>
56 #if defined(VISP_HAVE_THREADS) && defined(VISP_HAVE_DISPLAY) \
57 && (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
66 #include <visp3/core/vpCameraParameters.h>
67 #include <visp3/core/vpHomogeneousMatrix.h>
68 #include <visp3/core/vpImage.h>
69 #include <visp3/core/vpImagePoint.h>
70 #include <visp3/core/vpIoTools.h>
71 #include <visp3/core/vpMath.h>
72 #include <visp3/core/vpMeterPixelConversion.h>
73 #include <visp3/gui/vpDisplayFactory.h>
74 #include <visp3/io/vpParseArgv.h>
75 #include <visp3/robot/vpSimulatorAfma6.h>
76 #include <visp3/visual_features/vpFeatureBuilder.h>
77 #include <visp3/visual_features/vpFeaturePoint.h>
78 #include <visp3/vs/vpServo.h>
81 #define GETOPTARGS "cdh"
83 #ifdef ENABLE_VISP_NAMESPACE
87 void usage(
const char *name,
const char *badparam);
88 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display);
98 void usage(
const char *name,
const char *badparam)
101 Tests a control law with the following characteristics:\n\
102 - eye-in-hand control\n\
103 - articular velocity are computed\n\
104 - servo on 4 points,\n\
105 - internal and external camera view displays.\n\
108 %s [-c] [-d] [-h]\n",
114 Disable the mouse click. Useful to automate the \n\
115 execution of this program without human intervention.\n\
118 Turn off the display.\n\
124 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
138 bool getOptions(
int argc,
const char **argv,
bool &click_allowed,
bool &display)
146 click_allowed =
false;
152 usage(argv[0],
nullptr);
157 usage(argv[0], optarg_);
163 if ((c == 1) || (c == -1)) {
165 usage(argv[0],
nullptr);
166 std::cerr <<
"ERROR: " << std::endl;
167 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
174 int main(
int argc,
const char **argv)
176 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
177 std::shared_ptr<vpDisplay> displayInt;
182 bool opt_click_allowed =
true;
183 bool opt_display =
true;
186 if (getOptions(argc, argv, opt_click_allowed, opt_display) ==
false) {
196 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
205 std::cout << std::endl;
206 std::cout <<
"----------------------------------------------" << std::endl;
207 std::cout <<
" Test program for vpServo " << std::endl;
208 std::cout <<
" Eye-in-hand task control, articular velocity are computed" << std::endl;
209 std::cout <<
" Simulation " << std::endl;
210 std::cout <<
" task : servo 4 points " << std::endl;
211 std::cout <<
"----------------------------------------------" << std::endl;
212 std::cout << std::endl;
226 for (
unsigned int i = 0; i < 4; i++)
231 for (
unsigned int i = 0; i < 4; i++)
241 for (
unsigned int i = 0; i < 4; i++)
242 point[i].track(cdMo);
244 for (
unsigned int i = 0; i < 4; i++)
254 for (
unsigned int i = 0; i < 4; i++)
261 vpSimulatorAfma6 robot(opt_display);
272 robot.initialiseObjectRelativeToCamera(cMo);
275 robot.setDesiredCameraPosition(cdMo);
279 robot.getCameraParameters(cam, Iint);
284 robot.getInternalView(Iint);
291 unsigned int iter = 0;
293 while (iter++ < 500) {
294 std::cout <<
"---------------------------------------------" << iter << std::endl;
301 cMo = robot.get_cMo();
304 std::cout <<
"Initial robot position with respect to the object frame:\n";
309 for (
unsigned int i = 0; i < 4; i++) {
318 robot.getInternalView(Iint);
322 if (opt_display && opt_click_allowed && iter == 1) {
324 std::cout <<
"Click in the internal view window to continue..." << std::endl;
334 std::cout <<
"|| s - s* || " << (task.
getError()).sumSquare() << std::endl;
343 std::cout <<
"Final robot position with respect to the object frame:\n";
346 if (opt_display && opt_click_allowed) {
348 std::cout <<
"Click in the internal view window to end..." << std::endl;
352 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
353 if (display !=
nullptr) {
360 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
361 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
362 if (display !=
nullptr) {
368 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
369 if (display !=
nullptr) {
375 #elif !(defined(VISP_HAVE_DISPLAY))
378 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface) of OpenCV functionalities to display images..."
380 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
381 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
382 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
383 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
386 #elif !(defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
389 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
395 std::cout <<
"You do not have threading capabilities" << std::endl;
396 std::cout <<
"Tip:" << std::endl;
397 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 vpImagePoint &t)
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.
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)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
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)
void setServo(const vpServoType &servo_type)
vpColVector getError() const
vpColVector computeControlLaw()
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 int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()