当前位置:网站首页>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 
边栏推荐
- asp. Net datalist when there are multiple data displays
- LeetCode之三步问题
- Kubernetes理论基础
- How to insert a single quotation mark into a table as a data type in Oracle pl/sql
- 券商注册开户靠谱吗?安全吗?
- Is it reliable to register and open an account for stock speculation? Is it safe?
- Do you know TCP protocol (2)?
- asp. Net error "/" server error in the application. String or binary data would be truncated. The statement...
- How to use redis to solve concurrency problems
- Redis implements distributed locks
猜你喜欢

Kubernetes理论基础

你了解TCP協議嗎(二)?

SQL analysis (query interception analysis for SQL optimization)

Buffer pool in MySQL

nlp序列完全可以模拟人脑智能

Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)

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

Activity隐式跳转

Vagrant installation

ROS 笔记(08)— 服务数据的定义与使用
随机推荐
A single node obtains the lock lock of the order number
At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions
How to use redis to solve concurrency problems
Generation and verification of JWT token
Static resource compression reduces bandwidth pressure and increases access speed
ROS 笔记(09)— 参数的查询和设置
【js】-【节流、防抖函数】
MySQL single table access method
Software design of power control board
Do you know TCP protocol (1)?
股票炒股注册开户靠谱吗?安全吗?
Connaissez - vous le protocole TCP (2)?
GPIO configuration of SOC
Airflow2 configuration windows azure SSO details based on oauth2 protocol
Prometheus deployment alarm docking QQ mailbox
Design of DSP image data stream
SQL analysis (query interception analysis for SQL optimization)
MySQL installation and environment variable configuration
Flutter realizes the function of "shake"
云原生:云计算技术再次升级 开启全面云开发时代