Launch启动文件的使用方法

Launch启动文件的使用方法

  • 案例一:运行两个节点
  • 案例二:加载参数与命名空间
  • 案例三:小海龟跟随的launch启动方法
  • 案例四:remap修改节点名

Launch文件可以通过XML文件实现多节点的配置和启动,省去了启动多个终端与多个节点的复杂操作,同时launch文件也不用进行roscore

案例一:运行两个节点

在工作空间src文件夹内新建一个learning_launch功能包

catkin_creat_pkg learning_launch

touch一个simple.launch文件,打开文件在设置-高亮可以更改为xml语法高亮

<launch>
    <node pkg="learning_topic" type="person_subscriber" name="talker" output="screen" />
    <node pkg="learning_topic" type="person_publisher" name="listener" output="screen" /> 
launch>



catkin_make编译
roslaunch learning_launch simple.launch运行

案例二:加载参数与命名空间

Launch启动文件的使用方法_第1张图片

<launch>

    <param name="/turtle_number"   value="2"/>

    <node pkg="turtlesim" type="turtlesim_node" name="turtlesim_node">
		<param name="turtle_name1"   value="Tom"  />
		<param name="turtle_name2"   value="Jerry"/>

		<rosparam file="$(find learning_launch)/config/param.yaml" command="load"/>
    node>

    <node pkg="turtlesim" type="turtle_teleop_key" name="turtle_teleop_key" output="screen"/>


launch>




Launch启动文件的使用方法_第2张图片注意在运行前,要在功能包内创建config文件夹,并创建param.yaml文件,内容如下,group加缩进也为命名空间
Launch启动文件的使用方法_第3张图片

案例三:小海龟跟随的launch启动方法

小海龟跟随见上节ROS中的坐标系管理系统
运行c++文件

 <launch>

    
    <node pkg="turtlesim" type="turtlesim_node" name="sim"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="teleop" output="screen"/>

    <node pkg="learning_tf" type="turtle_tf_broadcaster" args="/turtle1" name="turtle1_tf_broadcaster" />
    <node pkg="learning_tf" type="turtle_tf_broadcaster" args="/turtle2" name="turtle2_tf_broadcaster" />

    <node pkg="learning_tf" type="turtle_tf_listener" name="listener" />

  launch>


运行python文件,type中加.py

<launch>

	
	<node pkg="turtlesim" type="turtlesim_node" name="sim"/>
	<node pkg="turtlesim" type="turtle_teleop_key" name="teleop" output="screen"/>

	<node name="turtle1_tf_broadcaster" pkg="learning_tf" type="turtle_tf_broadcaster.py">
	  <param name="turtle" type="string" value="turtle1" />
	node>
	<node name="turtle2_tf_broadcaster" pkg="learning_tf" type="turtle_tf_broadcaster.py">
	  <param name="turtle" type="string" value="turtle2" /> 
	node>

    <node pkg="learning_tf" type="turtle_tf_listener.py" name="listener" />

launch>

案例四:remap修改节点名

<launch>

    <include file="$(find learning_launch)/launch/simple.launch" />

    <node pkg="turtlesim" type="turtlesim_node" name="turtlesim_node">

		<remap from="/turtle1/cmd_vel" to="/cmd_vel"/>
    node>

launch>


roslaunch learning_launch turtlesim_remap.launch
重新打开终端输入rostopic list查看当前话题
Launch启动文件的使用方法_第4张图片
之前的/turtle1/cmd_vel已经改为/cmd_vel,可以用这个话题名发布速度指令
Launch启动文件的使用方法_第5张图片

你可能感兴趣的:(ROS入门,c++)