File: tutorial-plotter.dox

package info (click to toggle)
visp 3.6.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 119,296 kB
  • sloc: cpp: 500,914; ansic: 52,904; xml: 22,642; python: 7,365; java: 4,247; sh: 482; makefile: 237; objc: 145
file content (97 lines) | stat: -rw-r--r-- 3,748 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**

\page tutorial-plotter Tutorial: Real-time curves plotter tool
\tableofcontents

This tutorial focuses on real-time curves drawing. It shows how to modify tutorial-ibvs-4pts.cpp introduced in \ref tutorial-ibvs to draw the evolution of the visual features error and the camera velocity skew vector during an image-based visual servoing.

Note that all the material (source code and image) described in this tutorial is part of ViSP source code and could be downloaded using the following command:

\code
$ svn export https://github.com/lagadic/visp.git/trunk/tutorial/visual-servoing/ibvs
\endcode

The modified code also available in tutorial-ibvs-4pts-plotter.cpp is the following.


\include tutorial-ibvs-4pts-plotter.cpp

The last image of the drawing is the following:

\image html img-ibvs-plotter.jpg Last image produced by the plotter.

Now we describe the new lines that were introduced:

\code
#include <visp3/core/vpPlot.h>
\endcode

Include the header of the vpPlot class that allows curves drawing.

\code
#ifdef VISP_HAVE_DISPLAY
  vpPlot plotter(2, 250*2, 500, 100, 200, "Real time curves plotter");
\endcode

Since the plotter opens a windows to display the graphics, the usage of vpPlot class is only possible if ViSP is build with a 3rd party that allows display capabilities; either libx11, GDI, OpenCV or GTK. If this is the case, we create an instance of the vpPlot class. The window that is created will contain two graphics. The windows size will be 500 by 500 pixels. The window position will be (100, 200), and the title "Real time curves plotter".

\code
  plotter.setTitle(0, "Visual features error");
  plotter.setTitle(1, "Camera velocities");
\endcode

To differentiate the graphics we associate a title to each of them. The first graphic (the one with index 0) will be designed to draw the evolution of the visual features error, while the second (index 1) will be designed to draw the camera velocities.

\code
  plotter.initGraph(0, 8);
  plotter.initGraph(1, 6);
\endcode

Here we initialize the first graphic to be able to plot 8 curves. We recall that we have 4 points, each point has 2 visual features (x and y), that is why there are 8 curves to plot. The second graphic is designed to plot 6 curves corresponding to the camera velocities (3 translation velocities in m/s and 3 rotation velocities in rad/s).

\code
  plotter.setLegend(0, 0, "x1");
  plotter.setLegend(0, 1, "y1");
  plotter.setLegend(0, 2, "x2");
  plotter.setLegend(0, 3, "y2");
  plotter.setLegend(0, 4, "x3");
  plotter.setLegend(0, 5, "y3");
  plotter.setLegend(0, 6, "x4");
  plotter.setLegend(0, 7, "y4");

  plotter.setLegend(1, 0, "v_x");
  plotter.setLegend(1, 1, "v_y");
  plotter.setLegend(1, 2, "v_z");
  plotter.setLegend(1, 3, "w_x");
  plotter.setLegend(1, 4, "w_y");
  plotter.setLegend(1, 5, "w_z");
#endif
\endcode

The previous lines allow to associate a legend to each curve.
 
\code
#ifdef VISP_HAVE_DISPLAY
    plotter.plot(0, iter, task.getError());
    plotter.plot(1, iter, v);
#endif
\endcode

Once the plotter is initialized, in the servo loop we add at each iteration the corresponding values of the visual features error \f${\bf e}(t) = {\bf s}-{\bf s}^*\f$, and the camera velocities \f${\bf v}_c\f$.

\code
#ifdef VISP_HAVE_DISPLAY
  plotter.saveData(0, "error.dat");
  plotter.saveData(1, "vc.dat");
#endif
\endcode

At the end of the servo loop, we save the data that were plotted in two separate files, one for each graphic. The first line of each text file is the graphic title. Then the coordinates along x,y and z are given in separated columns for each data. 

\code
  vpDisplay::getClick(plotter.I);
\endcode

Before exiting the program we wait for a human mouse click in the plotter window.
 
*/