parameter-passing - 将 arg 添加到启动文件

标签 parameter-passing command-line-arguments launch ros depth

我没有使用命令行运行包,而是制作了一个启动文件

命令行:

rosrun image_view image_saver image:=/the-rgb-image-topic

启动文件:

<launch>
  <node name="extract" pkg="image_view" type="extract_images" respawn="false" output="screen" cwd="ROS_HOME">
    <remap from="image" to="/camera/rgb/image_raw"/>
  </node>
</launch>

现在我想为此做同样的事情:

rosrun image_view image_saver image:=/camera/depth/image _encoding:=16UC1

如何将参数添加到启动文件..

我觉得我应该这样开始

<launch>
  <node name="extract" pkg="image_view" type="extract_images" respawn="false" output="screen" cwd="ROS_HOME">
    <remap from="image" to="/camera/rgb/image_raw"/>

  <node name="extract" pkg="image_view" type="extract_images" respawn="false" output="screen" cwd="ROS_HOME">
    <remap from="image" to="/camera/depth/image"/>
  </node>
</launch>

最佳答案

要将任意参数传递给启动文件中的节点,您可以使用 node tagargs 属性:

<node name="image_saver" pkg="image_view" type="image_saver" args="_encoding:=16UC1" ...>

但是,在这种特定情况下,有一个更好的方法:_encoding 不仅仅是一些任意参数,而是一个由 ROS Parameter Server 处理的参数 .虽然它可能会工作,但使用 args 属性,更好的方法是使用 param tag :

<node name="image_saver" pkg="image_view" type="image_saver">
    <remap from="image" to="/camera/depth/image" />
    <param name="encoding" value="16UC1" type="string" />
</node>

关于parameter-passing - 将 arg 添加到启动文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37969527/

相关文章:

javascript - 拆分为数组并作为参数传递

python - 在 Python 中使用命令行参数 : Understanding sys. argv

iphone - 为什么 iPhone 启动图像在转换时不与主屏幕背景图像对齐?

amazon-web-services - ec2 的 AWS Cloudformation 默认 key 对

bash - 如果传递参数,则强制从脚本外部获取变量值

javascript - OnClick 传递 url 参数

python - 如何使用 argparse 将输入文件中的值附加到命令行选项?

c - 在 C 中使用 argv 和 argc 解析命令行

java - Processing IDE 启动 - 未启动任何Processing 2.0 版本(测试版和稳定版)

c++ - 如何在 Visual Studio Code 中构建和运行作为发布版的 C++ 应用程序