Differences

This shows you the differences between two versions of the page.

Link to this comparison view

dynamic_reconfigure [2019/03/31 14:49] (current)
Line 1: Line 1:
 +====== Dynamic Reconfigure ======
 +
 +The dynamic_reconfigure package provides a means to change node parameters at any
 +time without having to restart the node.
 +
 +To create parameters that can be dynamically reconfigured do the following:
 +
 +===== Setup the package dependencies =====
 +If starting a new package do: 
 +<code bash>
 +catkin_create_pkg package_name ropsy roscpp dynamic_reconfigure
 +</code>
 +
 +If modifying existing package: 
 +<code xml>
 +<build_depend>dynamic_reconfigure</build_depend>
 +<build_depend>roscpp</build_depend>
 +<build_depend>rospy</build_depend>
 +
 +<build_export_depend>dynamic_reconfigure</build_export_depend>
 +<build_export_depend>roscpp</build_export_depend>
 +<build_export_depend>rospy</build_export_depend>
 +
 +<exec_depend>dynamic_reconfigure</exec_depend>
 +<exec_depend>roscpp</exec_depend>
 +<exec_depend>rospy</exec_depend>
 +</code>
 +
 +
 +===== Make a .cfg file. =====
 +
 +Add a config file and call it Something.cfg. Place it in package/cfg directory.
 +
 +<code python>
 +#!/usr/bin/env python
 +PACKAGE = "dynamic_tutorials"
 +
 +from dynamic_reconfigure.parameter_generator_catkin import *
 +
 +gen = ParameterGenerator()
 +
 +gen.add("int_param",    int_t,    0, "An Integer parameter", 50,  0, 100)
 +gen.add("double_param", double_t, 0, "A double parameter",    .5, 0,   1)
 +gen.add("str_param",    str_t,    0, "A string parameter",  "Hello World")
 +gen.add("bool_param",   bool_t,   0, "A Boolean parameter",  True)
 +
 +size_enum = gen.enum([ gen.const("Small",      int_t, 0, "A small constant"),
 +                       gen.const("Medium",     int_t, 1, "A medium constant"),
 +                       gen.const("Large",      int_t, 2, "A large constant"),
 +                       gen.const("ExtraLarge", int_t, 3, "An extra large constant")],
 +                     "An enum to set size")
 +
 +gen.add("size", int_t, 0, "A size parameter which is edited via an enum", 1, 0, 3, edit_method=size_enum)
 +
 +# This is important. The second parameter should be the name of the pacakge
 +# and the third parameter is the prefix of the generated libaries
 +exit(gen.generate(PACKAGE, "dynamic_tutorials", "Tutorials"))
 +</code>
 +
 +Set the config file to be exectutable:
 +<code bash>
 +chmod a+x cfg/Tutorials.cfg
 +</code>
 +
 +Add the following to the CmakeLists.txt: 
 +<code cmake>
 +# add dynamic reconfigure api
 +#find_package(catkin REQUIRED dynamic_reconfigure)
 +generate_dynamic_reconfigure_options(
 +    cfg/Tutorials.cfg
 +)
 + 
 +# If using a c++ node, make sure that you add this dependency so that 
 +# the library gets generated before building the node
 +# add_dependencies(example_node ${PROJECT_NAME}_gencfg)
 +</code>
 +
 +===== Using the .cfg library in your node =====
 +
 +You can do this in python or c++. Import the generated Config library and attach a
 +callback function to get the parameter updates. Then do whatever you want with the
 +parameters! Yay! Follow these tutorials: 
 +
 +[[http://wiki.ros.org/dynamic_reconfigure/Tutorials/SettingUpDynamicReconfigureForANode%28python%29|Python]]
 +[[http://wiki.ros.org/dynamic_reconfigure/Tutorials/SettingUpDynamicReconfigureForANode%28cpp%29|C++]]
 +
  
  • dynamic_reconfigure.txt
  • Last modified: 2019/03/31 14:49
  • (external edit)