Skip to content

Group dynamic reconfigure parameters under a node

Konstantinos Panayiotou edited this page Jul 2, 2014 · 7 revisions

In case you want to group your parameters for efficiency in the dynamic reconfigure window, consider the following:

Suppose node my_node, whose parameters need to be changed in run time and two structs of parameters: struct debug, which features parameters regarding debugging, and struct general, which features general parameters regarding the function of my_node.

What we want to happen eventually is to have a list of collapsible items in the dynamic reconfigure's window, under the my_node entry, which correspond to parameters under structs debug and general.

First, construct the debug.cfg and general.cfg files as instructed here. Having done that, a separate configuration file needs to be constructed, which will correspond to the node's configuration file. The my_node.cfg file cannot include any parameters. Example:

#!/usr/bin/env python
# Kinect configuration

PACKAGE = 'my_package'

from dynamic_reconfigure.parameter_generator_catkin import *

gen = ParameterGenerator()

exit(gen.generate(PACKAGE, "my_node", "my_node"))

Having concluded the creation of the configuration files, inside class MyNode, two things must be declared:

(a) The configuration files' headers must be included. (b) A nodehandle needs to be created for each configuration file added, except for my_node.cfg whose corresponding nodehandle is the node's nodehandle.

Example:

#include <my_package/my_nodeConfig.h>
#include <my_package/debugConfig.h>
#include <my_package/generalConfig.h>


// The main ROS nodehandle
ros::NodeHandle nodeHandle_;

// The ROS nodehandle needed by the debug_cfg
ros::NodeHandle debugNodeHandle_;

// The ROS nodehandle needed by the general_cfg
ros::NodeHandle generalNodeHandle_;

Next, for each configuration file added, a dynamic reconfigure server and callback type need to be added as private members of class MyNode, like so:

class MYNode
{
  private:
  ...

  // The dynamic reconfigure server for debugging parameters
  dynamic_reconfigure::Server<my_package::debug_Config> serverDebug;

  // The dynamic reconfigure callback type for the above server
  dynamic_reconfigure::Server<my_package::debug_Config>::CallbackType f_debug;

  // The dynamic reconfigure server for general parameters
  dynamic_reconfigure::Server<my_package::general_Config> serverGeneral;

  // The dynamic reconfigure callback type for the above server
  dynamic_reconfigure::Server<my_package::general_Config>::CallbackType f_general;
  ...
}

MyNode's constructor will have to initialize the nodehandles and dynamic reconfigure servers like so:

MyNode::MyNode() :
  nodeHandle_(""),
  debugNodeHandle_("~/debug"),
  serverDebug(debugNodeHandle_),
  generalNodeHandle_("~/general"),
  serverGeneral(generalNodeHandle_)
{
  ...
}

Now, the connection between the callbacks firing when parameters change from within the dynamic reconfigure utility, and the corresponding dynamic reconfigure servers must be declared. In our example, it would look something like this:

class MyNode
{
  ...

  // The dynamic reconfigure server for debugging parameters
  serverDebug.setCallback(boost::bind(&MyNode::parametersCallbackDebug, this, _1, _2));

  // The dynamic reconfigure server for general parameters
  serverGeneral.setCallback(boost::bind(&MyNode::parametersCallbackGeneral, this, _1, _2));

  ...
}

Next, we must privately declare the callbacks. Their signature looks like this:

class MyNode
{
  ...

  void MyNode::parametersCallbackDebug (
    const my_package::debug_Config &config,
    const uint32_t& level);

  void MyNode::parametersCallbackGeneral (
    const pandora_vision_hole_detector::general_Config &config,
    const uint32_t& level);
 
  ...
}

Finally, we need to inlude the configuration files in the CMakeLists.txt file:

generate_dynamic_reconfigure_options(
  ...
  cfg/my_node.cfg
  cfg/debug.cfg
  cfg/general.cfg
 ...
)

Metapackages

###pandora_audio

  • [Audio capture node](Audio Capture Node)
  • [Audio monitoring node](Audio Monitoring Node)
  • [Audio recording node](Audio Recording Node)
  • [Audio processing node](Audio Processing Node)
Clone this wiki locally