系统版本:MacOS 10.15.6(官方写的是支持 10.14)

ROS版本:Foxy

shell:zsh

Mac:MacBook Pro (13-inch, 2016, Four Thunderbolt 3 Ports)

安装方式基本与官方的安装方式一致:

https://index.ros.org/doc/ros2/Installation/Foxy/macOS-Install-Binary/

安装之前建议先将 brew 换用国内镜像源,当然即使更换了源也会出现少数地方比较慢需要科学上网的情况,比如 opencv 的安装。也可以不科学上网,仅仅只是慢,应该能下载成功。

安装必要依赖

  1. Python3.8:ROS2 Foxy 开始默认支持 Python 3.8
1
2
3
brew install python@3.8
brew unlink python
brew link --force python@3.8
  1. asiotinyxml2:Fast-RTPS 依赖,用来订阅发布消息的组件。以后会详细介绍 DDS
1
brew install asio tinyxml2
  1. tinyxmleigenpcrepoco:机器人状态发布者的依赖
1
brew install tinyxml eigen pcre poco
  1. opencv:非必须,但是视觉常常需要用到。安装它可能需要科学上网。如果没有会比较慢,耐心等待试试。
1
brew install opencv
  1. openssl:用来加密,zshrc 根据你的 shell 进行调整
1
2
brew install openssl
echo "export OPENSSL_ROOT_DIR=$(brew --prefix openssl)" >> ~/.zshrc
  1. Rviz的依赖
1
brew install qt freetype assimp
  1. rosbag2 需要的组件
1
brew install console_bridge
  1. rcl_logging_log4cxx 的依赖
1
brew install log4cxx spdlog
  1. Cyclone DDS 需要的组件
1
brew install cunit
  1. rqt 的依赖
1
2
3
4
5
6
7
brew install sip pyqt5
ln -s /usr/local/share/sip/Qt5 /usr/local/share/sip/PyQt5
brew install graphviz
python3 -m pip install pygraphviz pydot
# 安装 pygraphviz 可能会遇到问题:error: Error locating graphviz。尝试使用下面命令解决
# python3 -m pip install --install-option="--include-path=/usr/local/include/" --install-option="--library-path=/usr/local/lib/" pygraphviz

  1. SROS2的依赖
1
python3 -m pip install lxml
  1. 命令行工具的依赖
1
python3 -m pip install -U argcomplete catkin_pkg colcon-common-extensions coverage cryptography empy flake8 flake8-blind-except flake8-builtins flake8-class-newline flake8-comprehensions flake8-deprecated flake8-docstrings flake8-import-order flake8-quotes ifcfg lark-parser lxml mock mypy netifaces nose pep8 pydocstyle pydot pygraphviz pyparsing pytest-mock rosdep setuptools vcstool

禁用系统完整性保护(sip)

  1. 终端输入 csrutil status

如果显示的是 System Integrity Protection status: disabled. 则表示是禁用的,后面无需进行了。如果是 enabled 则继续往下进行。

  1. 重启电脑开机的同时按住 command + r 不要松手,直到出现白苹果
  2. 在实用工具中找到终端
  3. 输入命令:csrutil disable
  4. 如果得到结果为: Successfully disabled System Integrity Protection. Please restart the machine for the changes to take effect. 则说明禁用成功

安装 ROS 2

  1. 打开下载界面:https://github.com/ros2/ros2/releases

  2. 找到 ros2-foxy-xxx-macos-amd64.tar.bz2,我当前使用的下载链接为 ros2-foxy-20200807-macos-amd64.tar.bz2

  3. 下载后解压会有一个 ros2-osx 的文件夹,该文件就是 ros2 的源文件了

  4. 将其放在任何你想放在的文件夹内,官方将其放在了 ~/ros2_foxy 中。

使用简单的例子测试 ros2

  1. 加载环境
1
. ~/ros2_foxy/ros2-osx/setup.zsh
  1. 打开 talker
1
ros2 run demo_nodes_cpp talker
  1. 打开另一个终端,打开 listener(别忘了加载 ros 环境)
1
ros2 run demo_nodes_py listener

talker 打印如下

1
2
[INFO] [1598014476.967367729] [talker]: Publishing: "Hello World: 0"
[INFO] [1598014476.967367729] [talker]: Publishing: "Hello World: 1"

linstener 打印如下

1
2
[INFO] [1598014543.990184042] [listener]: I heard: [Hello World: 67]
[INFO] [1598014543.990184042] [listener]: I heard: [Hello World: 68]

安装后出现的问题

  1. . ~/ros2_foxy/ros2-osx/setup.zsh 之后出现如下内容:
1
[connext_cmake_module] Warning: The location at which Connext was found when the workspace was built [[/Applications/rti_connext_dds-5.3.1]] does not point to a valid directory, and the NDDSHOME environment variable has not been set. Support for Connext will not be available.

暂时将其忽略,没发现影响。

  1. 运行 rqt_graph
1
The 'tango_icons_vendor' package was not found - icons will not work

该报错导致 rqt 工具的图片都无法显示,解决办法暂时没有找到。

评论