当前位置:网站首页>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 ;
边栏推荐
- Warning: retrying occurs during PIP installation
- 319. 灯泡开关
- 图解八道经典指针笔试题
- Mathematical modeling: factor analysis
- Infix expression evaluation
- Dynamic dimensions required for input: input, but no shapes were provided. Automatically overriding
- Business modeling of software model | overview
- ECMAScript6介绍及环境搭建
- 12、动态链接库,dll
- 猜谜语啦(7)
猜你喜欢
UE pixel stream, come to a "diet pill"!
Daily question - input a date and output the day of the year
猜谜语啦(9)
[Niuke brush questions day4] jz55 depth of binary tree
319. Bulb switch
C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)
微信H5公众号获取openid爬坑记
leetcode - 445. Add two numbers II
Example 010: time to show
Count of C # LINQ source code analysis
随机推荐
U8g2 drawing
Lori remote control commissioning record
Halcon Chinese character recognition
每日一题——替换空格
容易混淆的基本概念 成员变量 局部变量 全局变量
Task failed task_ 1641530057069_ 0002_ m_ 000000
Agile project management of project management
Guess riddles (2)
STM32 lights up the 1.8-inch screen under Arduino IDE
LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
12、动态链接库,dll
Bit operation related operations
Cmder of win artifact
Infected Tree(树形dp)
Adaboost使用
Business modeling of software model | vision
图解网络:什么是网关负载均衡协议GLBP?
[daily training -- Tencent selected 50] 557 Reverse word III in string
【NOI模拟赛】汁树(树形DP)
Some pitfalls of win10 network sharing