当前位置:网站首页>ROS notes (09) - query and setting of parameters
ROS notes (09) - query and setting of parameters
2022-06-28 08:03:00 【wohu1104】
Parameter server in ROS It is mainly used to realize data sharing between different nodes . The parameter server is then equivalent to a common container independent of all nodes , You can store data in this container , Called by different nodes , Of course, different nodes can also store data , The typical application scenarios of the parameter server are as follows :
When navigation is implemented , We'll do path planning , such as : Global path planning , Design an approximate path from the starting point to the target point . Local path planning , The travel path will be generated according to the current road conditions
In the above scenario , Global path planning and local path planning , The parameter server will be used :
Path planning , It is necessary to refer to the size of the trolley , We can store these size information in the parameter server , Global path planning nodes and local path planning nodes can middle note these parameters from the parameter server.
Parameter server , It is generally applicable to some application scenarios with data sharing .
1. Parametric model
As shown above , The parametric model can be seen as ROS The global dictionary of , Each node Node The corresponding parameter information can be obtained from the parameter model .
For details, please refer to :http://wiki.ros.org/Parameter%20server
2. Common parameter command line
Common parameter command lines are as follows
$ rosparam
rosparam is a command-line tool for getting, setting, and deleting parameters from the ROS Parameter Server.
Commands:
rosparam set set parameter
rosparam get get parameter
rosparam load load parameters from file
rosparam dump dump parameters to file
rosparam delete delete parameter
rosparam list list parameter names
- List all current parameters
$ rosparam list
/rosdistro
/roslaunch/uris/host_wohu_pc__42765
/rosversion
/run_id
/turtlesim/background_b
/turtlesim/background_g
/turtlesim/background_r
- Display a parameter value
$ rosparam get /run_id
b37e6c1a-f0fe-11ec-92ca-00e070ce7d11
$ rosparam get /turtlesim/background_b
255
- Set a parameter value
$ rosparam set /turtlesim/background_b 100
$ rosparam get /turtlesim/background_b
100
$ rosservice call /clear "{}" # Used to make the new value of the setting effective
- Save parameters to file
$ rosparam dump config
$ ls
build config devel src
$ cat config
rosdistro: 'melodic '
roslaunch:
uris: {
host_wohu_pc__42765: 'http://wohu-pc:42765/'}
rosversion: '1.14.13 '
run_id: b37e6c1a-f0fe-11ec-92ca-00e070ce7d11
turtlesim: {
background_b: 100, background_g: 86, background_r: 69}
- Read parameters from file
$ rosparam load config
$ rosservice call /clear "{}"
- Delete parameters
$ rosparam set /aaa 100
$ rosparam get /aaa
100
$ rosparam delete /aaa
3. Parameter storage format
All parameters are stored in one YAML Format file .
rosdistro: 'melodic
'
roslaunch:
uris: {
host_wohu_pc__42765: 'http://wohu-pc:42765/'}
rosversion: '1.14.13
'
run_id: b37e6c1a-f0fe-11ec-92ca-00e070ce7d11
turtlesim: {
background_b: 100, background_g: 86, background_r: 69}
4. Parameter setting and query code
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This routine sets / Read the parameters in the turtle routine
import sys
import rospy
from std_srvs.srv import Empty
def parameter_config():
# ROS Node initialization
rospy.init_node('parameter_config', anonymous=True)
# Read background color parameters
red = rospy.get_param('/turtlesim/background_r')
green = rospy.get_param('/turtlesim/background_g')
blue = rospy.get_param('/turtlesim/background_b')
rospy.loginfo("Get Backgroud Color[%d, %d, %d]", red, green, blue)
# Set the background color parameters
rospy.set_param("/turtlesim/background_r", 255);
rospy.set_param("/turtlesim/background_g", 255);
rospy.set_param("/turtlesim/background_b", 255);
rospy.loginfo("Set Backgroud Color[255, 255, 255]");
# Read background color parameters
red = rospy.get_param('/turtlesim/background_r')
green = rospy.get_param('/turtlesim/background_g')
blue = rospy.get_param('/turtlesim/background_b')
rospy.loginfo("Get Backgroud Color[%d, %d, %d]", red, green, blue)
# Find out /spawn After service , Create a service client , The connection name is /spawn Of service
rospy.wait_for_service('/clear')
try:
clear_background = rospy.ServiceProxy('/clear', Empty)
# Request service call , Enter request data
response = clear_background()
return response
except rospy.ServiceException, e:
print "Service call failed: %s"%e
if __name__ == "__main__":
parameter_config()
function
$ cd ~/catkin_ws
$ catkin_create_pkg parameter rospy std_msgs geometry_msgs turtlesim
$ catkin_make
$ source ./devel/setup.bash
take Python Put the code in the following path 
Carry on
$ roscore
$ rosrun turtlesim turtlesim_node
$ rosrun parameter parameter_config.py
The results change 
边栏推荐
- Upgrade HDP spark to spark 2.4.8 without upgrading ambari
- 股票炒股注册开户靠谱吗?安全吗?
- Redis persistence problem and final solution
- flex布局
- Online WPS tool
- Redis cluster deployment and application scenarios
- The solution of "user account control to continue, please enter administrator user name and password" appears in win10 Professional Edition
- 十大券商注册开户靠谱吗?安全吗?
- Investment transaction and settlement of the fund
- 8 figures | analyze Eureka's first synchronization registry
猜你喜欢

LeetCode之三步问题

Eslint 语法监测关闭

Unity-UI-shadow组件

Software design of power control board

HJ prime factor

Section Xi. Axi of zynq_ Use of DMA

Idea package together, using compact middle packages to solve &

Trigonometric transformation formula

本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献

Software testing and quality final review
随机推荐
How to insert a single quotation mark into a table as a data type in Oracle pl/sql
Today's notes 22/1/7
券商注册开户靠谱吗?安全吗?
Prometheus deployment alarm docking QQ mailbox
Is it reliable for flush to register and open an account? Is it safe?
Kubernetes cluster command line tool kubectl
SOC clock configuration
Ambari (VIII) --- ambari integrated impala document (valid for personal test)
HJ string sort
Design and implementation of spark offline development framework
Flutter realizes the function of "shake"
Study notes 22/1/17
kubernetes集群命令行工具kubectl
Disposition Flex
ROS 笔记(09)— 参数的查询和设置
Redis persistence problem and final solution
Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)
推荐系统系列精讲(第五讲): 排序模型的调优实践
8 figures | analyze Eureka's first synchronization registry
How to configure DDR3 of dm8148