当前位置:网站首页>Use and programming method of ros-8 parameters
Use and programming method of ros-8 parameters
2022-07-05 08:45:00 【m0_ forty-six million ninety-three thousand eight hundred and t】
One 、 Concept
ROS Master There is a parameter server in Paramester Server, It is a global dictionary , It's for keeping Each node Configuration parameters between .

Two 、rosparam
For the parameters of each node , We can rosparam XXX And so on , Modify and other operations , The specific operation can be input through the terminal rosparam Command view .

Try not to open any nodes ,ros Global parameters in the system .

Then I open the little turtle node , The global parameters in the current system are :

You can see , After opening the little turtle node, there are three more parameters , These three parameters are used to set the background plate of the little turtle RGB It's worth it .
Pay attention to each background Namespace before , In the future, whether you view or modify it, you should bring this namespace .
Can pass get Check the instructions of :


2.1 Modify the global parameters through the command line
Now let's try to modify these parameters on the command line :

Let me use it first. rosparam set take b Value changed to 0, And then use rosparam get see b Value discovery changes take effect . But the background color of the little turtle is still this blue , There is no change . So here we need to pay attention to , Changing parameters on the command line is not real-time , Therefore, if the parameter is modified with the command line , You need to resend the parameter change request , The parameter change request command is as follows :

2.2 Save the global parameters of the current system
have access to rosparam dump file name .yaml To save the global parameters of the current system , It should be noted that the default path for saving files is the home directory

After the save .yaml The documents are as follows :

We can also be here .yaml Modify parameter values in .
for example : I put background_g Change it to 255
After saving the file , Need to pass through rosparam load file name .yaml Load the modified file , Then send the parameter change request again .

2.3 Set the global parameters through the program
Create in the current workspace learning_parameter Function pack , And write the following c++ Program parameter_config:
/***********************************************************************
Copyright 2020 GuYueHome (www.guyuehome.com).
***********************************************************************/
/**
* This routine sets / Read the parameters in the turtle routine
*/
#include <string>
#include <ros/ros.h>
#include <std_srvs/Empty.h>
int main(int argc, char **argv)
{
int red, green, blue;
// ROS Node initialization
ros::init(argc, argv, "parameter_config");
// Create node handle
ros::NodeHandle node;
// Read background color parameters
ros::param::get("/turtlesim/background_r", red);
ros::param::get("/turtlesim/background_g", green);
ros::param::get("/turtlesim/background_b", blue);
ROS_INFO("Get Backgroud Color[%d, %d, %d]", red, green, blue);
// Set the background color parameters
ros::param::set("/turtlesim/background_r", 255);
ros::param::set("/turtlesim/background_g", 255);
ros::param::set("/turtlesim/background_b", 255);
ROS_INFO("Set Backgroud Color[255, 255, 255]");
// Read background color parameters
ros::param::get("/turtlesim/background_r", red);
ros::param::get("/turtlesim/background_g", green);
ros::param::get("/turtlesim/background_b", blue);
ROS_INFO("Re-get Backgroud Color[%d, %d, %d]", red, green, blue);
// Call the service , Refresh background color
ros::service::waitForService("/clear");
ros::ServiceClient clear_background = node.serviceClient<std_srvs::Empty>("/clear");
std_srvs::Empty srv;
clear_background.call(srv);
sleep(1);
return 0;
}
After writing the program , After compiling , restart roscore, Run the little turtle node , And then run the program
The operation results are as follows ;

边栏推荐
- MPSoC QSPI Flash 升级办法
- Lori remote control commissioning record
- How to manage the performance of R & D team?
- Daily question - input a date and output the day of the year
- LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
- Digital analog 1: linear programming
- 猜谜语啦(8)
- My university
- Redis实现高性能的全文搜索引擎---RediSearch
- 【日常训练--腾讯精选50】557. 反转字符串中的单词 III
猜你喜欢

Guess riddles (10)

Guess riddles (8)
![[matlab] matlab reads and writes Excel](/img/80/78e4c7fcd27473526e480d4b930e2c.jpg)
[matlab] matlab reads and writes Excel
![[牛客网刷题 Day4] JZ35 复杂链表的复制](/img/bc/ce90bb3cb6f52605255f1d6d6894b0.png)
[牛客网刷题 Day4] JZ35 复杂链表的复制

Business modeling of software model | vision

猜谜语啦(142)

整形的分类:short in long longlong

Bluebridge cup internet of things competition basic graphic tutorial - clock selection

C# LINQ源码分析之Count

深度学习模型与湿实验的结合,有望用于代谢通量分析
随机推荐
Business modeling of software model | stakeholders
Infected Tree(树形dp)
Wheel 1:qcustomplot initialization template
Numpy 小坑:维度 (n, 1) 和 维度 (n, ) 数组相加运算后维度变为 (n, n)
ORACLE进阶(三)数据字典详解
Guess riddles (6)
[matlab] matlab reads and writes Excel
287. Looking for repeats - fast and slow pointer
我从技术到产品经理的几点体会
leetcode - 445. Add two numbers II
Guess riddles (8)
皮尔森相关系数
猜谜语啦(11)
Xrosstools tool installation for X-Series
猜谜语啦(142)
PIP installation
Halcon blob analysis (ball.hdev)
Esp8266 interrupt configuration
287. 寻找重复数-快慢指针
Example 010: time to show