ROS入门——ROS基础语法(launch文件)


通过xml文件实现多节点的配置与启动(可自启动ROS Master)

1. launch文件语法概述

<launch>launch文件中的根元素采用<launch> 标签定义

<node> 启动节点

<node pkg="package-name" type="execulate-name" name="node-name"/>
pkg :功能包名称
type:节点可执行文件名称
name:节点运行时的名称

参数设置:
<param>/<rosparam>
设置ROS系统运行参数,存储在参数服务器中

<param name="output_name"   value="odom"/>
name:参数名
value:参数值

加载参数文件中的多个参数
<rosparam file="params.yaml" command="load"ns="params"/>
例:<rosparam file="$(find learning_launch)/config/param.yaml" command="load"/>

<arg>
launch文件内部的局部变量,仅仅在launch文件中使用

<arg name="arg_name" default="arg_value"/>
name:参数名
value:参数值
<param name="foo" value="$(arg arg_name)"/>
<node name="node pkg="package-name" type="type" arg="$(arg arg_name)"/>

重映射:
<remap> 重映射ROS计算图资源的命名
tips:remap之后,原命名会不复存在

<remap from="/turtle1/cmd_vel" to="/cmd_vel"/>
from:原命名
to:之后的命名

嵌套:
<include>包含其他launch的头文件,类似c与cpp

<include file="$(dirname)/other.launch" />
例:<include file="$(find learning_launch)/launch/simple.launch" />

2. 实例讲述

2.1 launch启动文件实例

编写相关simple.cpp文件

<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

2.2 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>

编译运行

roslaunch learning_launch start_tf_demo_c++.launch 

2.3 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>

编译运行
若更改后小乌龟正常运动,则正常

roslaunch learning_launch turtlesim_remap.launch
rostopic pub /cmd_vel geometry_msgs/Twist "linear:
  x: 1.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 0.0" 

3.参考内容

launch启动文件的使用
ROS入门——ROS基础语法(parameter&tf)

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Teviour Camdylre

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值