 |
Visual Servoing Platform
version 3.3.0
|
49 #include <visp3/core/vpCameraParameters.h>
50 #include <visp3/core/vpHomogeneousMatrix.h>
51 #include <visp3/core/vpImage.h>
52 #include <visp3/core/vpIoTools.h>
53 #include <visp3/core/vpMath.h>
54 #include <visp3/core/vpSphere.h>
55 #include <visp3/core/vpTime.h>
56 #include <visp3/core/vpVelocityTwistMatrix.h>
57 #include <visp3/gui/vpDisplayD3D.h>
58 #include <visp3/gui/vpDisplayGDI.h>
59 #include <visp3/gui/vpDisplayGTK.h>
60 #include <visp3/gui/vpDisplayOpenCV.h>
61 #include <visp3/gui/vpDisplayX.h>
62 #include <visp3/io/vpImageIo.h>
63 #include <visp3/io/vpParseArgv.h>
64 #include <visp3/robot/vpSimulatorCamera.h>
65 #include <visp3/robot/vpWireFrameSimulator.h>
66 #include <visp3/visual_features/vpFeatureBuilder.h>
67 #include <visp3/visual_features/vpGenericFeature.h>
68 #include <visp3/vs/vpServo.h>
70 #define GETOPTARGS "dh"
72 #ifdef VISP_HAVE_DISPLAY
74 void usage(
const char *name,
const char *badparam);
75 bool getOptions(
int argc,
const char **argv,
bool &display);
87 void usage(
const char *name,
const char *badparam)
90 Demonstration of the wireframe simulator with a simple visual servoing.\n\
92 The visual servoing consists in bringing the camera at a desired position from the object.\n\
94 The visual features used to compute the pose of the camera and thus the control law are special moments computed with the sphere's parameters.\n\
97 %s [-d] [-h]\n", name);
102 Turn off the display.\n\
108 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
122 bool getOptions(
int argc,
const char **argv,
bool &display)
133 usage(argv[0], NULL);
138 usage(argv[0], optarg_);
144 if ((c == 1) || (c == -1)) {
146 usage(argv[0], NULL);
147 std::cerr <<
"ERROR: " << std::endl;
148 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
168 double gx = sphere.
get_x();
169 double gy = sphere.
get_y();
175 if (std::fabs(gx) > std::numeric_limits<double>::epsilon() || std::fabs(gy) > std::numeric_limits<double>::epsilon())
181 double sx = gx * h2 / (sqrt(h2 + 1));
182 double sy = gy * h2 / (sqrt(h2 + 1));
183 double sz = sqrt(h2 + 1);
198 L[0][0] = -1 / sphere.
getR();
199 L[1][1] = -1 / sphere.
getR();
200 L[2][2] = -1 / sphere.
getR();
209 for (
unsigned int i = 0; i < 3; i++)
210 for (
unsigned int j = 0; j < 3; j++)
211 L[i][j + 3] = sk[i][j];
214 int main(
int argc,
const char **argv)
217 bool opt_display =
true;
220 if (getOptions(argc, argv, opt_display) ==
false) {
228 #if defined VISP_HAVE_X11
230 #elif defined VISP_HAVE_OPENCV
232 #elif defined VISP_HAVE_GDI
234 #elif defined VISP_HAVE_D3D9
236 #elif defined VISP_HAVE_GTK
242 display[0].init(Iint, 100, 100,
"The internal view");
243 display[1].init(Iext1, 100, 100,
"The first external view");
244 display[2].init(Iext2, 100, 100,
"The second external view");
258 float sampling_time = 0.040f;
286 computeVisualFeatures(sphere, s);
292 computeVisualFeatures(sphere, sd);
295 computeInteractionMatrix(sd, sphere, L);
296 sd.setInteractionMatrix(L);
363 std::cout <<
"Click on a display" << std::endl;
375 while (iter++ < stop) {
393 computeVisualFeatures(sphere, s);
401 camoMf.buildFrom(0, 0.0, 2.5, 0,
vpMath::rad(150), 0);
432 std::cout <<
"|| s - s* || = " << (task.
getError()).sumSquare() << std::endl;
439 std::cout <<
"Catch an exception: " << e << std::endl;
446 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface), or GTK functionalities to display images..." << std::endl;
447 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
448 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
449 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
450 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
@ SPHERE
A 15cm radius sphere.
void setExternalCameraPosition(const vpHomogeneousMatrix &cam_Mf)
static double sqr(double x)
VISP_EXPORT int wait(double t0, double t)
vpHomogeneousMatrix get_fMo() const
static void setWindowPosition(const vpImage< unsigned char > &I, int winx, int winy)
static double rad(double deg)
Generic class defining intrinsic camera parameters.
void set_eJe(const vpMatrix &eJe_)
void setPosition(const vpHomogeneousMatrix &wMc)
void setMaxTranslationVelocity(double maxVt)
void getExternalImage(vpImage< unsigned char > &I)
Implementation of a wire frame simulator. Compared to the vpSimulator class, it does not require thir...
Display for windows using GDI (available on any windows 32 platform).
void set_fMo(const vpHomogeneousMatrix &fMo_)
void get_s(vpColVector &s) const
get the value of all the features.
void set_cVe(const vpVelocityTwistMatrix &cVe_)
Class that enables to define a feature or a set of features which are not implemented in ViSP as a sp...
Class that consider the case of a translation vector.
static const vpColor none
void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_)
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Class that defines the simplest robot: a free flying camera.
Implementation of column vector and the associated operations.
void setInternalCameraParameters(const vpCameraParameters &cam)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1, const vpImagePoint &offset=vpImagePoint(0, 0))
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Implementation of a matrix and operations on matrices.
void setServo(const vpServoType &servo_type)
VISP_EXPORT double measureTimeMs()
void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
vpHomogeneousMatrix getPosition() const
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
static void display(const vpImage< unsigned char > &I)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
void setCameraPositionRelObj(const vpHomogeneousMatrix &cMo_)
void setMaxRotationVelocity(double maxVr)
vpColVector getError() const
void get_eJe(vpMatrix &eJe)
Class that defines what is a sphere.
void setExternalCameraParameters(const vpCameraParameters &cam)
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
void set_s(const vpColVector &s)
set the value of all the features.
vpColVector computeControlLaw()
static void flush(const vpImage< unsigned char > &I)
virtual void setSamplingTime(const double &delta_t)
vpHomogeneousMatrix inverse() const
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
error that can be emited by ViSP classes.
void track(const vpHomogeneousMatrix &cMo)
vpHomogeneousMatrix getExternalCameraPosition() const
void getInternalImage(vpImage< unsigned char > &I)