当前位置:网站首页>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 
边栏推荐
- Vagrant installation
- MySQL single table access method
- Hash slot of rediscluster cluster cluster implementation principle
- Safety training is the greatest benefit for employees! 2022 induction safety training for new employees
- SOC serial port configuration
- asp. Net error "/" server error in the application. String or binary data would be truncated. The statement...
- Cloud native: cloud computing technology is upgraded again to open an era of comprehensive cloud development
- 22/02/15 study notes
- What is the lifecycle of automated testing?
- Trigonometric transformation formula
猜你喜欢

Eslint 语法监测关闭

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

Activity implicit jump

Redis cerebral fissure
![[shangpinhui] project notes](/img/aa/043dd16c20348f1f80ca5e9e4ad330.png)
[shangpinhui] project notes

22/02/14 study notes

Configuring MySQL multi instance master-slave synchronization for Linux

A single node obtains the lock lock of the order number

Redis cluster deployment and application scenarios

本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献
随机推荐
Disposition Flex
asp. Net registration page
asp. Net to search products and realize paging function
Rediscluster cluster mode capacity expansion node
A single node obtains the lock lock of the order number
Prometheus service discovery
Ambari (VI) -- ambari API use
Dataset filling data, and the use of rows and columns
ES6 use of return in arrow function
sql主從複制搭建
Install haproxy
[shangpinhui] project notes
HJ质数因子
SQL Master slave Replication Build
Soft exam -- software designer -- afternoon question data flow diagram DFD
MySQL installation and environment variable configuration
8 figures | analyze Eureka's first synchronization registry
Ambari (IX) --- use expect to realize no interaction in ambri server setup phase (valid for personal test)
HJ delete the character with the least number of occurrences in the string
Host is not allowed to connect to this MySQL server