(六)阅读教程Understanding ROS 2 parameters

背景

【A parameter is a configuration value of a node. You can think of parameters as node settings. A node can store parameters as integers, floats, booleans, strings and lists. In ROS 2, each node maintains its own parameters. All parameters are dynamically reconfigurable, and built off of ROS 2 services.】

一个参数时一个node的配置值。你可以将这些参数视为对node的设置。一个node可以存储整型、浮点、布尔、字符串和列表类型的参数。在ROS2中,每个node都包含它自己的参数。所有参数都是动态可重新配置的,并且是基于ROS2 services构建的。

Tasks

1、Setup

Start up the two turtlesim nodes, /turtlesim and /teleop_turtle.

2、ros2 param list

【To see the parameters belonging to your nodes, open a new terminal and enter the command:】

ros2 param list

 【You will see the node subnamespaces, /teleop_turtle and /turtlesim, followed by each node’s parameters:】

【Every node has the parameter use_sim_time; it’s not unique to turtlesim.】

每个node都有use_sim_time这个参数,它不是turtlesim所独有的。

【Based on their names, it looks like /turtlesim’s parameters determine the background color of the turtlesim window using RGB color values.】

基于他们的名字, /turtlesim的参数看起来像是用RGB颜色值定义了turtle窗口的背景色。

【To be certain of a parameter type, you can use ros2 param get.】

可以使用 ros2 param get 命令来确定参数类型。

 

3、ros2 param get

【To get the current value of a parameter, use the command:】

ros2 param get <node_name> <parameter_name>

#Let’s find out the current value of /turtlesim’s parameter background_g:

ros2 param get /turtlesim background_g

 Which will return the value:

【Now you know background_g holds an integer value.】

background_g拥有一个整数值

【If you run the same command on background_r and background_b, you will get the values 69 and 255, respectively.】

 

 

4、ros2 param set

【To change a parameter’s value at runtime, use the command:】

ros2 param set <node_name> <parameter_name> <value>

#Let’s change /turtlesim’s background color:

ros2 param set /turtlesim background_r 150

Your terminal should return the message:

And the background of your turtlesim window should change colors:

【Setting parameters with the set command will only change them in your current session, not permanently. However, you can save your settings changes and reload them next time you start a node.】

使用set 命令设置参数将只会修改当前会话中的值,不会永久修改。然而,你可以保存设置更改并且在下次启动时重新加载他们。

 

5、ros2 param dump

【You can “dump” all of a node’s current parameter values into a file to save for later using the command:】

你可以用以下命令将这个node当前的参数值倒入一个文件夹保存起来以便下次使用。

ros2 param dump <node_name>

#To save your current configuration of /turtlesim’s parameters, enter the command:

ros2 param dump /turtlesim

Your terminal will return the message:

【You will find a new file in the directory your workspace is running in. If you open this file, you’ll see the following contents:】

在你当前正在运行的工作空间的目录中将会出现一个新文件。如果你打开这个文件将会看到以下内容:

【Dumping parameters comes in handy if you want to reload the node with the same parameters in the future.】

将参数值转存便于您以后重新加载此节点时使用相同的配置。

 

6、Load parameter file

【To start the same node using your saved parameter values, use:】

ros2 run <package_name> <executable_name> --ros-args --params-file <file_name>

【This is the same command you always use to start turtlesim, with the added flags --ros-args and --params-file, followed by the file you want to load.】

在常用的开启turtlesim的命令的后面加上flags --ros-args和--params-file,后面再跟上你想要的加载的文件。

#Stop your running turtlesim node so you can try reloading it with your saved parameters, using:

ros2 run turtlesim turtlesim_node --ros-args --params-file ./turtlesim.yaml

【The turtlesim window should appear as usual, but with the purple background you set earlier.】

 

Summary

【Nodes have parameters to define their default configuration values. You can get and set parameter values from the command line. You can also save parameter settings to reload in a new session.】

nodes用参数来定义他们的默认配置值。你可以通过命令行获取(get)和设置(set)参数值。你也可以通过保存参数设置来重新加载到新的会话中。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值