LoginSignup
7
3

macOS で ROS 2をビルドする

Last updated at Posted at 2023-09-18

はじめに

dockerもvmも何も使いません。

テスト環境

  • M1 Max 64GB MacBook Pro
  • macOS 14.1.1 (23B81)

依存関係のインストール

  1. brew インストール

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  2. ここでbrewインストールの最後に言われたコマンドを実行する
    この手順はbrewのバージョンによって異なるので言われた通りに実行してください。

    # 例
    echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/hoge/.zprofile
    eval $(/opt/homebrew/bin/brew shellenv)
    
  3. brewを使って依存関係のインストール

    brew install \
        asio assimp bison bullet cmake console_bridge cppcheck \
        cunit eigen freetype graphviz opencv openssl orocos-kdl pcre poco \
        pyqt5 python qt@5 sip spdlog tinyxml tinyxml2 wget
    
  4. 不要なパッケージのアンインストール
    Python3.12が勝手にインストールされるので削除します

    brew uninstall --ignore-dependencies python@3.12
    
  5. pipを使って依存関係のインストール

    python3 -m pip install -U pip
    python3 -m pip install --global-option=build_ext \
           --global-option="-I$(brew --prefix graphviz)/include/" \
           --global-option="-L$(brew --prefix graphviz)/lib/" \
           pygraphviz
    python3 -m pip install -U \
          argcomplete catkin_pkg colcon-common-extensions coverage \
          cryptography empy flake8 flake8-blind-except==0.1.1 flake8-builtins \
          flake8-class-newline flake8-comprehensions flake8-deprecated \
          flake8-docstrings flake8-import-order flake8-quotes \
          importlib-metadata lark==1.1.1 lxml matplotlib mock mypy==0.931 netifaces \
          nose pep8 psutil pydocstyle pydot pygraphviz pyparsing==2.4.7 \
          pytest-mock rosdep rosdistro setuptools==59.6.0 vcstool
    

ビルド

  1. ソースの用意

    git clone https://github.com/TakanoTaiga/ros2_m1_native.git
    cd ros2_m1_native
    mkdir src
    vcs import src < ros2.repos
    
  2. ビルド

    colcon build --symlink-install --merge-install --cmake-args \
                -DBUILD_TESTING=OFF \
                -DTHIRDPARTY=FORCE \
                -DCMAKE_BUILD_TYPE=Release
    

.zshrcに書き込むもの

source ~/Documents/ros2_m1_native/install/setup.zsh
export ROS_VERSION=2
export ROS_PYTHON_VERSION=3
export ROS_DISTRO=humble

source ~/Documents/ros2_m1_native/install/setup.zshこれはDocument配下でgit cloneした場合の例。home配下だとsource ~/ros2_m1_native/以下略になる。

テスト

ターミナルを再起動して以下を実行。

# terminal 1
ros2 run demo_nodes_cpp talker
# terminal 2
ros2 run demo_nodes_py listener

最後に

トラブルがあればこちらにIssueを投げて頂ければと思います。

7
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
3