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/gui/vpPlot.h> 63 #include <visp3/io/vpImageIo.h> 64 #include <visp3/io/vpParseArgv.h> 65 #include <visp3/robot/vpSimulatorCamera.h> 66 #include <visp3/robot/vpWireFrameSimulator.h> 67 #include <visp3/visual_features/vpFeatureBuilder.h> 68 #include <visp3/visual_features/vpGenericFeature.h> 69 #include <visp3/vs/vpServo.h> 71 #define GETOPTARGS "dhp" 73 #if defined(VISP_HAVE_DISPLAY) \ 74 && (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV)) 84 void usage(
const char *name,
const char *badparam)
87 Demonstration of the wireframe simulator with a simple visual servoing.\n\ 89 The visual servoing consists in bringing the camera at a desired position from the object.\n\ 91 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\ 94 %s [-d] [-p] [-h]\n", name);
99 Turn off the display.\n\ 102 Turn off the plotter.\n\ 108 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
123 bool getOptions(
int argc,
const char **argv,
bool &display,
bool &plot)
137 usage(argv[0], NULL);
141 usage(argv[0], optarg_);
146 if ((c == 1) || (c == -1)) {
148 usage(argv[0], NULL);
149 std::cerr <<
"ERROR: " << std::endl;
150 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
171 double gx = sphere.
get_x();
172 double gy = sphere.
get_y();
178 if (std::fabs(gx) > std::numeric_limits<double>::epsilon() || std::fabs(gy) > std::numeric_limits<double>::epsilon())
184 double sx = gx * h2 / (sqrt(h2 + 1));
185 double sy = gy * h2 / (sqrt(h2 + 1));
186 double sz = sqrt(h2 + 1);
201 L[0][0] = -1 / sphere.
getR();
202 L[1][1] = -1 / sphere.
getR();
203 L[2][2] = -1 / sphere.
getR();
212 for (
unsigned int i = 0; i < 3; i++)
213 for (
unsigned int j = 0; j < 3; j++)
214 L[i][j + 3] = sk[i][j];
217 int main(
int argc,
const char **argv)
220 bool opt_display =
true;
221 bool opt_plot =
true;
224 if (getOptions(argc, argv, opt_display, opt_plot) ==
false) {
232 #if defined VISP_HAVE_X11 234 #elif defined VISP_HAVE_OPENCV 236 #elif defined VISP_HAVE_GDI 238 #elif defined VISP_HAVE_D3D9 240 #elif defined VISP_HAVE_GTK 246 display[0].
init(Iint, 100, 100,
"The internal view");
247 display[1].
init(Iext1, 100, 100,
"The first external view");
248 display[2].
init(Iext2, 100, 100,
"The second external view");
264 float sampling_time = 0.020f;
292 computeVisualFeatures(sphere, s);
298 computeVisualFeatures(sphere, sd);
301 computeInteractionMatrix(sd, sphere, L);
302 sd.setInteractionMatrix(L);
320 plotter =
new vpPlot(2, 480, 640, 750, 550,
"Real time curves plotter");
321 plotter->
setTitle(0,
"Visual features error");
322 plotter->
setTitle(1,
"Camera velocities");
325 plotter->
setLegend(0, 0,
"error_feat_sx");
326 plotter->
setLegend(0, 1,
"error_feat_sy");
327 plotter->
setLegend(0, 2,
"error_feat_sz");
388 std::cout <<
"Click on a display" << std::endl;
403 while (iter++ < max_iter && !stop) {
422 computeVisualFeatures(sphere, s);
430 camoMf.buildFrom(0, 0.0, 2.5, 0,
vpMath::rad(150), 0);
435 plotter->
plot(1, iter, v);
461 std::stringstream ss;
462 ss <<
"Loop time: " << t - t_prev <<
" ms";
476 std::cout <<
"|| s - s* || = " << (task.
getError()).sumSquare() << std::endl;
479 if (opt_plot && plotter != NULL) {
496 std::cout <<
"Catch an exception: " << e << std::endl;
500 #elif !(defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV)) 503 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
509 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface), or GTK functionalities to display images..." << std::endl;
510 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
511 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
512 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
513 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
void setPosition(const vpHomogeneousMatrix &wMc)
Implementation of a matrix and operations on matrices.
unsigned int getDimension() const
Return the task dimension.
VISP_EXPORT int wait(double t0, double t)
void set_s(const vpColVector &s)
set the value of all the features.
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines the simplest robot: a free flying camera.
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
void set_fMo(const vpHomogeneousMatrix &fMo_)
Display for windows using GDI (available on any windows 32 platform).
void set_eJe(const vpMatrix &eJe_)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
static const vpColor none
error that can be emited by ViSP classes.
void track(const vpHomogeneousMatrix &cMo)
void setExternalCameraPosition(const vpHomogeneousMatrix &cam_Mf)
Class that defines a 3D sphere in the object frame and allows forward projection of a 3D sphere in th...
void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_)
void setLegend(unsigned int graphNum, unsigned int curveNum, const std::string &legend)
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void setMaxRotationVelocity(double maxVr)
void get_s(vpColVector &s) const
get the value of all the features.
virtual void setSamplingTime(const double &delta_t)
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed...
vpColVector getError() const
vpHomogeneousMatrix get_fMo() const
vpColVector computeControlLaw()
static double sqr(double x)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Generic class defining intrinsic camera parameters.
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="")
void setTitle(unsigned int graphNum, const std::string &title)
void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
vpHomogeneousMatrix getPosition() const
void plot(unsigned int graphNum, unsigned int curveNum, double x, double y)
void getExternalImage(vpImage< unsigned char > &I)
Implementation of a wire frame simulator. Compared to the vpSimulator class, it does not require thir...
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
static double rad(double deg)
void setExternalCameraParameters(const vpCameraParameters &cam)
void setCameraPositionRelObj(const vpHomogeneousMatrix &cMo_)
void initGraph(unsigned int graphNum, unsigned int curveNbr)
void getInternalImage(vpImage< unsigned char > &I)
static void setWindowPosition(const vpImage< unsigned char > &I, int winx, int winy)
Implementation of column vector and the associated operations.
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))
void set_cVe(const vpVelocityTwistMatrix &cVe_)
vpHomogeneousMatrix inverse() const
void setInternalCameraParameters(const vpCameraParameters &cam)
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Class that enables to define a feature or a set of features which are not implemented in ViSP as a sp...
void get_eJe(vpMatrix &eJe)
void setServo(const vpServoType &servo_type)
void setMaxTranslationVelocity(double maxVt)
Class that consider the case of a translation vector.
vpHomogeneousMatrix getExternalCameraPosition() const