いつもはUbuntuだけど、macでもROS2にもインストールできるそうなんで、手持ちのMacbookAirにインストールしてみる。
公式ドキュメント
https://index.ros.org/doc/ros2/Installation/Dashing/OSX-Install-Binary/
まずはbrewで必要な物をインストール
brew install asio tinyxml2
brew install tinyxml eigen pcre poco
brew install opencv
brew install openssl
echo "export OPENSSL_ROOT_DIR=$(brew --prefix openssl)" >> ~/.bashrc
brew install qt freetype assimp
brew install log4cxx
brew install cunit
brew install pyqt5
ln -s /usr/local/share/sip/Qt5 /usr/local/share/sip/PyQt5
brew install graphviz
次にPythonのモジュールを入れる。
virtualEnvでROS2用に環境を作る。
mba:pyenv dp$ virtualenv ros@3.7.0
mba:pyenv dp$ source ros\@3.7.0/bin/activate
(ros@3.7.0) mba:pyenv dp$ pip install pygraphviz pydot lxml catkin_pkg empy lark-parser pyparsing pyyaml setuptools argcomplete
Macの場合、SIP(System Integrity Protection)の無効化をしないと親子プロセスで変数の継承ができないらしいので、OFFにしようと思ったら
$ csrutil status
System Integrity Protection status: disabled.
SIPがdisabledになってる。
Macのログイン画面の背景変更の時かな?
OFFだったので、スルーする。
ROS2のダウンロード
https://github.com/ros2/ros2/releases
mba:pyenv dp$ mkdir -p ~/ros2_crystal
mba:pyenv dp$ cd ~/ros2_crystal
mba:pyenv dp$ wget https://github.com/ros2/ros2/releases/download/release-dashing-20191018/ros2-dashing-20191018-macos-amd64.tar.bz2
mba:pyenv dp$ tar xf ros2-dashing-20191018-macos-amd64.tar.bz2
mba:pyenv dp$ . ~/ros2_crystal/ros2-osx/setup.bash
ROS2インストール完了したはずなので
デモを起動したら、エラー。。。
mba:pyenv dp$ ros2 run mba:pyenv dp$ demo_nodes_cpp talker
Failed to load entry point 'delete': dlopen(/Users/dp/ros2_crystal/ros2-osx/lib/python3.7/site-packages/rclpy/_rclpy.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/opt/tinyxml2/lib/libtinyxml2.7.dylib
Referenced from: /Users/dp/ros2_crystal/ros2-osx/lib/libbuiltin_interfaces__rosidl_typesupport_fastrtps_c.dylib
Reason: image not found
The C extension '/Users/dp/ros2_crystal/ros2-osx/lib/python3.7/site-packages/rclpy/_rclpy.cpython-37m-darwin.so' failed to be imported while being present on the system. Please refer to 'https://index.ros.org/doc/ros2/Troubleshooting/#import-failing-even-with-library-present-on-the-system' for possible solutions
Failed to load entry point 'info': dlopen(/Users/dp/ros2_crystal/ros2-osx/lib/python3.7/site-packages/rosbag2_transport/_rosbag2_transport_py.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/opt/poco/lib/libPocoFoundation.63.dylib
Referenced from: /Users/dp/ros2_crystal/ros2-osx/lib/python3.7/site-packages/rosbag2_transport/_rosbag2_transport_py.cpython-37m-darwin.so
Reason: image not found
The C extension '/Users/dp/ros2_crystal/ros2-osx/lib/python3.7/site-packages/rclpy/_rclpy.cpython-37m-darwin.so' failed to be imported while being present on the system. Please refer to 'https://index.ros.org/doc/ros2/Troubleshooting/#import-failing-even-with-library-present-on-the-system' for possible solutions
dyld: Library not loaded: /usr/local/opt/poco/lib/libPocoFoundation.63.dylib
Referenced from: /Users/dp/ros2_crystal/ros2-osx/lib/librosidl_typesupport_c.dylib
Reason: image not found
調べてみたらlibtinyxml2のバージョンに問題があるみたい。
Homebewでインストール済みのバージョンはtinyxml2(7.1.0)だけど7系は動かないとのこと
「ROS 2 fails to build against tinyxml2 7.0.0 #671」
https://github.com/ros2/ros2/issues/671
Homebewでインストール済みのtinyxml2をダウングレード
https://github.com/ros2/ros2/issues/625
brew unlink tinyxml2
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/da9a96f093a57eb8ac7c9470c1ec04fd1823a37a/Formula/tinyxml2.rb
brew switch tinyxml2 6.2.0
またdylibが見つからないのはlinkを作成
$ ll /usr/local/opt/poco/lib/libPocoFoundatio*
-rw-r--r-- 1 dp staff 1701096 12 19 23:12 /usr/local/opt/poco/lib/libPocoFoundation.64.dylib
lrwxr-xr-x 1 dp staff 26 9 18 17:03 /usr/local/opt/poco/lib/libPocoFoundation.dylib -> libPocoFoundation.64.dylib
ln -s libPocoFoundation.dylib libPocoFoundation.63.dylib
$ ll /usr/local/opt/tinyxml2/lib/libtinyxm*
lrwxr-xr-x 1 yuta staff 23 4 6 2018 /usr/local/opt/tinyxml2/lib/libtinyxml2.6.dylib -> libtinyxml2.6.2.0.dylib
lrwxr-xr-x 1 yuta staff 19 4 6 2018 /usr/local/opt/tinyxml2/lib/libtinyxml2.dylib -> libtinyxml2.6.dylib
$ cd /usr/local/opt/tinyxml2/lib/
$ ln -s libtinyxml2.6.2.0.dylib libtinyxml2.7.dylib
console_bridgeのインストールを忘れてた。
brew install console_bridge
これで対応できたと思ったけどpipモジュールが見つからないエラーが大量。。
(ros@3.7.0) mba:lib dp$ ros2 -help
Failed to load entry point 'test': No module named 'yaml'
Failed to load entry point 'launch': No module named 'yaml'
Failed to load entry point 'send_goal': No module named 'yaml'
Failed to load entry point 'list': No module named 'yaml'
Failed to load entry point 'load': No module named 'yaml'
Failed to load entry point 'standalone': No module named 'yaml'
これはpyenv使ってインストールした関係なので、パスを設定してからsetup.shを実行してOK
export PYTHONPATH=~/pyenv/ros\@3.7.0/lib/python3.7/site-packages/
$ which python
/Users/dp/pyenv/ros@3.7.0/bin/python
$. ~/ros/dashing/setup.bash
まだ自分マックはbashを使ってる。
間違えてsetup.shを実行したらエラーがでてしばらく悩んでしまった。
export PYTHONPATH=~/pyenv/ros\@3.7.0/lib/python3.7/site-packages/
$. ~/ros/dashing/setup.sh
The build time path "/Users/osrf/jenkins-agent/workspace/packaging_osx/ws/install" doesn't exist. Either source a script for a different shell or set the environment variable "COLCON_CURRENT_PREFIX" explicitly.