ROS2-launch文件的入门
launch文件介绍
我们在之前运行listener和talker两个节点的时候肯定注意到过一个问题,就是我们需要重复打开两个终端,运行两次,那如果我们做一个大型项目,里面包含了一万个节点,难道我们要打开一万个终端,输入一万个指令吗?这显然是浪费生命且D疼的一件事,这也是不可能出现在发展了这么久的ROS上的。于是乎,launch应运而生,他就可以很好地解决这个问题。
launch文件主要就是将所有要运行的节点信息写在该文件中,然后运行这个launch文件即可,这样就省去了极大的麻烦。当然官方文档对他的介绍是相当隆重的:
The launch system in ROS 2 is responsible for helping the user describe the configuration of their system and then execute it as described. The configuration of the system includes what programs to run, where to run them, what arguments to pass them, and ROS-specific conventions which make it easy to reuse components throughout the system by giving them each a different configuration. It is also responsible for monitoring the state of the processes launched, and reporting and/or reacting to changes in the state of those processes.
大概意思就是可以描述配置,可以运行配置,还可以监视配置,等。
创建launch文件
官方教程是新建功能包再进行教程,我们这里为了更好的运用,所以就利用上次的cpp_pubsub功能包了。首先在包目录下创建一个launch文件夹,再在文件夹内创建相应的launch文件。如图
这