当前位置:网站首页>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 ;

边栏推荐
猜你喜欢

STM32 lights up the 1.8-inch screen under Arduino IDE

C# LINQ源码分析之Count

猜谜语啦(5)

猜谜语啦(10)

Halcon clolor_ pieces. Hedv: classifier_ Color recognition

Example 010: time to show

Business modeling | process of software model

猜谜语啦(8)

Bluebridge cup internet of things basic graphic tutorial - GPIO input key control LD5 on and off

Redis实现高性能的全文搜索引擎---RediSearch
随机推荐
Infix expression evaluation
Some pitfalls of win10 network sharing
STM32 lights up the 1.8-inch screen under Arduino IDE
asp.net(c#)的货币格式化
UE pixel stream, come to a "diet pill"!
Bluebridge cup internet of things basic graphic tutorial - GPIO input key control LD5 on and off
[daily training] 1200 Minimum absolute difference
Digital analog 2: integer programming
Business modeling of software model | object modeling
Hello everyone, welcome to my CSDN blog!
Pytorch entry record
GEO数据库中搜索数据
js异步错误处理
Lori remote control commissioning record
Halcon affine transformations to regions
U8g2 drawing
Run菜单解析
Guess riddles (7)
猜谜语啦(6)
287. 寻找重复数-快慢指针