当前位置:网站首页>ROS 笔记(09)— 参数的查询和设置
ROS 笔记(09)— 参数的查询和设置
2022-06-28 07:58:00 【wohu1104】
参数服务器在ROS中主要用于实现不同节点之间的数据共享。参数服务器相当于是独立于所有节点的一个公共容器,可以将数据存储在该容器中,被不同的节点调用,当然不同的节点也可以往其中存储数据,关于参数服务器的典型应用场景如下:
导航实现时,会进行路径规划,比如: 全局路径规划,设计一个从出发点到目标点的大致路径。本地路径规划,会根据当前路况生成时时的行进路径
上述场景中,全局路径规划和本地路径规划时,就会使用到参数服务器:
路径规划时,需要参考小车的尺寸,我们可以将这些尺寸信息存储到参数服务器,全局路径规划节点与本地路径规划节点都可以从参数服务器中调用这些参数
参数服务器,一般适用于存在数据共享的一些应用场景。
1. 参数模型
如上所示,参数模型可以看做是 ROS 的全局字典,各个节点 Node 都可以从参数模型中获取对应的参数信息。
具体可参考:http://wiki.ros.org/Parameter%20server
2. 常用参数命令行
常用参数命令行有以下
$ 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
- 列出当前所有参数
$ rosparam list
/rosdistro
/roslaunch/uris/host_wohu_pc__42765
/rosversion
/run_id
/turtlesim/background_b
/turtlesim/background_g
/turtlesim/background_r
- 显示某个参数值
$ rosparam get /run_id
b37e6c1a-f0fe-11ec-92ca-00e070ce7d11
$ rosparam get /turtlesim/background_b
255
- 设置某个参数值
$ rosparam set /turtlesim/background_b 100
$ rosparam get /turtlesim/background_b
100
$ rosservice call /clear "{}" # 用于使设置的新值生效
- 保存参数到文件
$ 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}
- 从文件中读取参数
$ rosparam load config
$ rosservice call /clear "{}"
- 删除参数
$ rosparam set /aaa 100
$ rosparam get /aaa
100
$ rosparam delete /aaa
3. 参数存储格式
所有参数是存储在一个 YAML 格式的文件中。
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. 参数设置和查询代码
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 该例程设置/读取海龟例程中的参数
import sys
import rospy
from std_srvs.srv import Empty
def parameter_config():
# ROS节点初始化
rospy.init_node('parameter_config', anonymous=True)
# 读取背景颜色参数
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)
# 设置背景颜色参数
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]");
# 读取背景颜色参数
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)
# 发现/spawn服务后,创建一个服务客户端,连接名为/spawn的service
rospy.wait_for_service('/clear')
try:
clear_background = rospy.ServiceProxy('/clear', Empty)
# 请求服务调用,输入请求数据
response = clear_background()
return response
except rospy.ServiceException, e:
print "Service call failed: %s"%e
if __name__ == "__main__":
parameter_config()
运行
$ cd ~/catkin_ws
$ catkin_create_pkg parameter rospy std_msgs geometry_msgs turtlesim
$ catkin_make
$ source ./devel/setup.bash
将 Python 代码放到如下路径
继续执行
$ roscore
$ rosrun turtlesim turtlesim_node
$ rosrun parameter parameter_config.py
结果变化
边栏推荐
- Section 8: DMA of zynq
- Ambari (IX) --- use expect to realize no interaction in ambri server setup phase (valid for personal test)
- Explanation and application of instr() function in Oracle
- SOC serial port configuration
- HJ字符串排序
- Llvm and clang
- Leetcode learning records
- SOC clock configuration
- Is it reliable to open a new bond registration account? Is it safe?
- Uninstall and reinstall the latest version of MySQL database. The test is valid
猜你喜欢

你了解TCP协议吗(一)?

Today's notes 22/1/7

Resizing node of rediscluster cluster cluster mode

asp. Net to search products and realize paging function

Unity UI shadow component

flex布局

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

推荐系统系列精讲(第五讲): 排序模型的调优实践

Unity-UI-shadow组件

asp. Net registration page
随机推荐
es数据导出csv文件
异或的应用。(提取出数字中最右侧的1,面试中经常用的到)
MySQL single table access method
Evaluation of inverse Polish expression < difficulty coefficient >
Disposition Flex
Section 9: dual core startup of zynq
GPIO configuration of SOC
Soft test -- software designer -- database design of afternoon questions
asp. Net datalist when there are multiple data displays
Dataset filling data, and the use of rows and columns
MySQL installation and environment variable configuration
HJ进制转换
Safety training is the greatest benefit for employees! 2022 induction safety training for new employees
Uninstall and reinstall the latest version of MySQL database. The test is valid
Rediscluster cluster mode capacity expansion node
Section VII starting principle and configuration of zynq
自动化测试的生命周期是什么?
Conversion between HJ integer and IP address
Flex layout
Tencent continued to lay off staff in the second half of the year, and all business groups reduced by at least 10%. What do you think of this? Followers