如何在ROS2中启动带有参数的节点? [英] How to launch a node with a parameter in ROS2?

查看:123
本文介绍了如何在ROS2中启动带有参数的节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将 ros1 包迁移到 ros2 并且无法弄清楚如何使用 ros2 中的参数启动.

Migrating ros1 package to ros2 and couldn't figure how to launch with a paramter in ros2.

在 ros1 中,我有一个引用配置文件的启动文件,我从 cpp 代码使用 node.getParam

With ros1 I have a launch file that refers to a config file and from cpp code I use node.getParam

启动文件:

<launch>
    <arg name="node_name" default="collector" />
    <arg name="config_file" default="" />
    <node name="$(arg node_name)" pkg="collector" type="collector" respawn="true">
      <rosparam if="$(eval config_file!='')" command="load" file="$(arg config_file)"/>
    </node>
</launch>

配置文件:

my_param: 5

cpp 代码:

double my_param = 0;
n.getParam("my_param", my_param);

我的问题是如何将其转化为 ROS2?

My question is how would that translate to ROS2?

推荐答案

对于 ROS2,请参见 此链接此链接.

For ROS2, please see this link and this link.

作为参考,截至本文,ROS2 已经发布了三个版本.虽然 Crystal Clemmens 支持 Python 节点,但之前的版本 Bouncy Bolson 不支持.同样,未来的版本可能会增加对如何/在何处输入配置文件的额外支持.

For reference, as of this post, ROS2 has had three releases. While Crystal Clemmens supports Python nodes, the previous release, Bouncy Bolson, does not. Similarly, future releases may add additional support for how/where to input config files.

ROS2 Wiki 引用使用 .yaml 配置文件来存储参数,并在运行 ROS2 节点时将配置文件作为命令行参数传递.

The ROS2 Wiki references using a .yaml config file to store parameters and, when running the ROS2 node, passing the config file as a command line parameter.

ROS2 维基:节点参数

示例demo_params.yaml 文件:

talker:
    ros__parameters:
        some_int: 42
        a_string: "Hello world"
        some_lists:
            some_integers: [1, 2, 3, 4]
            some_doubles : [3.14, 2.718]`

然后运行以下命令:

ros2 运行 demo_nodes_cpp talker __params:=demo_params.yaml

这篇关于如何在ROS2中启动带有参数的节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆