动态配置文件 (dynamic_reconfigure) 提供了一种将 ros 节点内的参数暴露出来的方式。该接口可以让用户在节点运行时通过客户端动态的调整参数,实时的观察特定参数参数对节点内算法的影响。
rosrun rqt_reconfigure rqt_reconfigure
$ rosrun dynamic_reconfigure dynparam list # list configureable nodes
$ rosrun dynamic_reconfigure dynparam get # get node configuration
$ rosrun dynamic_reconfigure dynparam set # configure node
$ rosrun dynamic_reconfigure dynparam set_from_parameters # copy configuration from parameter server
$ rosrun dynamic_reconfigure dynparam sdynparam dump # dump configuration to file
$ rosrun dynamic_reconfigure dynparam sdynparam load # load configuration from file
详细介绍可以参考:【链接】【教程 tutorial】
catkin_create_pkg --rosdistro ROSDISTRO dynamic_tutorials rospy roscpp dynamic_reconfigure
mkdir cfg
#!/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)
exit(gen.generate(PACKAGE, "dynamic_tutorials", "Tutorials"))
chmod a+x cfg/Tutorials.cfg
#add dynamic reconfigure api
#find_package(catkin REQUIRED dynamic_reconfigure)
generate_dynamic_reconfigure_options(
cfg/Tutorials.cfg
#...
)
# make sure configure headers are built before any node using them
add_dependencies(example_node ${PROJECT_NAME}_gencfg)
【原文链接】
#include
#include
#include
void callback(dynamic_tutorials::TutorialsConfig &config, uint32_t level) {
ROS_INFO("Reconfigure Request: %d %f %s %s %d",
config.int_param, config.double_param,
config.str_param.c_str(),
config.bool_param?"True":"False",
config.size);
}
int main(int argc, char **argv) {
ros::init(argc, argv, "dynamic_tutorials");
dynamic_reconfigure::Server<dynamic_tutorials::TutorialsConfig> server;
dynamic_reconfigure::Server<dynamic_tutorials::TutorialsConfig>::CallbackType f;
// bind 是一组重载的函数模板.用来向一个函数(或函数对象)绑定某些参数.bind的返回值是一个函数对象.
f = boost::bind(&callback, _1, _2);
server.setCallback(f);
ROS_INFO("Spinning node");
ros::spin();
return 0;
}
【boost::bind用法】
【原文链接】