watonomous.github.io

  1. Software Division
  2. Software Division Home
  3. Infrastructure Group

[ Software Division : Dynamic Reconfigure Tool ]

Created by [ Vinayak Sharma], last modified on Jan 08, 2020

What is the tool?

The focus of [dynamic_reconfigure] is on providing a standard way to expose a subset of a node's parameters to external reconfiguration. Client programs, e.g., GUIs, can query the node for the set of reconfigurable parameters, including their names, types, and ranges, and present a customized interface to the user. This is especially useful for hardware drivers but has broader applicability [1].

\

The need for the tool

On every alternate Sunday, the bolty is taken to the test track to test the new features and updates made by the team members. One of the major reasons for the delays at the test track revolved around the time taken to change/update certain constants in code base before testing the car. The goal of integrating this dynamic reconfigure tool is to reduce the testing time at the test track by providing the ability to change constants and thus test multiple different scenarios efficiently and quickly.

 

Tutorial on integrating the tool

[http://wiki.ros.org/dynamic_reconfigure/Tutorials]

  1. ** Using the Dynamic Reconfigure CPP client**

 The Code

**         **Now that we have a node that we can reconfigure, we need to write a node to   reconfigure it. Create a file called test_client.cpp in the nodes directory and add the following code to    it: 

#include <ros/ros.h>

#include <dynamic_reconfigure/client.h>

#include <dynamic_tutorials/TestConfig.h>

#include "ref_server.h"




using namespace dynamic_reconfigure;

using namespace dynamic_tutorials;




TestConfig CONFIG;

ConfigDescription DESCRIPTION;



void configurationCallback(const TestConfig& config) {

  ROS_INFO("Reconfigure Request: %d %f %f %s %s %d",

            config.int_param, config.double_param,

            config.double_param_test,

            config.str_param.c_str(),

            config.bool_param?"True":"False",

            config.size);

   CONFIG = config;

}




void descriptionCallback(const ConfigDescription& description) {

  ROS_INFO("Received description");

}



int main(int argc, char** argv) {

  ros::init(argc, argv, "test_client");

  ros::NodeHandle nh;




  Client<TestConfig> client("/ref_server");

  client.setConfigurationCallback(&configurationCallback);

  client.setDescriptionCallback(&descriptionCallback);

  std::cout << "Client Started" << std::endl;


  while (ros::ok()) {

      ROS_INFO("Information %f " , CONFIG.double_param );

  }


  ROS_INFO("Spinning node");

  ros::spin();

  return 0;

}

\

\

We then define a callback which will print the config returned by the server. There are two main differences between this callback and the servers, one it does not need to return an updated config object, two it does not have the "level" argument.

\

void configurationCallback(const TestConfig& config) {
  ROS_INFO("Reconfigure Request: %d %f %f %s %s %d",
            config.int_param, config.double_param,
            config.double_param_test,
            config.str_param.c_str(),
            config.bool_param?"True":"False",
            config.size);
   CONFIG = config;
}

void descriptionCallback(const ConfigDescription& description) {
  ROS_INFO("Received description");
}

CONFIG variable is used to store the CONFIG so that it could be used across access the variables sored in the config across multiple dependent files.

 

The code below is from the ref_server.h which is used to store the extern variable CONFIG which can used across multiple to access the variables stores in the config.

#ifndef REF_SERVER_H
#define REF_SERVER_H

#include <ros/ros.h>
#include <dynamic_reconfigure/client.h>
#include <dynamic_tutorials/TestConfig.h>

using namespace dynamic_reconfigure;
using namespace dynamic_tutorials;

extern dynamic_tutorials::TestConfig CONFIG;

extern double test;
#endif

\

In a separate terminal you need to run: rosrun rqt_reconfigure rqt_reconfigure and then hit refresh. This would popup a GUI called rqt_reconfigure which is used to change/update the values shown in the GUI stored in the cfg file. http://wiki.ros.org/rqt_reconfigure for more info.

Run It!

Once again make the node executable: [chmod +x src/test_client.cpp]{.inline-comment-marker data-ref=”9614b216-9110-4a3d-8d68-f203134094f9”}.  Launch a core and your server node and launch your new client node. If you've done everything correctly, both your client and server should begin to print out matching configurations whenever there is a change in values from the rqt_reconfigure GUI.

\

[Storing the value updates in the ROSBag]

The nodes where you can access the updated values:

rostopic ref_server/parameter_updates

ref_server dynamic node server

\

[YAML file to use the stored variable config]

Example:

<node name="prediction" pkg="dynamic_reconfigure" type="dynparam" args="load processing_server/parameter_updates $(find state_machine)/src/dynamic_config/processing_config.yaml" />

\

\

\

Document generated by Confluence on Dec 10, 2021 04:01

Atlassian