< >
Home » ROS2入门教程 » ROS2入门教程-launch文件在ros1和ros2间的异同

ROS2入门教程-launch文件在ros1和ros2间的异同

ROS2入门教程-launch文件在ros1和ros2间的异同

说明:

  • 介绍launch文件在ros1和ros2间的异同,便于从ros1向ros2移植

#####ros1和ros2都有的标签:

launch标签:

  • ros1和ros2相同

node标签:

  • 大部分与ros1相同
  • ros2下差异:
  • type 属性变为exec
  • machine, respawn, respawn_delay, clear_params不再使用
  • 例子:
<launch>
   <node pkg="demo_nodes_cpp" exec="talker"/>
   <node pkg="demo_nodes_cpp" exec="listener"/>
</launch>

param标签:

  • 大部分与ros1相同
  • 没有全局参数概念
  • type, textfile, binfile, executable, command不再使用
  • 例子:
<launch>
   <node pkg="demo_nodes_cpp" exec="parameter_event">
      <param name="foo" value="5"/>
   </node>
</launch>
  • 例子2:
<node pkg="my_package" exec="my_executable" name="my_node">
   <!--A string parameter with value "1"-->
   <param name="a_string" value="'1'"/>
   <!--A integer parameter with value 1-->
   <param name="an_int" value="1"/>
   <!--A float parameter with value 1.0-->
   <param name="a_float" value="1.0"/>
   <!--A string parameter with value "asd"-->
   <param name="another_string" value="asd"/>
   <!--Another string parameter, with value "asd"-->
   <param name="string_with_same_value_as_above" value="'asd'"/>
   <!--Another string parameter, with value "'asd'"-->
   <param name="quoted_string" value="\'asd\'"/>
   <!--A list of strings, with value ["asd", "bsd", "csd"]-->
   <param name="list_of_strings" value="asd, bsd, csd" value-sep=", "/>
   <!--A list of ints, with value [1, 2, 3]-->
   <param name="list_of_ints" value="1,2,3" value-sep=","/>
   <!--Another list of strings, with value ["1", "2", "3"]-->
   <param name="another_list_of_strings" value="'1';'2';'3'" value-sep=";"/>
   <!--A list of strings using an strange separator, with value ["1", "2", "3"]-->
   <param name="strange_separator" value="'1'//'2'//'3'" value-sep="//"/>
</node>
  • 例子3:
  • 参数嵌套
<node pkg="my_package" exec="my_executable" name="my_node" ns="/an_absoulute_ns">
   <param name="group1">
      <param name="group2">
         <param name="my_param" value="1"/>
      </param>
      <param name="another_param" value="2"/>
   </param>
</node>
  • 或者
<node pkg="my_package" exec="my_executable" name="my_node" ns="/an_absoulute_ns">
   <param name="group1.group2.my_param" value="1"/>
   <param name="group1.another_param" value="2"/>
</node>

rosparam标签:

  • 在ros1有效
  • 在param中使用from来加载
  • 例子:
<node pkg="my_package" exec="my_executable" name="my_node" ns="/an_absoulute_ns">
   <param from="/path/to/file"/>
</node>

remap标签:

  • 在ros1有效
  • 只能在node中使用
  • 例子:
<launch>
   <node pkg="demo_nodes_cpp" exec="talker">
      <remap from="chatter" to="my_topic"/>
   </node>
   <node pkg="demo_nodes_cpp" exec="listener">
      <remap from="chatter" to="my_topic"/>
   </node>
</launch>

include标签:

  • 在ros1有效
  • 需要在group中使用
  • 不支持ns
  • arg嵌套在include里面,if和unless标签不起效
  • env不起效,使用set_env和unset_env替代
  • clear_params 和pass_all_args 不支持
  • 例子:
<group>
   <include file="another_launch_file"/>
</group>

arg标签:

  • value 用let替代
  • doc 用description替代
  • 嵌套include ,if和unless不起效
  • 例子:
<launch>
   <arg name="topic_name" default="chatter"/>
   <node pkg="demo_nodes_cpp" exec="talker">
      <remap from="chatter" to="$(var topic_name)"/>
   </node>
   <node pkg="demo_nodes_cpp" exec="listener">
      <remap from="chatter" to="$(var topic_name)"/>
   </node>
</launch>

env标签:

  • env被set_env和unset_env替代
  • env只用于嵌套node 和executable 标签下,不支持if和unless标签
  • set_env 可以嵌套在launch和group 标签下
  • 例子:
<launch>
   <set_env name="MY_ENV_VAR" value="MY_VALUE" if="CONDITION_A"/>
   <set_env name="ANOTHER_ENV_VAR" value="ANOTHER_VALUE" unless="CONDITION_B"/>
   <set_env name="SOME_ENV_VAR" value="SOME_VALUE"/>
   <node pkg="MY_PACKAGE" exec="MY_EXECUTABLE" name="MY_NODE">
      <env name="NODE_ENV_VAR" value="SOME_VALUE"/>
   </node>
   <unset_env name="MY_ENV_VAR" if="CONDITION_A"/>
   <node pkg="ANOTHER_PACKAGE" exec="ANOTHER_EXECUTABLE" name="ANOTHER_NODE"/>
   <unset_env name="ANOTHER_ENV_VAR" unless="CONDITION_B"/>
   <unset_env name="SOME_ENV_VAR"/>
</launch>

group标签:

  • 没ns属性,查看新属性push-ros-namespace
  • clear_params不起效
  • 不能使用remap和param 作为下级标签
  • 例子
<launch>
   <arg name="use_time_prefix_in_talker" default="0"/>
   <group>
      <let name="launch-prefix" value="time" if="$(var use_time_prefix_in_talker)"/>
      <node pkg="demo_nodes_cpp" exec="talker"/>
   </group>
   <node pkg="demo_nodes_cpp" exec="listener"/>
</launch>

machine标签:

  • 未支持

test标签:

  • 未支持

#####ros2新出现的标签:

set_env and unset_env标签:

push-ros-namespace标签:

  • 例子:
<!-Other tags-->
<group>
   <push-ros-namespace namespace="my_ns"/>
   <!--Nodes here are namespaced with "my_ns".-->
   <!--If there is an include action here, its nodes will also be namespaced.-->
   <push-ros-namespace namespace="another_ns"/>
   <!--Nodes here are namespaced with "another_ns/my_ns".-->
   <push-ros-namespace namespace="/absolute_ns"/>
   <!--Nodes here are namespaced with "/absolute_ns".-->
   <!--The following node receives an absolute namespace, so it will ignore the others previously pushed.-->
   <!--The full path of the node will be /asd/my_node.-->
   <node pkg="my_pkg" exec="my_executable" name="my_node" ns="/asd"/>
</group>
<!--Nodes outside the group action won't be namespaced.-->
<!-Other tags-->

let标签:

  • 与arg功能类似
  • 例子
<let var="foo" value="asd"/>

executable标签:

  • 例子
<executable cmd="ls -las" cwd="/var/log" name="my_exec" launch-prefix="something" output="screen" shell="true">
   <env name="LD_LIBRARY" value="/lib/some.so"/>
</executable>

include标签

  • 用途和ros1不一样
  • 需要嵌套在group里
<group>
   <include file="another_launch_file"/>
</group>
  • 需要使用ns属性的话,可以这样
<group>
   <push-ros-namespace namespace="my_ns"/>
   <include file="another_launch_file"/>
</group>

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: ros2入门教程