[Documentation] [TitleIndex] [WordIndex

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 Plugins

Description: 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.

Plugin Parameters

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:

  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
    my_int: 42
    my_float: 3.14
      my_other_param: .....
    my_array: [1, 2, 3]

Those parameters can be accessed within your plugin by using the builtin param(...) or getParam(...) method.

   1 int my_int = param("my_int", 0);
   2 float my_float;
   3 getParam("my_float", my_float, 0.0f);

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);

External Parameters

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.

Parameter Inheritance

Parameters are inherited by all children. For detailed information read this article.

2019-12-14 13:15