launch文件:通过XML文件实现多节点的配置和启动(可自动启动ROS Master)

launch文件中包含很多标签和属性

*launch文件语法

<launch>
<node pkg="turtlesim" name = "sim1" type="turtlesim_nade"/>
<node pkg="turtlesim" name = "sim2" type="turtlesim_node"/>
</launch>

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

        启动节点

        <node pkg="package-name"type="executable-name"name="node-name"/>

* pkg: 节点所在的功能包名称

 <node>              * type:节点的可执行文件名称

        * name: 节点运行时的名称

        * output 、respawn、required 、ns 、args

参数设置

<paran>/

<rosparam>

设置ROS系统运行中的参数,存储在参数服务器中

<param name="output_frame"value="odom"/>

*name:参数名

*value:参数值

加载参数文件中的多个参数

<rosparam file="params.yaml" command="load" ns=  "params"/>

<arg>
launch文件内部的局部变量,仅限于launch文件使用
<arg name="arg-name" default="arg-value"/>
* name: 参数名
* value: 参数值 调用如下
<param name="foo" value="$(arg arg-value"/>
<node name="node" pkg="package"type="type" args="$(arg arg-name)"/>

重映射

标签<remap>
重映射RoS计算图资源的命名
<remap from="/turtlebot/cmd_vel"to="/cmd_vel"/>
*from :原命名
* to : 映射之后的命名

嵌套

<include>
包含其他launch文件,类似C语言中的头文件包含
<include file="$(dirname)/other.launch"/>
*file :包含的其他launch文件路径

我习惯的在src目录下创建对应的功能包,为了更好的管理代码空间

$ cd ~/catkin_ws/src

$ catkin_create_pkg  learning_launch

下面介绍一些launch文件的应用例子

例1:simple.launch

 1 <launch>
2 <node pkg="learning_topic" type="person_subscriber" name="talk er" output="screen" />
3 <node pkg="learning_topic" type="person_publisher" name="liste ner" output="screen" />
4 </launch>

这个launch文件比较简单,用一个根标签包含两个node标签,启动两个node节点,启动launch文件如下,观察到两个节点并行运行。而且不需要再去启动roscore,已经自动启动了。

 qqtsj  ~  roslaunch learning_launch simple.launch
... logging to /home/qqtsj/.ros/log/a8e85210-44bd-11ea-aa0f-9822efa1466f/roslaunch-qqtsj-Nitro-AN515-51-21388.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB. started roslaunch server http://qqtsj-Nitro-AN515-51:35961/ SUMMARY
======== PARAMETERS
* /rosdistro: melodic
* /rosversion: 1.14.3 NODES
/
listener (learning_topic/person_publisher)
talker (learning_topic/person_subscriber) auto-starting new master
process[master]: started with pid [21398]
ROS_MASTER_URI=http://localhost:11311 setting /run_id to a8e85210-44bd-11ea-aa0f-9822efa1466f
process[rosout-1]: started with pid [21409]
started core service [/rosout]
process[talker-2]: started with pid [21412]
process[listener-3]: started with pid [21414]
[ INFO] [1580539196.883750317]: Publish Person Info: name:Tom age:18 sex:1
[ INFO] [1580539197.883984881]: Publish Person Info: name:Tom age:18 sex:1
[ INFO] [1580539197.884465911]: Subcribe Person Info: name:Tom age:18 sex:1
[ INFO] [1580539198.883864113]: Publish Person Info: name:Tom age:18 sex:1
[ INFO] [1580539198.884350887]: Subcribe Person Info: name:Tom age:18 sex:1

例2: turtlesim_parameter_config.launch

 1 <launch>
2
3 <param name="/turtle_number" value="2"/>
4
5 <node pkg="turtlesim" type="turtlesim_node" name="turtlesim_no de">
6 <param name="turtle_name1" value="Tom"/>
7 <param name="turtle_name2" value="Jerry"/>
8
9 <rosparam file="$(find learning_launch)/config/param.yaml" command="load"/>
10 </node>
11
12 <node pkg="turtlesim" type="turtle_teleop_key" name="turtle_te leop_key" output="screen"/>
13
14 </launch>
15
16

这个launch文件用于参数设置

 qqtsj  ~  roslaunch learning_launch turtlesim_parameter_config.launch
... logging to /home/qqtsj/.ros/log/fffc0146-44c2-11ea-aa0f-9822efa1466f/roslaunch-qqtsj-Nitro-AN515-51-23633.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB. started roslaunch server http://qqtsj-Nitro-AN515-51:36955/ SUMMARY
======== PARAMETERS
* /rosdistro: melodic
* /rosversion: 1.14.3
* /turtle_number: 2
* /turtlesim_node/A: 123
* /turtlesim_node/B: hello
* /turtlesim_node/group/C: 456
* /turtlesim_node/group/D: hello
* /turtlesim_node/turtle_name1: Tom
* /turtlesim_node/turtle_name2: Jerry NODES
/
turtle_teleop_key (turtlesim/turtle_teleop_key)
turtlesim_node (turtlesim/turtlesim_node) auto-starting new master
process[master]: started with pid [23643]
ROS_MASTER_URI=http://localhost:11311 setting /run_id to fffc0146-44c2-11ea-aa0f-9822efa1466f
process[rosout-1]: started with pid [23654]
started core service [/rosout]
process[turtlesim_node-2]: started with pid [23661]
process[turtle_teleop_key-3]: started with pid [23662]
Reading from keyboard
---------------------------
Use arrow keys to move the turtle.
 qqtsj  ~  rosparam list
/background_b
/background_g
/background_r
/rosdistro
/roslaunch/uris/host_qqtsj_nitro_an515_51__36955
/rosversion
/run_id
/turtle_number
/turtlesim_node/A
/turtlesim_node/B
/turtlesim_node/group/C
/turtlesim_node/group/D
/turtlesim_node/turtle_name1
/turtlesim_node/turtle_name2

例3:start_tf_demo_c++.launch

 1  <launch>
2
3 <!-- Turtlesim Node-->
4 <node pkg="turtlesim" type="turtlesim_node" name="sim"/>
5 <node pkg="turtlesim" type="turtle_teleop_key" name="teleop" o utput="screen"/>
6
7 <node pkg="learning_tf" type="turtle_tf_broadcaster" args="/tu rtle1" name="turtle1_tf_broadcaster" />
8 <node pkg="learning_tf" type="turtle_tf_broadcaster" args="/tu rtle2" name="turtle2_tf_broadcaster" />
9
10 <node pkg="learning_tf" type="turtle_tf_listener" name="listen er" />
11
12 </launch>

这个launch文件是上讲说的小海龟跟随实例,这里不需要开启5个终端,只需要运行对应的launch文件就可以了

 qqtsj  ~  roslaunch learning_launch start_tf_demo_c++.launch
... logging to /home/qqtsj/.ros/log/bb367d92-44cd-11ea-aa0f-9822efa1466f/roslaunch-qqtsj-Nitro-AN515-51-25949.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB. started roslaunch server http://qqtsj-Nitro-AN515-51:39467/ SUMMARY
======== PARAMETERS
* /rosdistro: melodic
* /rosversion: 1.14.3 NODES
/
listener (learning_tf/turtle_tf_listener)
sim (turtlesim/turtlesim_node)
teleop (turtlesim/turtle_teleop_key)
turtle1_tf_broadcaster (learning_tf/turtle_tf_broadcaster)
turtle2_tf_broadcaster (learning_tf/turtle_tf_broadcaster) auto-starting new master
process[master]: started with pid [25959]
ROS_MASTER_URI=http://localhost:11311 setting /run_id to bb367d92-44cd-11ea-aa0f-9822efa1466f
process[rosout-1]: started with pid [25970]
started core service [/rosout]
process[sim-2]: started with pid [25973]
process[teleop-3]: started with pid [25977]
process[turtle1_tf_broadcaster-4]: started with pid [25979]
Reading from keyboard
---------------------------
Use arrow keys to move the turtle.
process[turtle2_tf_broadcaster-5]: started with pid [25981]
process[listener-6]: started with pid [25987]

ros中launch启动文件的使用方法的更多相关文章

  1. ROS launch启动文件的理解与编写

    博客参考:https://blog.csdn.net/weixin_41995979/article/details/81784987 和 https://www.cnblogs.com/zjiaxi ...

  2. 由浅到深理解ROS(5)- launch启动文件的理解与编写

    ROS提供了一个同时启动节点管理器(master)和多个节点的途径,即使用启动文件(launch file).事实上,在ROS功能包中,启动文件的使用是非常普遍的.任何包含两个或两个以上节点的系统都可 ...

  3. 在TC(Total Commander)中添加启动Cygwin快捷键的方法

    在TC(Total Commander)中添加启动Cygwin快捷键的方法 1.在Cygwin的安装目录下,增加文件tc-cygwin.bat(例如C:\cygwin-177\tc-cygwin.ba ...

  4. 在.net中读写config文件的各种方法

    阅读目录 开始 config文件 - 自定义配置节点 config文件 - Property config文件 - Element config文件 - CDATA config文件 - Collec ...

  5. 在.net中读写config文件的各种方法(自定义config节点)

    http://www.cnblogs.com/fish-li/archive/2011/12/18/2292037.html 阅读目录 开始 config文件 - 自定义配置节点 config文件 - ...

  6. 在.net中读写config文件的各种方法【转】

    今天谈谈在.net中读写config文件的各种方法. 在这篇博客中,我将介绍各种配置文件的读写操作. 由于内容较为直观,因此没有过多的空道理,只有实实在在的演示代码, 目的只为了再现实战开发中的各种场 ...

  7. 【AT91SAM3S】英蓓特EM-SAM3S开发板例子工程中的启动文件分析

    手上一块英倍特的EM-SAM3S开发板,拿到已经有一个月了.本来是做uLoong活动使用的板子,可当初由于不熟悉这个芯片,使用了STM32F4当作了替代.最近准备抽点时间折腾下这个板子. 这个板子的资 ...

  8. iOS:Xcode中SVN不能提交CocoaPods中的.a文件的解决方法

    不能提交.a文件, 这个与SVN的配置有关, 其实与xcode倒没有关系. 解决方法: 1. 打开终端,  在命令行中输入: vi ~/.subversion/config  来打开配置文件.2. 然 ...

  9. ROS中.launch文件的remap标签详解

    https://www.cnblogs.com/LiuQiang921202/p/7679943.html

随机推荐

  1. 洛谷$P5444\ [APIO2019]$奇怪装置 数论

    正解:数论 解题报告: 传送门$QwQ$ 我好像当初考的时候这题爆零了,,,部分分都没想到,,,我真的好菜$kk$ 考虑如果在$t_1,t_2$两个时刻有$x_1=x_2,y_1=y_2$是什么情况$ ...

  2. 洛谷$P$1402 酒店之王 网络流

    正解:网络流 解题报告: 传送门! 一看就很网络流昂,,,于是现在的问题就变成怎么建图了$QwQ$ 首先如果只有一个要求,那就直接按要求建图然后跑个最大流就好. 现在变成,有两个要求,必须同时满足,考 ...

  3. $CF559C\ Gerald\ and\ Fiant\ Chess$ 计数类$DP$

    AcWing Description 有个$H$行$W$列的棋盘,里面有$N$个黑色格子,求一个棋子由左上方格子走到右下方格子且不经过黑色格子的方案数. $1<=H,M<=1e5,1< ...

  4. Java虚拟机详解(十一)------双亲委派模型

    在上一篇博客,我们介绍了类加载过程,包括5个阶段,分别是“加载”,“验证”,“准备”,“解析”,“初始化”,如下图所示: 本篇博客,我们来介绍Java虚拟机的双亲委派模型,在介绍之前,我先抛出一个问题 ...

  5. 7.netty内存管理-ByteBuf

    ByteBuf ByteBuf是什么 ByteBuf重要API read.write.set.skipBytes mark和reset duplicate.slice.copy retain.rele ...

  6. kubernetes-dashboard部署

    参考资料: kubernetes官方文档 官方GitHub 创建访问用户 解决chrome无法访问dashboard 官方部署方法如下: kubectl apply -f https://raw.gi ...

  7. Linux下卸载oracle需要删除的文件

    卸载oracle需要删除的文件 rm -rf /data1/oracle/app  #oracle安装目录在/data1/oracle中 rm -rf /usr/local/bin/dbhome rm ...

  8. linux文件通配符

    * #匹配任意字符 ? #匹配任意单个字符 ~ #当前用户家目录 ~user #用户user的家目录 ~+ #当前工作目录 ~- #前一个工作目录 [0-9] #匹配的数字范围 [a-z] #匹配小写 ...

  9. Java 基础(一)| 使用泛型的正确姿势

    前言 为跳槽面试做准备,今天开始进入 Java 基础的复习.希望基础不好的同学看完这篇文章,能掌握泛型,而基础好的同学权当复习,希望看完这篇文章能够起一点你的青涩记忆. 一.什么是泛型 泛型,即&qu ...

  10. NOIP2004普及组第3题 FBI树

    /* 1106: NOIP2004普及组第3题 FBI树 时间限制: 1 Sec 内存限制: 128 MB 提交: 10 解决: 9 [提交] [状态] [讨论版] [命题人:外部导入] 题目描述 我 ...