roslaunch是一个用于自动启动一系列ROS节点的命令行工具。从形式上看,该命令和rosrun有点像,需要包名和文件名。
roslaunch package_launch ****.launch
但是roslaunch操作launch文件,而不是节点。
launch文件是一组节点以及它们话题重映射和参数的XML文件。这些文件具有.launch的后缀。
在你的工作空间内
cd src
catkin_create_pkg testlaunch_bringup
cd testlaunch_bringup
mkdir launch
cd launch
nano test.launch 或者 vim test.launch
这里以显示我的takler节 Node下的takler.py 和 listenser.py为例,编写的test.launch 内容如下:
其中,每个标签包含了声明ROS图中节点所在的包文件pkg,节点的类型type,也就是可执行程序的文件名,节点的名字属性name。
output="screen"这个属性,表示talker和listener将把终端输出转储在当前控制台上,而不是日至文件中。这是一个调试常用的方法,一旦调试完成,可以去掉这个属性使输出终端更干净。
回到你的工作空间根目录
catkin_make //重新编译
roslaunch testlaunch_bringup test.launch //调用launch
运行结果如下:
started roslaunch server http://911K:36031/
SUMMARY
========
PARAMETERS
* /rosdistro: kinetic
* /rosversion: 1.12.14
NODES
/
listener (talker/listener.py)
talker (talker/talker.py)
ROS_MASTER_URI=http://localhost:11311
WARNING: Package name "calmCarVision" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes.
process[talker-1]: started with pid [8336]
process[listener-2]: started with pid [8337]
[INFO] [1563354322.533048]: hello worls 1563354322.53
[INFO] [1563354322.633193]: hello worls 1563354322.63
[INFO] [1563354322.634385]: /listenerI heard hello worls 1563354322.63
[INFO] [1563354322.733244]: hello worls 1563354322.73
[INFO] [1563354322.734434]: /listenerI heard hello worls 1563354322.73
[INFO] [1563354322.833239]: hello worls 1563354322.83
[INFO] [1563354322.834538]: /listenerI heard hello worls 1563354322.83
[INFO] [1563354322.933273]: hello worls 1563354322.93
[INFO] [1563354322.934673]: /listenerI heard hello worls 1563354322.93
[INFO] [1563354323.033265]: hello worls 1563354323.03
[INFO] [1563354323.034788]: /listenerI heard hello worls 1563354323.03
[INFO] [1563354323.133246]: hello worls 1563354323.13
[INFO] [1563354323.134533]: /listenerI heard hello worls 1563354323.13
[INFO] [1563354323.233454]: hello worls 1563354323.23
[INFO] [1563354323.234894]: /listenerI heard hello worls 1563354323.23
[INFO] [1563354323.333232]: hello worls 1563354323.33
[INFO] [1563354323.334744]: /listenerI heard hello worls 1563354323.33
[INFO] [1563354323.433267]: hello worls 1563354323.43
[INFO] [1563354323.434803]: /listenerI heard hello worls 1563354323.43
[INFO] [1563354323.533250]: hello worls 1563354323.53
[INFO] [1563354323.534827]: /listenerI heard hello worls 1563354323.53
[INFO] [1563354323.633260]: hello worls 1563354323.63
[INFO] [1563354323.634603]: /listenerI heard hello worls 1563354323.63
[INFO] [1563354323.733250]: hello worls 1563354323.73
[INFO] [1563354323.734725]: /listenerI heard hello worls 1563354323.73
[INFO] [1563354323.833287]: hello worls 1563354323.83
[INFO] [1563354323.834591]: /listenerI heard hello worls 1563354323.83
[INFO] [1563354323.933171]: hello worls 1563354323.93
[INFO] [1563354323.934433]: /listenerI heard hello worls 1563354323.93
[INFO] [1563354324.034103]: hello worls 1563354324.03
[INFO] [1563354324.035718]: /listenerI heard hello worls 1563354324.03
[INFO] [1563354324.133234]: hello worls 1563354324.13
[INFO] [1563354324.134787]: /listenerI heard hello worls 1563354324.13
[INFO] [1563354324.233226]: hello worls 1563354324.23
[INFO] [1563354324.234912]: /listenerI heard hello worls 1563354324.23
[INFO] [1563354324.333272]: hello worls 1563354324.33
[INFO] [1563354324.334603]: /listenerI heard hello worls 1563354324.33
[INFO] [1563354324.433291]: hello worls 1563354324.43
[INFO] [1563354324.434790]: /listenerI heard hello worls 1563354324.43
[INFO] [1563354324.533221]: hello worls 1563354324.53
[INFO] [1563354324.534743]: /listenerI heard hello worls 1563354324.53
[INFO] [1563354324.633243]: hello worls 1563354324.63
[INFO] [1563354324.634974]: /listenerI heard hello worls 1563354324.63
[INFO] [1563354324.733251]: hello worls 1563354324.73
[INFO] [1563354324.734788]: /listenerI heard hello worls 1563354324.73
[INFO] [1563354324.833220]: hello worls 1563354324.83
[INFO] [1563354324.834773]: /listenerI heard hello worls 1563354324.83
[INFO] [1563354324.933419]: hello worls 1563354324.93
[INFO] [1563354324.935056]: /listenerI heard hello worls 1563354324.93
[INFO] [1563354325.033219]: hello worls 1563354325.03
[INFO] [1563354325.034642]: /listenerI heard hello worls 1563354325.03
[INFO] [1563354325.133212]: hello worls 1563354325.13
[INFO] [1563354325.134689]: /listenerI heard hello worls 1563354325.13
[INFO] [1563354325.233151]: hello worls 1563354325.23
[INFO] [1563354325.234525]: /listenerI heard hello worls 1563354325.23
[INFO] [1563354325.333244]: hello worls 1563354325.33
[INFO] [1563354325.334713]: /listenerI heard hello worls 1563354325.33
[INFO] [1563354325.433243]: hello worls 1563354325.43
[INFO] [1563354325.434520]: /listenerI heard hello worls 1563354325.43
[INFO] [1563354325.533260]: hello worls 1563354325.53
[INFO] [1563354325.534742]: /listenerI heard hello worls 1563354325.53
[INFO] [1563354325.633274]: hello worls 1563354325.63
[INFO] [1563354325.634945]: /listenerI heard hello worls 1563354325.63
[INFO] [1563354325.733187]: hello worls 1563354325.73
[INFO] [1563354325.734666]: /listenerI heard hello worls 1563354325.73
[INFO] [1563354325.833235]: hello worls 1563354325.83
[INFO] [1563354325.834780]: /listenerI heard hello worls 1563354325.83
[INFO] [1563354325.933230]: hello worls 1563354325.93
[INFO] [1563354325.934662]: /listenerI heard hello worls 1563354325.93
[INFO] [1563354326.033253]: hello worls 1563354326.03
[INFO] [1563354326.034802]: /listenerI heard hello worls 1563354326.03
[INFO] [1563354326.133275]: hello worls 1563354326.13
[INFO] [1563354326.134794]: /listenerI heard hello worls 1563354326.13
[INFO] [1563354326.233278]: hello worls 1563354326.23
[INFO] [1563354326.234741]: /listenerI heard hello worls 1563354326.23
[INFO] [1563354326.333248]: hello worls 1563354326.33
[INFO] [1563354326.334829]: /listenerI heard hello worls 1563354326.33
[INFO] [1563354326.433096]: hello worls 1563354326.43
[INFO] [1563354326.434418]: /listenerI heard hello worls 1563354326.43
[INFO] [1563354326.533184]: hello worls 1563354326.53
[INFO] [1563354326.534615]: /listenerI heard hello worls 1563354326.53
[INFO] [1563354326.633264]: hello worls 1563354326.63
[INFO] [1563354326.634734]: /listenerI heard hello worls 1563354326.63
[INFO] [1563354326.733300]: hello worls 1563354326.73
[INFO] [1563354326.734860]: /listenerI heard hello worls 1563354326.73
[INFO] [1563354326.833242]: hello worls 1563354326.83
[INFO] [1563354326.834825]: /listenerI heard hello worls 1563354326.83
[INFO] [1563354326.933203]: hello worls 1563354326.93
[INFO] [1563354326.934551]: /listenerI heard hello worls 1563354326.93
[INFO] [1563354327.033295]: hello worls 1563354327.03
[INFO] [1563354327.034807]: /listenerI heard hello worls 1563354327.03
[INFO] [1563354327.133195]: hello worls 1563354327.13
[INFO] [1563354327.134773]: /listenerI heard hello worls 1563354327.13
[INFO] [1563354327.233117]: hello worls 1563354327.23
[INFO] [1563354327.234720]: /listenerI heard hello worls 1563354327.23
[INFO] [1563354327.333237]: hello worls 1563354327.33
[INFO] [1563354327.334722]: /listenerI heard hello worls 1563354327.33
[INFO] [1563354327.433253]: hello worls 1563354327.43
[INFO] [1563354327.434711]: /listenerI heard hello worls 1563354327.43
[INFO] [1563354327.533248]: hello worls 1563354327.53
[INFO] [1563354327.534816]: /listenerI heard hello worls 1563354327.53
[INFO] [1563354327.633248]: hello worls 1563354327.63
[INFO] [1563354327.634941]: /listenerI heard hello worls 1563354327.63
[INFO] [1563354327.733300]: hello worls 1563354327.73
[INFO] [1563354327.734899]: /listenerI heard hello worls 1563354327.73
[INFO] [1563354327.833278]: hello worls 1563354327.83
[INFO] [1563354327.834913]: /listenerI heard hello worls 1563354327.83
[INFO] [1563354327.933197]: hello worls 1563354327.93
[INFO] [1563354327.934611]: /listenerI heard hello worls 1563354327.93
[INFO] [1563354328.033237]: hello worls 1563354328.03
[INFO] [1563354328.034719]: /listenerI heard hello worls 1563354328.03
[INFO] [1563354328.133259]: hello worls 1563354328.13
[INFO] [1563354328.134814]: /listenerI heard hello worls 1563354328.13
[INFO] [1563354328.233270]: hello worls 1563354328.23
[INFO] [1563354328.234896]: /listenerI heard hello worls 1563354328.23
[INFO] [1563354328.333238]: hello worls 1563354328.33
[INFO] [1563354328.334574]: /listenerI heard hello worls 1563354328.33
[INFO] [1563354328.433315]: hello worls 1563354328.43
[INFO] [1563354328.434978]: /listenerI heard hello worls 1563354328.43
[INFO] [1563354328.533332]: hello worls 1563354328.53
[INFO] [1563354328.534858]: /listenerI heard hello worls 1563354328.53
[INFO] [1563354328.633157]: hello worls 1563354328.63
[INFO] [1563354328.634770]: /listenerI heard hello worls 1563354328.63
[INFO] [1563354328.733287]: hello worls 1563354328.73
[INFO] [1563354328.734809]: /listenerI heard hello worls 1563354328.73
[INFO] [1563354328.833325]: hello worls 1563354328.83
[INFO] [1563354328.834836]: /listenerI heard hello worls 1563354328.83
[INFO] [1563354328.933383]: hello worls 1563354328.93
[INFO] [1563354328.934845]: /listenerI heard hello worls 1563354328.93
[INFO] [1563354329.033229]: hello worls 1563354329.03
[INFO] [1563354329.034647]: /listenerI heard hello worls 1563354329.03
[INFO] [1563354329.133522]: hello worls 1563354329.13
[INFO] [1563354329.135275]: /listenerI heard hello worls 1563354329.13
[INFO] [1563354329.233232]: hello worls 1563354329.23
[INFO] [1563354329.234683]: /listenerI heard hello worls 1563354329.23
[INFO] [1563354329.333463]: hello worls 1563354329.33
[INFO] [1563354329.334885]: /listenerI heard hello worls 1563354329.33
[INFO] [1563354329.433225]: hello worls 1563354329.43
[INFO] [1563354329.434637]: /listenerI heard hello worls 1563354329.43
[INFO] [1563354329.533187]: hello worls 1563354329.53
[INFO] [1563354329.534820]: /listenerI heard hello worls 1563354329.53
[INFO] [1563354329.633275]: hello worls 1563354329.63
[INFO] [1563354329.634966]: /listenerI heard hello worls 1563354329.63
[INFO] [1563354329.733305]: hello worls 1563354329.73
1 roslaunch 不提供节点开始的顺序保证。这是特意的:没有办法知道哪个节点完全初始化
了,所以启动代码必须在启动顺序上鲁棒性比较强。这个行为体现了ROS哲学:每一个
节点与其他的节点都应该尽可能的独立、不相关,节点间耦合性尽可能低。
2 在开始任何一个节点前,roslaunch 将会确定 roscore是否已经在运行,如果没有则自动
启动它,因此在使用roslaunch启动节点时不用再提前启动roscore了。
3 大多数 ROS 节点在启动时连接到master节点管理器上,如果没有在launch中配置该节点
respawn属性为true运行中若连接中断,则不会尝试重新连接。因此如果 roscore被终止,
当前运行的其他节点将无法建立新的连接,即使稍后重启 roscore 也无济于事。
4.按下ctrl + c快捷键可以结束所有的节点。事实上,每次使用ROS,都需要使用roslaunch和ctrl + c来创建和销毁各种节点。