上网查了很多关于lauch文件中的pkg,type,都是说是包和可执行文件,具体这个文件在哪个文件夹也不甚清楚,实操了一番,记录一下。
这里不是写launch文件怎样写,也不是多个node启动,只写一个node,为了说明pkg和type在哪。
下面是一个示例的完整流程:
- cd ~/git (其他文件夹也可)
- git clone https://github.com/ethz-asl/ros_best_practices.git
- ln -s ~/git/ros_best_practices/ ~/catkin_ws/src/ (建立symbolic link, 多个项目时比较方便)
- cd ~/catkin_ws
- catkin build ros_package_template (ros_package_template在ros_best_practices文件夹下)
- source devel/setup.bash (更新work space)
- 可以看到~/catkin_ws/src/ros_best_practices/ros_package_template/launch文件夹下已经有了ros_package_template.launch
这时可以直接用roslaunch ros_package_template ros_package_template.launch命令启动
如果想写一个launch文件,通过launch文件启动的话,可用如下模板
<launch>
<node pkg="" type="" name="" output="screen">
</node>
</launch>
现在的问题是pkg和type应该写哪个
可以在~/catkin_ws/devel/lib 文件夹下看到刚才build好的ros_package_template文件夹,进入ros_package_template文件夹内发现有个可执行文件ros_package_template
所以这时pkg就是文件夹的名字ros_package_template,type就是可执行文件的名字ros_package_template(虽然它俩一样),name可以自己取,仍然取ros_package_template
这个launch文件的内容如下,命名为test.launch,假设把它放在~/git下面
<launch>
<node pkg="ros_package_template" type="ros_package_template" name="ros_package_template" output="screen">
</node>
</launch>
启动它时用roslaunch ~/git/test.launch即可