Important considerations about configuration files and the usage of yarp methods find() and findGroup() #3092
randaz81
started this conversation in
Design Documents
Replies: 3 comments
-
cc @robotology/everyone |
Beta Was this translation helpful? Give feedback.
0 replies
-
fyi @xela-95 |
Beta Was this translation helpful? Give feedback.
0 replies
-
For reference,
So if you use YARP plugins for gazebo and you want to use the recommended style for vector variable, now you can! fyi @xela-95 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In brief:
If you are a developer, check if your rfmodule/device/application is using config files with the following syntax:
wrong ini file:
my_parameter_list 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0
wrong xml file:
<param name="my_parameter_list "> 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 </param>
This syntax is NOT correct and might be not supported in the future. Please use the parenthesis to represent a list of values :
correct ini file:
my_parameter_list (100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0)
correct xml file
<param name="my_parameter_list "> (100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0) </param>
Regarding the source code that parses the list of parameters, you should use something like:
instead of:
Actions:
Long explanations:
As discussed in #3081, we are currently trying to automatize the cumbersome and error-prone process of the parameters parsing using a new tool that automatically generates the required code and the documentation.
We thus refactored many yarp devices with manually written parsers, fixing the errors we encountered along the process and noticing the most frequent ones.
One of these errors is indeed the use of the
findGroup()
method.This method was originally developed to obtain a subgroup (subsection) of parameters from a larger one. Let's consider the following .ini example:
The following method:
will return a Bottle of 4 elements which are:
which can be further processed to obtain the contents of the individual parameters as follows:
This way of using
findGroup()
is fine. However, problems arise if it is used on a key that is not a section, since the method will return a valid bottle also in this case (a better design of the method should imply its failure in the case it is called on something that is not a section). The resulting bottle contains the key and its value (2 elements) or a list of n+1 elements in the case of a vector. For example:The second example must be noticed carefully: a list included by the parenthesis is transformed into a bottle which requires an additional level of parsing.
This behavior is NOT correct and it is NOT consistent with the behavior of the method
find()
, as shown below:Therefore, if the user modifies the configuration file, adding the parenthesis (which is the correct syntax) without knowing how the parser is designed, i.e. which method is using:
find()
orfindGroup()
, it will result in an incorrect parsing.This is bad also from the design point of view. Given a configuration file, a parser should not give different results depending on which method is used.
Please note that all automatically generated parsers use the
find()
method and assume that list of values are included between parenthesis.Beta Was this translation helpful? Give feedback.
All reactions