Yarp 3.10 Feature preview: the new yarpDeviceParamParserGenerator tool #3081
randaz81
started this conversation in
Architecture
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Dear @robotology/everyone,
Yarp 3.10 introduces a new tool,
yarpDeviceParamParserGenerator
, which allows the automatic code generation for parameter parsers of Yarp devices/plugins. In this way, code, documentation and examples will be always updated and consistent!Since the tool documentation will appear on the website only after the official software release, I'm putting below a preview of the tool documentation. Please note that some minor details can still change, so I encourage you to check https://yarp.it/latest// for the latest version after yarp 3.10 release.
yarpDeviceParamParserGenerator: YARP code generator/compiler for parameters parsers
Description
yarpDeviceParamParserGenerator is an executable which generates code (.cpp .h files) which simplifies the development of yarp devices.
More specifically, it generates the devices parameters parsers, the corresponding doxygen documentation, the helper functions and the
usage examples.
Command Line
yarpDeviceParamParserGenerator can be executed from the command line. The syntax is the following:
or
Please note that the two parameters input_filename_ini and input_filename_md are mutually exclusive, since the generator will accept as input only a .ini or a .md file.
Also remember that invoking yarpDeviceParamParserGenerator by command line is fine for small, temporary projects or for testing purposes, but it is
much more convenient to automatize the process by invoking it from the CMakeLists.txt of the project, as indicated in the next sections.
Input files
Two types of input files are currently supported, .ini and .md. The content of the two files must match the following intuitive specifications:
\subsection yarpDeviceParamParserGenerator_input_files_ini_file ini file
Notes:
Otherwise, by the default, the variable name will be: m_myGroupName_myParamName.
the field defaultValue will be used for documentation purposes only (the user will have to provide a valid value for the required parameter for instantiating the device,
but the default value can be used as a template/hint)
\subsection yarpDeviceParamParserGenerator_input_files_md_file md file
Notes:
Output files
yarpDeviceParamParserGenerator will generate the following files:
(.cpp and .h files)
The generated .cpp and .h files contains the code (including Doxygen documentation) for parsing the parameters.
In order to use it, the user has to include the .h file and publicly derive its class from the generated one,
as shown in this snippet example for the class ChatBot_nwc_yarp:
Then the parsing of the parameters can be done in the open() method as shown below:
In this way the device will not be opened if the parameters parser fails, which can occur if one of the following conditions happens:
The parameters that have been successfully parsed store their value in ad hoc-generated variables whose names correspond
to the name of the parameter, as discussed in the yarpDeviceParamParserGenerator_extra_notes section.
(Other files)
If the parameters [--generate_yarpdev] or [--generate_yarprobotinterface] options are requested, yarpDeviceParamParserGenerator will
also generate a .ini file and .xml file which demonstrate how to open the device using yarpdev and yarprobotinterface respectively.
Please note that these files are just templates, because they may need additional customization to be successfully executed,
depending on the meaning of specific parameters (e.g. when a real hardware is involved).
CMake Usage
yarpDeviceParamParserGenerator usage can be integrated in the CMakeLists.txt of a device.
The usage is very simple: user has to add the generateDeviceParamsParser() command, whose input parameter must match the name of the class
of the device, in this case ChatBot_nws_yarp. yarpDeviceParamParserGenerator will generate the two files ChatBot_nws_yarp_ParamsParser.cpp,
ChatBot_nws_yarp_ParamsParser.h which must be added to target_sources.
please note that the CMake
generateDeviceParamsParser()
function, which is included by YarpDeviceParamsParserGenerator.cmake, has no effectif the CMake option ALLOW_DEVICE_PARAM_PARSER_GENERATION is set to off (which is the default value). If it is set to on, instead, the output files will be regenerated,
even if they are already existing. Every local edit will be thus overwritten. Additional details about how the generateDeviceParamsParser() function works
internally (e.g. which parameters are employed foe the call of the executable yarpDeviceParamsParserGenerator) are explained directly inside the
file YarpDeviceParamsParserGenerator.cmake
Extra Notes
will be displayed on user request (for example invoking the --help option)
Beta Was this translation helpful? Give feedback.
All reactions