|Note: This tutorial assumes that you have completed the previous tutorials: Create and Export new Plugin.|
|Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.|
How to use Dynamic Parameters in PluginsDescription: This tutorial describes how to (re)configure your plugins during runtime.
Keywords: plugin, parameters, reconfigure
Tutorial Level: BEGINNER
Next Tutorial: Working with the Plugin Manager
Actually the vigir_pluginlib supports two different way to provide parameters to the plugins.
The plugin description config can be extended by a param tag, where you can add in yaml-style your custom parameters passed to the plugin during instantiation. Thus, those parameters are ideal for static parameters that will likely not change after instantiation of the plugin. The example from above extends to:
# PLUGIN DESCRIPTION FILE my_concrete_plugin: type_class_package: my_concrete_plugins_pkg type_class: my_concrete_plugins_ns::MyConcretePlugin base_class_package: my_interface_plugins_pkg base_class: my_interface_plugins_ns::MyInterfacePlugin params: my_int: 42 my_float: 3.14 my_param_namespace: my_other_param: ..... my_array: [1, 2, 3] ...
Those parameters can be accessed within your plugin by using the builtin param(...) or getParam(...) method.
It is advised to store all parameters into a private field of your plugin class during the loadParams(params) call instead of obtaining them each time.
Note: If you want to use optional parameters and do not care about warnings, then you can set the ignore_warning flag to true, when calling the param(...) or getParam(...) method.
1 int my_int = param("my_int", 0, true);
The vigir_pluginlib takes already use of the vigir_generic_params package. When overriding the loadParams(...) method, you can access all needed parameters from the given parameter set. This method is recommended, when parameter are supposed to be changed during runtime. Parameter (re)loading can be triggerd by PluginManager::loadParams(params), where params is a plugin set from the vigir_generic_params package.
Parameters are inherited by all children. For detailed information read this article.