【机器人开发】一文解析ROS的launch启动文件

CSDN话题挑战赛第1期
活动详情地址:https://marketing.csdn.net/p/bb5081d88a77db8d6ef45bb7b6ef3d7f
参赛话题:自动驾驶技术学习记录
话题描述:自动驾驶是当前最火热的技术之一,吸引了无数的开发者与学习者融入其中。然而,自动驾驶技术是系统硬件平台与人工智能、物联网、大数据、云计算等新一代信息技术深度融合的产物,具有知识新、内容杂、难度深、缺少系统教程等特点,让许多开发者眼花缭乱。
本话题通过记录分享自动驾驶相关技术,为大家提供相互学习与交流的平台。话题分享与讨论的技术点包括不限于:自动驾驶算法、自动驾驶系统基础架构、智能驾驶交互技术、虚拟仿真、自动化测试、无人系统与车辆平台、自动驾驶计算平台与传感器等。

【ROS21讲】第六部分 launch启动文件(19讲)

(一)launch启动文件的概念

launch文件,是通过配置XML文件,实现多节点的配置与启动(可自动启动ROS MASTER)

(二)launch文件的语法

详细launch文件语法格式,参考链接:http://wiki.ros.org/roslaunch/XML

1、根标签<launch>

launch文件中的根元素采用标签定义
语法与案例:

2、启动节点 <node>

用于配置启动节点的相关信息
语法:
pkg:节点所在的功能包名称
type:节点的可执行文件名称
name:节点运行时的名称,因为会涉及单节点运行多次,造成重名问题
output="screen":节点标准信息输出打印到屏幕终端,默认为日志文件
respawn="true":复位属性,该节点停止是,会自动重启,默认为false
required="true":必要条件,该节点终止时,launch文件中其他节点也会终止
ns="namespace":命名空间,为节点内的相对名称添加命名空间前缀
args="arguments":节点需要输入参数
示例:

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

3、全局参数设置<param><rosparam>

<param>:设置ROS系统全局参数,将参数存储在参数服务器中,适用于单参数设置
语法<param name="output_frame" value="odom"/>
示例

<param name="turtle_name1"   value="Tom"/>
<param name="turtle_name2"   value="Jerry"/>

<rosparam>:设置ROS系统全局参数,将参数存储在参数服务器中,适用于参数文件设置
语法<rosparam file=" .yaml" command="load">
示例

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

4、局部参数设置<arg>

<arg>:设置launch文件内部的局部变量,仅lanuch文件内部使用
语法

< !-- 定义 -->
<arg name="arg-name" default="arg-value"/>
< !-- 使用 -->
<param name="foo" value="$(arg arg-name)"/>
<node name="node" pkg="package" type="type" args="$(arg arg-name)"/>

5、重映射<remap>

<remap>:重新映射ROS计算图资源的名称
语法:
from:原命名
to:映射后的命名
示例

<remap from="/turtlebot/cmd_vel" to="/cmd_vel"/>

6、嵌套<include>

<include>:包含其他launch文件,类似于C语言中的头文件包含。
语法<include file="..."/>
示例

<include file="$(dirname)/other.launch">

7、注释

语法<!-- 注释内容 -->

(三)launch文件运行方式与实例

1、launch启动文件的运行方式

语法roslaunch 功能包名 launch文件名

2、launch文件实例

<launch>
    <node pkg="learning_topic" type="person_subscriber" name="talker" output="screen" />
    <node pkg="learning_topic" type="person_publisher" name="listener" output="screen" /> 
</launch>
<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>

    <!-- Turtlesim Node-->
    <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>
<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>

CSDN话题挑战赛第1期
活动详情地址:https://marketing.csdn.net/p/bb5081d88a77db8d6ef45bb7b6ef3d7f

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
心中带点小风骚的头像心中带点小风骚普通用户
上一篇 2022年5月12日
下一篇 2022年5月12日

相关推荐