在 Mac OS Sierra(10.12.3)中编译安装 ROS Kinetic

在 Mac OS Sierra(10.12.3)中编译安装 ROS Kinetic_第1张图片
“Mac OS下通过Matlab控制ROS的Turtlesim”

ROS最初是作为科研辅助工具由斯坦福大学开发的,由于ROS极大的开放性和包容性,它能够兼容其他机器人开发工具、仿真工具和操作系统、使之融为一体。这使得ROS不断发展壮大,并成为应用和影响力最广泛的机器人软件平台。

对于Ubuntu系统,安装ROS只需要按照官网提供的教程Ubuntu install of ROS Kinetic安装即可。

对于苹果电脑,官网的安装文档[Installation Instructions for Kinetic in OS X][]提示

This is a work in progress! It really won't work right now...

按照其步骤安装有比较多的错误,查了比较多的资料终于部分安装成果。记录一下安装步骤。

主要步骤是参考Ubuntu install of ROS Kinetic和ros-install-osx

1. 编译环境

  • OS: Mac OS Sierra (10.12.3)
  • cmake: 3.7.2
  • python2: 2.7.13 (/usr/local/bin/python2)
  • python3: 3.6.0 (/usr/local/bin/python3)
  • Qt5: 5.8.0 (/usr/local/bin/qmake)
  • PyQt5: 5.8

2. 编译安装步骤

2.1 配置环境

$ brew update
$ brew install cmake
$ brew tap ros/deps
$ brew tap osrf/simulation   # Gazebo, sdformat, and ogre
$ brew tap homebrew/versions # VTK5
$ brew tap homebrew/science  # others
$ brew install caskroom/cask/brew-cask
$ brew cask install xquartz

Python

Python最好不要使用系统自带的,这里python2、python3均是通过brew安装,位于/usr/local/bin目录,

$ mkdir -p ~/Library/Python/2.7/lib/python/site-packages
$ echo "$(brew --prefix)/lib/python2.7/site-packages" >> ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth
$ brew install libyaml 
$ pip install -U setuptools rosdep rosinstall_generator wstool rosinstall catkin_tools bloom empy sphinx pycurl

初始化rosdep

$ sudo rosdep init
$ sudo sh -c "echo 'yaml https://raw.githubusercontent.com/mikepurvis/ros-install-osx/master/rosdeps.yaml osx' > /etc/ros/rosdep/sources.list.d/10-ros-install-osx.list"
$ rosdep update

初始化工作目录

$ mkdir -p kinetic_desktop_full_ws/src
$ cd kinetic_desktop_full_ws
$ rosinstall_generator desktop_full --rosdistro kinetic --deps --tar > kinetic_desktop_full.rosinstall
$ wstool init -j8 src kinetic_desktop_full.rosinstall # 下载包

这里desktop_full 包含了ROS, rqt, rviz, robot-generic libraries, 2D/3D simulators, navigation2D/3D perception等包,还可以换成desktopros_comm
如果长时间下载未完成,可以中断进程,然后重新下载

$ wstool update -j 8 -t src

更新包

desktop_full也不是最完整的,还可以单独安装其他的包,更多的包可以查看ros-gbp。例如,如果需要moveit 包,可以如下操作:

$ rosinstall_generator moveit --rosdistro kinetic --deps --tar > moveit.rosinstall
$ wstool merge -t src moveit.rosinstall
$ wstool update -t src

如果提示已经下载了包,则可以按s跳过。

安装补丁

# Grabbing these older meshes allows rviz to run with Ogre 1.7 rather than Ogre 1.8+.
# Some details here: https://github.com/ros-visualization/rviz/issues/782
$ cd src/rviz/ogre_media/models
$ curl https://raw.githubusercontent.com/ros-visualization/rviz/hydro-devel/ogre_media/models/rviz_cone.mesh > rviz_cone.mesh
$ curl https://raw.githubusercontent.com/ros-visualization/rviz/hydro-devel/ogre_media/models/rviz_cube.mesh > rviz_cube.mesh
$ curl https://raw.githubusercontent.com/ros-visualization/rviz/hydro-devel/ogre_media/models/rviz_cylinder.mesh > rviz_cylinder.mesh
$ curl https://raw.githubusercontent.com/ros-visualization/rviz/hydro-devel/ogre_media/models/rviz_sphere.mesh > rviz_sphere.mesh
$ cd -
# This patch originates from here: https://github.com/ros/catkin/pull/784
$ cd  src/catkin/cmake
$ curl https://raw.githubusercontent.com/ros/catkin/8a47f4eceb4954beb4a5b38b50793d0bbe2c96cf/cmake/catkinConfig.cmake.in > catkinConfig.cmake.in
$ cd -

解决依赖

$ rosdep install --from-paths src --ignore-src --rosdistro kinetic -y --as-root pip:no --skip-keys=python-qt-bindings-qwt5

创建安装目录

$ sudo mkdir -p /opt/ros/kinetic
$ sudo chown $USER /opt/ros/kinetic

2.2 编译安装

配置

$ catkin config --install  --install-space /opt/ros/kinetic --cmake-args \
    -DCMAKE_FIND_FRAMEWORK=LAST \
    -DCATKIN_ENABLE_TESTING=1 \
    -DCMAKE_BUILD_TYPE=Release \
    -DPYTHON_LIBRARY=$(python -c "import sys; print sys.prefix")/lib/libpython2.7.dylib \
    -DPYTHON_INCLUDE_DIR=$(python -c "import sys; print sys.prefix")/include/python2.7  \
    -DPYTHON3_LIBRARY=$(python3 -c "import sys; print (sys.prefix)")/lib/libpython3.6.dylib \
    -DPYTHON3_INCLUDE_DIR=$(python3 -c "import sys; print (sys.prefix)")/include/python3.6m \
    -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -DQT_MAC_USE_COCOA"

其中 -DCMAKE_FIND_FRAMEWORK=LAST选项是为了解决下面的问题no member named 'xxx'添加的。
-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -DQT_MAC_USE_COCOA"选项是为了解决rviz启动时Segmentation fault添加的。

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:79:9: error: no member named
      'strcoll' in the global namespace
using ::strcoll;
      ~~^

python2python3的路径根据自己python安装路径设置

编译

$ catkin build --limit-status-rate 1

编译是个非常漫长的过程,中间遇到很多的问题,如果遇到问题,提示不太明显,可以cd到相应的build目录。例如opencv3编译出错,则可以cd build/opencv3,然后make,查看更多信息。

3 出错及解决方法

3.1 opencv3

opencv3出的问题比较多,比如fatal error: 'QTKit/QTKit.h' file not found when I build OpenCV on mac,还有比较多的Undefined symbols for architecture x86_64错误。

QTKit错误因为MacOS中10.9版本开始取消了QTKit的支持,推荐使用AVFoundationopencv3.2.0的最新版本已经更新过了,但是通过rosinstall下载的代码还没有更新,因此为了方便,直接下载最新版的opencvopencv_contrib

不要直接删除src/opencv3目录,需要保留其中的.tarpackage.xml文件,其他文件删除后下载后覆盖原目录,其中opencv_contrib目录解压至opencv3目录下,由于opencv_contrib目录结构与rosinstall下载的有变化,因此修改src/opencv3/CMakeList.txt文件为

# ----------------------------------------------------------------------------
#  Path for additional modules
# ----------------------------------------------------------------------------
set(OPENCV_EXTRA_MODULES_PATH "${OpenCV_SOURCE_DIR}/opencv_contrib/modules" CACHE PATH "Where to look for additional OpenCV modules")

重新编译catkin build opencv3应该就可以了。运行效果如最上面的截图

3.2 Qt和PyQt版本

本文开始写的时候brewQt版本是5.8.0,PyQt5版本是5.7.1,因此在运行rqt这些程序的时候会报库版本不不兼容的警告

2017.2.19日发现PyQt5.8版本发布,但是brew中的版本依然是5.7.1,所以就准备手动安装。

brew安装pyqt5的Formula文件位于/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/pyqt5.rb,修改第四五行url为

url "https://downloads.sourceforge.net/project/pyqt/PyQt5/PyQt-5.8/PyQt5_gpl-5.8.tar.gz"
sha256 "9edf2816105a4111a447452df2bef7ce47d7efb307c75c3e74c27b8d31d7f66e"

第21行depends_on为depends_on "qt5",第44行qmake为"--qmake=#{Formula["qt5"].bin}/qmake",

由于PyQt5.8依赖sip 4.19.1,还需要将sip更新,更新后运行

brew install pyqt5 --with-python

即可。

3.3 rqt

rqt_bag模块运行时会报ImportError: No module named cairo错误,brew install py2cairo即可。

2017-2-26更新:
之前无法运行 rqt_image_view 模块,提示无法找到'libqt_gui_cpp_sip.so',今天发现ros-gbp网站很多模块有了更新,按照前面的更新包的方法更新qt_gui_corepython_qt_binding等包,重新编译发现已经没有问题了。

3.4 MoveIt!

MoveIt!包依赖fcl

brew install libccd
cd /Users/fitsir/Documents/ros-install-osx/kinetic_desktop_full_ws/src
git clone https://github.com/flexible-collision-library/fcl
cd fcl
git checkout fcl-0.5   # for kinetic
wget https://raw.githubusercontent.com/ros-gbp/fcl-release/debian/jade/fcl/package.xml

为保证fcl先于moveit_core编译,将fcl文件夹下的package.xml第二行的fcl改为libfcl-dev

moveit_setup_assistant包一直不能编译成功。

3.5 rviz

  • 在带有retina屏的苹果电脑中,由于高DPI,rviz只显示四分之一的区域,按照Correctly scale the render panel on high resolution displays修改即可。

  • 运行rviz时提示警告 “WARNING: rviz_sphere.mesh is an older format; you should upgrade it as soon”,进入/opt/ros/kinetic/share/rviz/ogre_media/models目录下分别对每个文件运行OgreMeshUpgrader命令

3.6 Astra

直接使用修改后的代码仓库fitsir/ros_astra_camera

参考文献

  1. ros.org
  2. Installation Instructions for Kinetic in OS X
  3. ros-install-osx
  4. Compiling ROS Kinetec from source fails when building image_proc
  5. fatal error: 'QTKit/QTKit.h' file not found when I build OpenCV on mac
  6. Building Common MoveIt! Dependencies from Source in Catkin
  7. Correctly scale the render panel on high resolution displays
  8. fitsir/ros_astra_camera

你可能感兴趣的:(在 Mac OS Sierra(10.12.3)中编译安装 ROS Kinetic)