mc_rtc::Configuration
general purpose configurationIn some instances, you may want to display graphs while a controller is running (for example, when tuning the gains of a stabilizer). One option to do this is to open the on-going log and plot the data you’re interested in. With long running experiments this can become cumbersome as the log size grows as does the time needed to open the log and process it.
The better option, presented in this tutorial, is to let your controller display an on-going log.
For the sake of clarity, in the examples, we will assume the following code snippet is present:
The two examples show how to create a graph with a shared abscissa and a graph without a shared abscissa.
In the first case, we must provide an absicssa constructed by mc_rtc::gui::plot::X
and plot data constructed by mc_rtc::gui::plot::Y
, mc_rtc::gui::plot::XY
or mc_rtc::gui::plot::Polygon(s)
. For the remainder of this document we will call this type of plots “regular plots”.
In the second case, we only need to proivde data constructed by mc_rtc::gui::plot::XY
or mc_rtc::gui::plot::Polygon(s)
. For the remainder of this document we will call this type of pots “XY plots”.
Both types of plots can be removed in the same way:
That’s the gist of it! In the next sections we will take a closer look at each of the elements introduced in the examples.
mc_rtc::gui::plot::AxisConfiguration
This class lets you manipulate the name and the range of a given axis. By default the range is [-inf, +inf]
which tells the GUI client to automatically guess the limits.
In a regular plot, the abscissa configuration is provided by mc_rtc::gui::plot::X
. In our first example, we only provided the name as the first argument but it can also accept a full configuration. For example:
In a XY plot, the abscissa configuration is optional, if you wish to provide it then an mc_rtc::gui::plot::AxisConfiguration
must be provided as the first argument of addXYPlot
. For example:
The ordinates can be configured by providing an AxisConfiguration
object for the left and right axis:
In both cases, the right Y axis configuration must be provided after the left Y axis configuration.
mc_rtc::gui::plot::X
There is not much to add at this point, you must provide two elements:
AxisConfiguration
for the abscissadouble
mc_rtc::gui::plot::Y
This has three required arguments and two optional arguments:
double
(required)Color
or a callback that returns a Color
(required)Style
, this defaults to Style::Solid
Side
to put the data on left Y axis or right Y axis, this defaults to Side::Left
Convenience functions are provided to specify the Style
and Side
after constructing the object.
mc_rtc::gui::plot::Style
Four line styles are available:
Style::Solid
is a solid line;Style::Dashed
is a dashed line;Style::Dotted
is a dotted line;Style::Point
replaces the line with a single point;mc_rtc::gui::plot::XY
This has four required arguments and two optional arguments:
double
for the abscissa value (x) (required)double
for the ordinate value (y) (required)Color
or a callback that returns a Color
(required)Style
, this defaults to Style::Solid
Side
to put the data on left Y axis or right Y axis, this defaults to Side::Left
Convenience functions are provided to specify the Style
and Side
after constructing the object.
mc_rtc::gui::plot::Polygon
This has two required arguments and one optional argument:
PolygonDescription
, we introduce this next (required)Side
to put the data on left Y axis or right Y axis, this defaults to Side::Left
A convenience function is provided to specify the Side
after constructing the object.
mc_rtc::gui::plot::PolygonDescription
This object holds the following information:
points()
is a list of points (i.e. an std::vector<std::array<double, 2>>
)outline()
is the Color
of the polygon outlinestyle()
is the line Style
of the polygon outline (defaults to Style::Solid
)fill()
is the Color
used to fill the polygon when it is closed (defaults to transparent, i.e. no filling)closed()
tells whether the polygon is closed (defaults to true)Note: if the polygon is closed, you don’t need to repeat the first point at the end of points()
, this will be handled by the client.
Note: since mc_rtc::gui::plot::Polygon
callback returns a PolygonDescription
you are free to change the display style of this polygon anytime while the plot is active.
mc_rtc::gui::plot::Polygons
This is similar to mc_rtc::gui::plot::Polygon
but the callback must return an std::vector<PolygonDescription>
. This allows you to provide a changing set of polygons while the plot is active to create simple animations.
The API presented in the introduction may give you trouble if you want to build a graph from a selection done at runtime. This can be achieved using the mc_rtc::gui::StateBuilder::addPlotData
method as shown below:
Note: this makes some runtime checks
- If the provided plot does not exist, the call has no effect
- If the provided data is one dimensional but the graph is an XY plot, the call has no effect
The examples we provided so far always provide a single point of data at a time. However, the XY plot supports an additional signature that allow you to provide an arbitrary number of points at a time. This can be useful to plot data that comes in asynchronously or to draw a single plot at once.
Note: This is only supported with XY plots as we would not be able to synchronize a Y plot correctly otherwise.