当前位置:网站首页>ROS learning (26) dynamic parameter configuration
ROS learning (26) dynamic parameter configuration
2022-07-07 01:52:00 【Ice cream with code】
List of articles
Preface
In the previous study , Have known ROS Communication mechanism of parameter server , If Listenner Do not actively query parameter values , You can't get Talker Whether it has been submitted to Master Updated parameter values .
In many cases , We need to update parameters dynamically , Such as parameter debugging ,ROS Provides dynamic_reconfigure Function pack , Realize dynamic parameter configuration .
One 、 principle
ROS The dynamic parameters of are modified by C/S framework , At run time , The client does not need to restart after modifying parameters , Instead, send a request to the server ; The server confirms through the callback function , You can complete the dynamic configuration of parameters .
Two 、 Realization
1、 Create Feature Pack
Create a dynamic_tutorials Function pack , The order is as follows :
catkin_create_pkg dynamic_tutorials rospy roscpp dynamic_reconfigure
2、 create profile
Under function pack cfg Under the folder , Create a Tutorials.cfg The file of , The contents are as follows :
#!/usr/bin/env python
PACKAGE = "dynamic_tutorials"
# Import parameter generator
from dynamic_reconfigure.parameter_generator_catkin import *
# Create a parameter generator
gen = ParameterGenerator()
# Define parameters that need dynamic configuration , Parameters respectively represent parameter names 、 type 、 Parameter dynamically configure the mask in the callback 、 describe 、 The default value is 、 Min and Max ( The latter two are optional , And invalid for string and Boolean types )
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)
# Define an enumeration , The parameters respectively represent the enumeration value name 、 type 、 Value and description
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")
# Define an integer value , It can be listed by enumeration
gen.add("size", int_t, 0, "A size parameter which is edited via an enum", 1, 0, 3, edit_method=size_enum)
# Generate all and C++ and python Related documents , And exit the program , The second parameter represents the node name of the runtime , The third parameter is the prefix used by the generated file , It needs to be the same as the configuration file name
exit(gen.generate(PACKAGE, "dynamic_tutorials", "Tutorials"))
The real runtime , Need to remove the Chinese Notes . When the configuration is complete , Add executable permissions to the file .
3、 modify CMakeLists.txt file
Add Compilation Rules , The contents are as follows :
generate_dynamic_reconfigure_options(
cfg/Tutorials.cfg
)
add_dependencies(dynamic_reconfigure_node ${
PROJECT_NAME}_gencfg)
4、 establish dynamic_reconfigure_node node
4、1 Create a server node
stay src Under the table of contents , establish server.cpp file , The contents are as follows :
#include <ros/ros.h>
#include <dynamic_reconfigure/server.h>
// This header file is generated by the configuration file during compilation
#include <dynamic_tutorials/TutorialsConfig.h>
// Callback function , Parameters respectively represent the configuration values of parameter updates 、 Mask of parameter modification
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)
{
// initialization ROS node
ros::init(argc, argv, "dynamic_tutorials");
// Create a server instance , Listen to the parameter configuration request of the client
dynamic_reconfigure::Server<dynamic_tutorials::TutorialsConfig> server;
// Define callback function
dynamic_reconfigure::Server<dynamic_tutorials::TutorialsConfig>::CallbackType f;
// The callback function is bound to the server , When the client requests to modify parameters , The server jumps to the callback function for processing
f = boost::bind(&callback, _1, _2);
server.setCallback(f);
ROS_INFO("Spinning node");
ros::spin();
return 0;
}
4、2 modify CMakeLists.txt file
Add Compilation Rules , The contents are as follows :
# for dynamic reconfigure
add_executable(dynamic_reconfigure_node src/server.cpp)
# make sure configure headers are built before any node using them
add_dependencies(dynamic_reconfigure_node ${
PROJECT_NAME}_gencfg)
# for dynamic reconfigure
target_link_libraries(dynamic_reconfigure_node ${
catkin_LIBRARIES})
After completing the above configuration , Compile function packs .
5、 Parameter dynamic configuration
function roscore and dynamic_reconfigure_node node , The order is as follows :
roscore
rosrun dynamic_tutorials dynamic_reconfigure_node
here , The server with dynamic parameter configuration starts to run , Next use ROS Provide visual parameter configuration tools to modify parameters , The order is as follows :
rosrun rqt_reconfigure rqt_reconfigure
Pictured :
You can drag 、 Input 、 Drop down box and other methods to modify parameters , It is worth noting that , The different input methods here are related to the parameter settings in the configuration file , For example, the maximum value is set / minimum value , There will be a drag bar ; Enumeration set , A drop-down box will appear .
With the change of parameter value , In the output of the server node , You will see the modified information , Pictured :
边栏推荐
- AcWing 1140. 最短网络 (最小生成树)
- AcWing 904. Wormhole solution (SPFA for negative rings)
- ZOJ Problem Set – 2563 Long Dominoes 【如压力dp】
- Compile command line terminal swift
- ROS学习(十九)机器人SLAM功能包——cartographer
- ROS學習(23)action通信機制
- 百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (下)
- Related programming problems of string
- JS Es5 can also create constants?
- AcWing 344. 观光之旅题解(floyd求无向图的最小环问题)
猜你喜欢
ROS学习(21)机器人SLAM功能包——orbslam的安装与测试
Appium automation test foundation uiautomatorviewer positioning tool
Gin 入门实战
ROS學習(23)action通信機制
刨析《C语言》【进阶】付费知识【一】
爬虫实战(六):爬笔趣阁小说
Can't you understand the code of linked list in C language? An article allows you to grasp the secondary pointer and deeply understand the various forms of parameter passing in the function parameter
The cradle of eternity
我如何编码8个小时而不会感到疲倦。
ROS学习(24)plugin插件
随机推荐
AcWing 344. Solution to the problem of sightseeing tour (Floyd finding the minimum ring of undirected graph)
Related programming problems of string
Yunna - work order management system and process, work order management specification
Get to know MySQL for the first time
AcWing 1148. Secret milk transportation problem solution (minimum spanning tree)
ROS learning (23) action communication mechanism
POJ 3177 redundant paths POJ 3352 road construction (dual connection)
ROS学习(23)action通信机制
LeetCode. 剑指offer 62. 圆圈中最后剩下的数
Recognition of C language array
AcWing 346. Solution to the problem of water splashing festival in the corridor (deduction formula, minimum spanning tree)
设置Wordpress伪静态连接(无宝塔)
Analyze "C language" [advanced] paid knowledge [End]
js如何快速创建一个长度为 n 的数组
shell脚本快速统计项目代码行数
刨析《C语言》【进阶】付费知识【一】
制作带照明的DIY焊接排烟器
dvajs的基础介绍及使用
Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 1)
ZOJ problem set – 2563 long dominoes [e.g. pressure DP]