ROS软件包开发完成后,需要安装包,如果你用的是catkin创建的工作空间,那么即可使用命令"catkin_make install"完成此项任务.下面介绍其安装的过程:
1.源码准备
准备好需要安装的代码,通常可以使用catkin来创建工作空间,包和编译整个项目.本例子假定工作空间为catkin_ws,包名为package_install.目录如下图所示:
2.编辑CMakeLists.txt
打开package/CMakeLists.txt,在文件末尾添加添加如下的代码:
############# ## Install ## ############# # all install targets should use catkin DESTINATION variables # See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html ## Mark executable scripts (Python etc.) for installation ## 添加python程序.in contrast to setup.py, you can choose the destination install(PROGRAMS scripts/talker.py scripts/listener.py DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} ) ## 添加可执行文件或者库文件,Mark executables and/or libraries for installation install(TARGETS talker_node listener_node ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} ) ## 添加头文件.Mark cpp header files for installation install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} FILES_MATCHING PATTERN "*.h" PATTERN ".svn" EXCLUDE ) ## 添加资源文件的目录,例如文件夹:urdf mesh rviz,其下的所有子目录的文件也会安装到相应的目录下. install(DIRECTORY model DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} ) install(DIRECTORY urdf DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} ) install(DIRECTORY mesh DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} ) install(DIRECTORY rviz DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} ) ## 添加资源文件.Mark other files for installation (e.g. launch and bag files, etc.) install(FILES launch/bringup.launch DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch )
3.编译
打开命令终端,到catkin_ws目录下,执行如下命令:
catkin_make install
安装的文件会生成在目录catkin_ws/install下.目录的结构如下图所示
4.运行
a.首先,可将install整个文件夹随意拷贝到一个目录下;然后,打开命令终端,到该目录install下,执行如下命令:
source devel/setup.bash
b.打开命令终端,运行程序,执行如下命令:
roslaunch package_install bringup.launch
这样就可以把安装的程序跑起来了.
5.源码
源码下载:catkin_ws.rar