很多launch文件中,都会去调用某个文件作为package的参数。
比如rviz:
<node launch-prefix="nice" pkg="rviz" type="rviz" name="rviz" args="-d $(find covgrid_slam_ros)/rviz_cfg/covgrid_mapping.rviz" />
其中,$(find covgrid_slam_ros) 用来定位到一个package,增强了项目的可移植性。
那么如何在自己的项目中实现find呢?
其实,find能够在项目中自动寻找后面指定名字的包的路径,因此必不可少的两个要素:CMakeLists.txt和package.xml
1. CMakeLists.txt
CMakeLists.txt中加入项目名称即可
cmake_minimum_required(VERSION 2.8.3)
project(calib_file)
2. package.xml
package.xml中指定name等。要注意其中有一些参数是不可缺少的。比如maintainer等。所以最好把下面所有参数都写上,随便写一些就可以。
<package>
<name>calib_file</name>
<version>1.0.0</version>
<description>for calibration file</description>
<maintainer email="mjy121225@163.com">MJY</maintainer>
<url type="website">http://wiki.ros.org/Robots/Pioneer</url>
<author email="mjy9dfsf8065@163.com">MJY</author>
<author>Adept MobileRobots</author>
<license>BSD</license>
<run_depend>roslaunch</run_depend>
</package>
这样就可以在launch文件中愉快的使用find找到目标位置了。
如:
<param name="camera_info_url" type="string" value="file://$(find calib_file)/camera_calibration.yaml" />