Bootstrap

dynamic_reconfigure


这个stack包含dynamic_reconfigure包,他提供了一种不必更改重启节点,而随时更改节点参数的方法。

1.reconfugure_gui

reconfigure_gui工具现在由rqt提供。

rosrunrqt_reconfigure rqt_reconfigure


  1. howto write your first .cfg file.

  1. createa package called dynamic_tutorials

roscreate-pkg dynamic_tutorials rospy roscpp dynamic_reconfigure
(2) the cfg file

切换行号显示

   1 #!/usr/bin/env python
   2 PACKAGE = "dynamic_tutorials"
   3 
   4 import roslib;roslib.load_manifest(PACKAGE)
   5 
   6 from dynamic_reconfigure.parameter_generator import *
   7 
   8 gen = ParameterGenerator()
   9 
  10 gen.add("int_param", int_t, 0, "An Integer parameter", 50, 0, 100)
  11 gen.add("double_param", double_t, 0, "A double parameter", .5, 0, 1)
  12 gen.add("str_param", str_t, 0, "A string parameter", "Hello World")
  13 gen.add("bool_param", bool_t, 0, "A Boolean parameter", True)
  14 
  15 size_enum = gen.enum([ gen.const("Small", int_t, 0, "A small constant"),
  16                   gen.const("Medium", int_t, 1, "A medium constant"),
  17                   gen.const("Large", int_t, 2, "A large constant"),
  18                   gen.const("ExtraLarge", int_t, 3, "An extra large constant") ],
  19                   "An enum to set size")
  20 
  21 gen.add("size", int_t, 0, "A size parameter which is edited via an enum", 1, 0, 3, edit_method=size_enum)
  22 
  23 exit(gen.generate(PACKAGE, "dynamic_tutorials", "Tutorials"))

gen:是一个生成器,我们可以通过他来定义参数。
参数的内容:

name- a string which specifies the name under which this parameter shouldbe stored

  • type- defines the type of value stored, and can be any of int_t,double_t, str_t, or bool_t

  • level- A bitmask which will later be passed to the dynamic reconfigurecallback. When the callback is called all of the level values forparameters that have been changed are ORed together and theresulting value is passed to the callback.

  • description- string which describes the parameter

  • default- specifies the default value

  • min- specifies the min value (optional and does not apply to stringsand bools)

  • max- specifies the max value (optional and does not apply to stringsand bools)

  1. 使用cgf文件

首先更改文件权限,将文件更改为可执行的文件。

chmod a+x cfg/Tutorials.cfg

其次,将下列语句加入到CMakeLists.txt文件中。

#add dynamic reconfigure api
rosbuild_find_ros_package(dynamic_reconfigure)
include(${dynamic_reconfigure_PACKAGE_PATH}/cmake/cfgbuild.cmake)
gencfg()



3. 建立一个节点,调用dynamic_reconfigure
   1 #include <ros/ros.h>
   2 
   3 #include <dynamic_reconfigure/server.h>
   4 #include <dynamic_tutorials/TutorialsConfig.h>
   5 
   6 void callback(dynamic_tutorials::TutorialsConfig &config, uint32_t level) {
   7   ROS_INFO("Reconfigure Request: %d %f %s %s %d", 
   8             config.int_param, config.double_param, 
   9             config.str_param.c_str(), 
  10             config.bool_param?"True":"False", 
  11             config.size);
  12 }
  13 
  14 int main(int argc, char **argv) {
  15   ros::init(argc, argv, "dynamic_tutorials");
  16 
  17   dynamic_reconfigure::Server<dynamic_tutorials::TutorialsConfig> server;
  18   dynamic_reconfigure::Server<dynamic_tutorials::TutorialsConfig>::CallbackType f;
  19 
  20   f = boost::bind(&callback, _1, _2);
  21   server.setCallback(f);
  22 
  23   ROS_INFO("Spinning node");
  24   ros::spin();
  25   return 0;
  26 }1TutorialsConfig.h是由dynamic_configure从我们的configure文件中产生的。
(2) 当新的配置文件configuration被送到dynamic_configure server的时候,调用回调函数。他有两个参数,第一个是一个新的config,第二个是表示lever.3) 运行节点
在CMakeLists.txt中,加入
rosbuild_add_executable(server src/server.cpp)
rosmake编译
运行
$ rosrun rqt_reconfigure rqt_reconfigure
$ rosrun dynamic_reconfigure reconfigure_gui ## On Fuerte or earlier
结果:


;