- name:参数名,使用字符串描述;
-
- type:定义参数的类型,可以是int_t, double_t, str_t, 或者bool_t;
-
- level:需要传入参数动态配置回调函数中的掩码,在回调函数中会修改所有参数的掩码,表示参数已经进行修改;
-
- description:描述参数作用的字符串;
-
- default:设置参数的默认值;
-
- min:可选,设置参数的最小值,对于字符串和布尔类型值不生效;
-
- max:可选,设置参数的最大值,对于字符串和布尔类型值不生效;
- #!/usr/bin/env python3
- PACKAGE = "example_2" #声明当前的包名
- from dynamic_reconfigure.parameter_generator_catkin import *
- gen = ParameterGenerator() #参数生成器调用变量gen
- gen.add("speed",int_t,0,"speed of car",50,0,120) #gen中添加 int 速度 默认 50 最小 0 最大 120
- gen.add("pkg",str_t,0,"package name","example_2") # 追加包的名字是example2
- size_enum = gen.enum([gen.const("Low",int_t,0,"low is 0"), # 枚举 低
- gen.const("Medium",int_t,1,"Medium is 1"), # 枚举 中
- gen.const("High",int_t,2,"Hight is 2")], # 枚举 高
- "Select from the list")
- gen.add("size",int_t,0,"Select from the list",1,0,2,edit_method=size_enum)
- exit(gen.generate(PACKAGE,"example_2","Test")) # 生成包 test 文件 关联配置文件的.h动态文件 跨语言的头文件
对应的.cpp文件
- #include
- #include
- #include "example_2/TestConfig.h"
-
- void callback(example_2::TestConfig &cfg,uint32_t level){
- ROS_INFO("Reconfigure Request: ths speed is %d,%s,the size is %d, the level is %d",
- cfg.speed,
- cfg.pkg.c_str(),
- cfg.size,
- level
- );
- }
- int main(int argc, char **argv)
- {
- ros::init(argc, argv, "param");
- dynamic_reconfigure::Server
server; // 服务端动态类型 - dynamic_reconfigure::Server
::CallbackType f; // 绑定回调函数掩码 - //_1,_2为占位符,表示用实际的第一个、第二个参数替换
- f = boost::bind(&callback,_1,_2);
- server.setCallback(f);
- ros::spin(); // 不断监听回调函数
- return 0;
- }