ROS编译:catkin简析
博客转载自:https://blog.csdn.net/zyh821351004/article/details/50388429
Catkin tutorials: http://wiki.ros.org/catkin/Tutorials
1. catkin_make 与cmake的关系
程序在cmake编译是这样的流程, cmake指令依据你的CMakeLists.txt 文件,生成makefiles文件,make再依据此makefiles文件编译链接生成可执行文件. catkin_make是将cmake与make的编译方式做了一个封装的指令工具, 规范了工作路径与生成文件路径.
cmake标准流程
# 在一个CMake项目里
$ mkdir build
$ cd build
$ cmake ..
$ make
$ make install # (可选)
catkin_make 的流程
# In a catkin workspace
$ catkin_make
$ catkin_make install # (可选) 如果源码不在默认工作空间,需要指定编译路径:
# In a catkin workspace
$ catkin_make --source my_src
$ catkin_make install --source my_src # (optionally)
2.catkin_make
more information: Catkin Variables
1).catkin_make默认的路径信息
在catkin_make运行后终端输出文件部分解析 #基本路径
Base path: /home/user/catkin_ws
Source space: /home/user/catkin_ws/src
Build space: /home/user/catkin_ws/build
Devel space: /home/user/catkin_ws/devel
Install space: /home/user/catkin_ws/install #catkin_make 封装运行中cmake运行的情况
Running command: "cmake /home/user/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/user/catkin_ws/devel
-DCMAKE_INSTALL_PREFIX=/home/user/catkin_ws/install" in "/home/user/catkin_ws/build" #编译工具查找
-- Using CATKIN_DEVEL_PREFIX: /tmp/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/groovy
-- This workspace overlays: /opt/ros/groovy #编译的包
<pre name="code" class="cpp">#catkin_make 封装运行中make运行的情况 # Running command: "make -j4" in "/home/user/catkin_ws/build"
2).layout:ros工作空间文件系统结构
workspace_folder/ --WORKSPACE
src/ --SOURCE SPACE
CMakeLists.txt/ --This is symlinked to catkin/cmake/toplevel.cmake
package_1/
CMakeLists.txt
package.xml
...
package_n/
CMakeLists.txt
package.xml
build/ --BUILD SPACE(this is where build system is invoked, not necessarily within workspace)
CATKIN_IGNORE --Marking the folder to be ignored when crawling for packages (necessary when source
space is in the root of the workspace, the file is emtpy)
#此选项可用于忽略某个包编译
devel/ --DEVEL SPACE (targets go here, parameterizable, but defaults to peer of Build Space)
# 生成二值 库 可执行文件
bin/
etc/
/include/
lib/
share/
.catkin --Marking the folder as a development space (the file contains a semicolon separated list of Source space paths)
#
env.bash
setup.bash
setup.sh
...
install/ --INSTALL SPACE (this is where installed targets for test installations go, not necessarily within workspace)
bin/
etc/
include/
lib/
share/
.catkin --Marking the folder as an install space (the file is emtpy)
env.bash
setup.bash -- Environment setup file for Bash shell
setup.sh -- Environment setup file for Bourne shell
...
/
opt/
ros/
groovy/
setup.bash -- Environment setup file for Bash shell
setup.sh -- Environment setup file for Bourne shell
setup.zsh -- Environment setup file for zshell
...
说明
工作空间
源空间
编译空间
开发空间 安装空间 -DCMAKE_INSTALL_PREFIX=/any/directorycmake默认是/usr/local 系统安装空间 /opt/ros/ROSDISTRO 结果空间 source RESULT-SPACE/setup.sh 类似扫描安装空间与开发空间,替换系统通用下的对应文件.
3).Overlays
catkin支持包的逐层覆盖, 当前最高,其它依据source的顺序逐层变高, 高层可覆盖低层.
Example 4: Overlaying workspace 3 on top of local workspace2 install space on top of workspace1 devel space on top of system install cd ~/workspace2/build
cmake -DCMAKE_INSTALL_PREFIX=~/ws2_installed ../src
make
make install source ~/ws2_installed/setup.bash cd ~/workspace3/build
cmake ../src
make
ros 环境变量设置 可以参考.bashrc文件: ros工作环境设置
###### slam_ws
source /opt/ros/indigo/setup.bash
source /home/yhzhao/slam_ws/devel/setup.bash export ROS_PACKAGE_PATH=~/slam_ws/src:$ROS_PACKAGE_PATH
export ROS_WORKSPACE=~/slam_ws/src
4) 混合 Mixing catkin And rosbuild Workspaces
catkin was designed to allow rosbuild packages to sit on top of catkin ones. This is accomplished by using overlays.
~/rosbuild_ws/
dry_pkg1/
...
dry_pkgN/
setup.bash
setup.sh
~/catkin_ws/
src/
wet_pkg1/
...
wet_pkgN/
build/
devel/
setup.bash
setup.sh
install/
setup.bash
setup.sh
注: 我们在系统文件夹下的 .bashrc 中加入相应的source文件, 就是为了添加ros 的环境变量等信息.
Differences in CMakeLists.txt for rosbuild and catkin
5) catkin_make 编译指定的包
catkin_make -DCATKIN_WHITELIST_PACKAGES="package1;package2"
恢复编译所有的包
catkin_make -DCATKIN_WHITELIST_PACKAGES=""
4. package. xml 与 CMakeList. txt
4.1 package. xml
每个包的描述文件,都需要放置在包的根目录下,对包的名字/版本/作者/维护者/依赖关系进行说明.与rosbuild中的manifest.xml相似. 依赖不正确在本地可以可以编译通过,但不能在ROS社区正确工作起来.
4.1.1 格式
<package>
<name>foo_core</name>
<version>1.2.4</version>
<description>
This package provides foo capability.
</description>
<maintainer email="ivana@willowgarage.com">Ivana Bildbotz</maintainer>
<license>BSD</license> <url>http://ros.org/wiki/foo_core</url>
<author>Ivana Bildbotz</author> <buildtool_depend>catkin</buildtool_depend> <depend>roscpp</depend>
<depend>std_msgs</depend> <build_depend>message_generation</build_depend> <exec_depend>message_runtime</exec_depend>
<exec_depend>rospy</exec_depend> <test_depend>python-mock</test_depend> <doc_depend>doxygen</doc_depend>
</package>
C++ catkin library dependencies: http://docs.ros.org/jade/api/catkin/html/howto/format2/catkin_library_dependencies.html
6种依赖标签
1. Build Dependencies 指出你的包编译需要依赖的包
2. Build Export Dependencies 指出你的包编译导出库
specify which packages are needed to build libraries against this package. This is the case when you transitively include their headers in
public headers in this package (especially when these packages are declared as (CATKIN_)DEPENDS in catkin_package() in CMake).
3. Execution Dependencies 执行时依赖
4. Test Dependencies 单元测试
5. Build Tool Dependencies 编译系统工具
6. Documentation Tool Dependencies doc生成工具
<depend> specifies that a dependency is a build, export, and execution dependency. This is the most commonly used dependency tag.
<buildtool_depend>
<build_depend>
<build_export_depend>
<exec_depend>
<test_depend>
<doc_depend>http://write.blog.csdn.net/postedit/50388429
4.1.2 Metapackages 将多个包组合成一个逻辑包
<export>
<metapackage />
</export>
仅需要标签: <buildtool_depends> 依赖 catkin 和 <run_depend>,对应cmakelists.txt中
cmake_minimum_required(VERSION 2.8.3)
project(<PACKAGE_NAME>)
find_package(catkin REQUIRED)
catkin_metapackage()
通用版本的package.xml
<package>
<name>universal_robot</name>
<version>1.1.5</version>
<description>
Drivers, description, and utilities for Universal Robot Arms.
</description> <maintainer email="aub@ipa.fhg.de">Alexander Bubeck</maintainer> <license>BSD</license> <url type="website">http://ros.org/wiki/universal_robot</url> <author email="sedwards@swri.org">Shaun Edwards</author>
<author>Stuart Glaser</author>
<author email="kphawkins@gatech.edu">Kelsey Hawkins</author>
<author>Wim Meeussen</author>
<author email="fxm@ipa.fhg.de">Felix Messmer</author> <buildtool_depend>catkin</buildtool_depend>
<run_depend>ur3_moveit_config</run_depend>
<run_depend>ur5_moveit_config</run_depend>
<run_depend>ur10_moveit_config</run_depend>
<run_depend>ur_bringup</run_depend>
<run_depend>ur_description</run_depend>
<run_depend>ur_driver</run_depend>
<run_depend>ur_gazebo</run_depend>
<run_depend>ur_kinematics</run_depend>
<run_depend>ur_msgs</run_depend> <export>
<metapackage/>
</export>
</package>
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
project(universal_robot)
find_package(catkin REQUIRED)
catkin_metapackage()
4.2 CMakeLists.txt
cmak 不会找package.xml文件, 但catkin需要. 依据cmakelists.txt文件编译需要清晰指出头文件和库文件的指向.
Finding the library: 需要在package.xml中使用标签<depend> 或者<build_depend>
find_package(catkin REQUIRED COMPONENTS roscpp)
Include directories
include_directories(include ${catkin_INCLUDE_DIRS})
Exporting interfaces: 需要在package.xml中使用<depend> 或者<build_export_depend>,catkin_package() 命令仅调用一次,它需要额外的参数依赖于你的包导出的依赖.
catkin_package(CATKIN_DEPENDS angles roscpp std_msgs)
4.3 C++ 系统库依赖
Finding the library
1) 依据CMake module . 大部分的boost 库在头文件完全实现,运行时不需要独立的分享连接.
find_package(Boost REQUIRED)
但boost thread 运行时需要库,必须指出组件thread .
find_package(Boost REQUIRED COMPONENTS thread)
find_package()之后就可以用此编译和连接了. 命名规则基本是这样: ${name}_INCLUDE_DIRS and${name}_LIBRARIES .
2) cmake modules 无效情况下,但库开发包提供了pkg-config module . 编译标签
find_package(PkgConfig REQUIRED)
pkg_check_modules(GSTREAMER REQUIRED libgstreamer-0.10)
pkg_check_modules() 参数声明了一个cmake前缀,GSTREAMER_INCLUDE_DIRS 和GSTREAMER_LIBRARIES,用于命令行中插入正确的编译选项. (.pc文件 ) libgstreamer-0.10.pc.
Include directories
include_directories(include ${Boost_INCLUDE_DIRS} ${GSTREAMER_INCLUDE_DIRS})
如有依赖catkin 包 ,再添加 ${catkin_INCLUDE_DIRS}
Exporting interfaces
catkin_package(DEPENDS Boost GSTREAMER)
确保所有的包在package.xml被用到, <build_export_depend> 和<depend>标签, 标准命名 ${name}_INCLUDE_DIRS and${name}_LIBRARIES . catkin包一般是小写,大写(asGSTREAMER) 或混合 (likeBoost)
4.4 编译安装 C++ libraries and headers
include_directories(include
${catkin_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${GSTREAMER_INCLUDE_DIRS})
生成库
add_library(libName libsrc1.cpp libsrc2.cpp libsrc_etc.cpp)
或者
set(YOUR_LIB_SOURCES
libsrc1.cpp
libsrc2.cpp
libsrc3.cpp
libsrc4.cpp
libsrc_etc.cpp)
add_library(your_library ${YOUR_LIB_SOURCES})
target_link_libraries(libName${catkin_LIBRARIES})
链接库
target_link_libraries(libName
${catkin_LIBRARIES}
${Boost_LIBRARIES}
${GSTREAMER_LIBRARIES})
catkin_package(CATKIN_DEPENDS std_msgs
DEPENDS Boost
INCLUDE_DIRS include
LIBRARIES your_library)
<depend>std_msgs</depend>
<build_export_depend>boost</build_export_depend>
安装
install(TARGETS your_library your_other_library
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION})
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
PATTERN ".svn" EXCLUDE)
4.5 编译安装 C++ 执行文件
include_directories(include
${catkin_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${GSTREAMER_INCLUDE_DIRS})
add_executable(you_node src1.cpp src2.cpp src_etc.cpp)
set(${PROJECT_NAME}_SOURCES
src/file1.cpp
src/file2.cpp
src/file3.cpp
src/file4.cpp
src/file5.cpp
src/file6.cpp
src/file_etc.cpp)
add_executable(your_node ${${PROJECT_NAME}_SOURCES})
add_executable(your_node ${${PROJECT_NAME}_SOURCES})
target_link_libraries(your_node ${catkin_LIBRARIES})
add_executable(your_node ${${PROJECT_NAME}_SOURCES})
target_link_libraries(your_node
${catkin_LIBRARIES}
${Boost_LIBRARIES}
${GSTREAMER_LIBRARIES})
ros下的安装,使得rosrun 与roslaunch能够使用.需要下面的方式安装.
install(TARGETS your_node
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
安装 cmake文件
catkin_package(CFG_EXTRAS your_macros.cmake your_modules.cmake)
install(FILES cmake/your_macros.cmake cmake/your_modules.cmake
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/cmake)
install(DIRECTORY cmake
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
PATTERN ".svn" EXCLUDE)
ROS编译:catkin简析的更多相关文章
- 简析.NET Core 以及与 .NET Framework的关系
简析.NET Core 以及与 .NET Framework的关系 一 .NET 的 Framework 们 二 .NET Core的到来 1. Runtime 2. Unified BCL 3. W ...
- 简析 .NET Core 构成体系
简析 .NET Core 构成体系 Roslyn 编译器 RyuJIT 编译器 CoreCLR & CoreRT CoreFX(.NET Core Libraries) .NET Core 代 ...
- PHP的错误报错级别设置原理简析
原理简析 摘录php.ini文件的默认配置(php5.4): ; Common Values: ; E_ALL (Show all errors, warnings and notices inclu ...
- Java Annotation 及几个常用开源项目注解原理简析
PDF 版: Java Annotation.pdf, PPT 版:Java Annotation.pptx, Keynote 版:Java Annotation.key 一.Annotation 示 ...
- 《共享库PATH与ld.so.conf简析》
这是摘抄<共享库PATH与ld.so.conf简析>1. 往/lib和/usr/lib里面加东西,是不用修改/etc/ld.so.conf的,但是完了之后要调一下ldconfig,不然这个 ...
- PHP单一文件入口框架简析
<?php /** * PHP单一文件框架设计简析 * 1.MVC架构实现 * 2.URL路由原理 */ //URL路由原理 /** * 路由作用 * 获取url中的c和a变量,执行c类对应的方 ...
- Linux 目录结构学习与简析 Part2
linux目录结构学习与简析 by:授客 QQ:1033553122 ---------------接Part 1-------------- #1.查看CPU信息 #cat /proc/cpuinf ...
- Unity5中新的Shader体系简析
一.Unity5中新的Shader体系简析 Unity5和之前的书写模式有了一定的改变.Unity5时代的Shader Reference官方文档也进一步地变得丰满. 主要需要了解到的是,在原来的Un ...
- ROS学习笔记一(ROS的catkin工作空间)
在安装完成ROS indigo之后,需要查看环境变量是否设置正确,并通过创建一个简单的实例来验证ROS能否正常运行. 1 查看环境变量 在ROS的安装过程中,我们执行了如下命令:(此命令就是向当前用户 ...
随机推荐
- EL表达式可以直接放在url的“ ”里面
<div class="hc-prm-search search flr"> <form action="/userCenter/projectInfo ...
- Spring、Spring MVC、Struts2优缺点整理
Spring 及其优点 大部分项目都少不了Spring的身影,为什么大家对他如此青睐,而且对他的追捧丝毫没有减退之势呢 Spring是什么: Spring是一个轻量级的DI和AOP容器框架. 说它轻量 ...
- hibernate 一对一(One-to-One)
一对一(one-to-one)实例(Person-IdCard) 一对一的关系在数据库中表示为主外关系.例如.人和身份证的关系.每个人都对应一个身份证号.我们应该两个表.一个是关于人信息的表(Pers ...
- 转载FPGA学习之内嵌乘法器调用
补充一点,除法的时候如果直接a/b那么就会调用lpm模块,不管输入是否是常数,乘法的时候输入都是reg型变量会调用硬件乘法器,有一个是常数就会调用lpm模块. 上课的时候一直听老师说真正实践的时候你别 ...
- 【java规则引擎】一个基于drools规则引擎实现的数学计算例子
最近在研究JBPM工作流引擎,发现JBPM是基于Drools的,官方文档查看得知Drools是一款规则引擎.兴趣之下,仔细了解了下 Drools,Drools作为JBoss出品的一款开源推理和规则引擎 ...
- CentOS虚拟机中安装VMWare Tools
1.单击VMWare的[虚拟机]菜单,选择[安装VMWare Tools]命令 2.接着CentOS系统会自动挂载VMWare Tools,并自动打开,如果没有打开可以自己去图形界面打开VMWare ...
- ASP.NET Cache缓存的使用
ASP.NET Cache是提升系统性能的重要方法,它使用了“最近使用”原则(a least-recently-used algorithm).在数据库访问中经常会用到Cache保存数据库数据. 1. ...
- Kubernetes安装部署演示介绍
四.安装k8s 1.安装 使用的是k8s 1.2.4版本. 将kubernetes.tar.gz 上传主机,并解压. tar -xzvf kubernetes.tar.gz cd kubernetes ...
- php redis 常用方法
一些php redis 常用的方法: 1.hGet($key,$hashKey) Redis Hget 命令用于返回哈希表中指定字段的值. <?php $redis = new redis(); ...
- AD芯片的基准参考电压问题
基准参考电压的精度一般非常高的! AD芯片 : AD9226的基准参考电压 误差一般是 千分之一! 我之前用万用表测量AD9226的参考电压大概是1.89V(这款AD的正确参考电压应该是2V),所 ...