当前位置:网站首页>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 
边栏推荐
- MySQL implements transaction persistence using redo logs
- How to insert a single quotation mark into a table as a data type in Oracle pl/sql
- Section VII starting principle and configuration of zynq
- Redis one master multi slave cluster setup
- pip 更新到最新的版本
- Airflow2.1.1 ultra detailed installation document
- Buffer pool in MySQL
- Dataset filling data, and the use of rows and columns
- Software design of power control board
- 打新债注册开户靠谱吗?安全吗?
猜你喜欢

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

Static resource compression reduces bandwidth pressure and increases access speed

Section 9: dual core startup of zynq

The solution of "user account control to continue, please enter administrator user name and password" appears in win10 Professional Edition

Hash slot of rediscluster cluster cluster implementation principle

NLP sequence can completely simulate human brain intelligence

Section 5: zynq interrupt

MySQL installation and environment variable configuration

Uninstall and reinstall the latest version of MySQL database. The test is valid

你了解TCP協議嗎(二)?
随机推荐
你了解TCP协议吗(二)?
Rediscluster cluster mode capacity expansion node
Flex layout
ROS 笔记(08)— 服务数据的定义与使用
Software design of power control board
HJ质数因子
异或的应用。(提取出数字中最右侧的1,面试中经常用的到)
nlp序列完全可以模拟人脑智能
Activity implicit jump
Disposition Flex
Host is not allowed to connect to this MySQL server
ROS 笔记(09)— 参数的查询和设置
sql主从复制搭建
asp. Net to search products and realize paging function
SQL analysis (query interception analysis for SQL optimization)
三角变换公式
Software design of resistance test board
Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)
HJ字符个数统计
Soft exam -- software designer -- afternoon question data flow diagram DFD