0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

macOS上でpixiを使いROS2環境を構築して外部PCと通信する方法

0
Posted at

概要

macOS 上で pixi を使用して ROS2 Humble 環境を構築し,cyclonedds を導入することで,同一ネットワーク上のロボットや外部 PC とトピック通信を行うための手順をまとめます.

実施条件

このドキュメントは以下の環境で行われました.

OS macOS 26.2
ターミナル bash
CPU Intel (osx-64)
ROS2 バージョン Humble

上記の通り,この検証は Intel アーキテクチャの MacBook Pro で行われました.ぜひ Apple Silicon でも同様に動作するか検証していただき,フォードバックを連絡していただけると助かります. (Apple Silicon Mac を持っていないので...)

pixi をインストールする 1

このセクションでは,パッケージマネージャーである pixi をインストールする方法を解説します.

  1. 以下のコマンドを実行して pixi をインストールする.

    curl -fsSL https://pixi.sh/install.sh | sh
    
  2. ターミナルを再起動するか,以下のコマンドを実行して設定を反映させる.

    source ~/.bashrc
    

    使用しているシェルに合わせて ~/.zshrc など適宜読み替えてください.

  3. 以下のコマンドを実行して pixi のインストールを確認する.

    pixi -V
    

ワークスペースの作成と ROS2 のインストール 2

ROS2 用のワークスペースを作成し,必要なパッケージをインストールします.

  1. ワークスペースディレクトリを作成する.

    pixi init ros2_ws
    
  2. ワークスペースディレクトリに移動する.

    cd ros2_ws
    
  3. pixi.toml を編集し,チャンネルに robostack-humble を追加する.

    pixi.toml
    [workspace]
    channels = ["conda-forge", "robostack-humble"]
    platforms = ["osx-64"]
    ...
    
  4. 以下のコマンドを実行して ros-humble-desktop を追加する.

    pixi add ros-humble-desktop
    

動作確認 (turtlesim)

インストールされた ROS2 が正しく動作するか確認します.

  1. 以下のコマンドを実行して turtlesim を起動する.

    pixi run ros2 run turtlesim turtlesim_node
    

    初回起動には時間がかかることがあります.

  2. 別のターミナルから以下のコマンドを実行し,トピック通信ができるか確認する.

    pixi run ros2 topic pub --once /turtle1/cmd_vel geometry_msgs/msg/Twist "linear: {x: 1.0}"
    

Cyclone DDS による外部通信設定

外部のロボットや PC と通信するために cyclonedds を導入し,環境変数を設定します.

  1. ワークスペースに Cyclone DDS を追加する.

    pixi add ros-humble-rmw-cyclonedds-cpp
    
  2. pixi.toml[activation.env] セクションに環境変数を追加する.
    RMW_IMPLEMENTATIONrmw_cyclonedds_cpp を指定します.

    pixi.toml
    [activation.env]
    RMW_IMPLEMENTATION="rmw_cyclonedds_cpp"
    ROS_DOMAIN_ID="0"
    ROS_LOCALHOST_ONLY="0"
    
  3. 以下のコマンドを実行して環境変数が反映されているか確認する.

    pixi run env | grep RMW_
    

Cyclone DDS の詳細設定と外部通信の安定化

同一ネットワーク上のロボットや外部 PC とのトピック通信を安定させるために,cyclonedds.xml を使用した詳細設定を行います.

  1. Mac のネットワークインターフェース(NIC)を確認する.
    以下のコマンドを実行し,現在使用している NIC の名称(例: en0)を確認します.

    ifconfig
    
  2. ワークスペースに cyclonedds.xml を作成する.
    <NetworkInterface name="NIC">NIC 部分を確認した NIC 名に書き換えます.また,<Peer address="..."/> に接続先の IP アドレス(ロボットやルーター)を指定します.

    cyclonedds.xml
    <?xml version="1.0" encoding="UTF-8" ?>
    <CycloneDDS xmlns="https://cdds.io/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://cdds.io/config https://raw.githubusercontent.com/eclipse-cyclonedds/cyclonedds/master/etc/cyclonedds.xsd">
        <Domain id="any">
            <General>
                <Interfaces>
                    <NetworkInterface name="NIC" priority="default" multicast="true" />
                </Interfaces>
                <AllowMulticast>true</AllowMulticast>
                <DontRoute>true</DontRoute>
            </General>
            <Discovery>
                <Peers>
                    <Peer address="ルーターIPアドレスまたはロボットのIPアドレス"/>
                </Peers>
                <ParticipantIndex>auto</ParticipantIndex>
                <MaxAutoParticipantIndex>500</MaxAutoParticipantIndex>
            </Discovery>
        </Domain>
    </CycloneDDS>
    
  3. 外部からのトピックが観測できるか確認する.

    pixi run ros2 topic list
    

RViz2 の導入と起動

可視化ツールである rviz2 を導入します.

  1. RViz2 パッケージを追加する.

    pixi add ros-humble-rviz2
    
  2. RViz2 を起動する.

    pixi run rviz2
    

    トピックが観測できるならば,以下のように RViz で可視化できます.

トラブルシューティング:外部通信ができない場合

詳細設定を行っても外部 PC やロボットからのトピックが観測できない場合,macOS の ファイアウォール が通信を遮断している可能性があります.

  1. ファイアウォールの状態を確認・無効化する.
    「システム設定」>「ネットワーク」>「ファイアウォール」から,一時的にファイアウォールをオフにして通信が改善するか確認してください.

    ファイアウォールを無効にする間は,信頼できるネットワーク内での作業に限定し,作業完了後は速やかに有効に戻すことを推奨します.

参考元

  1. pixi 公式ドキュメント

  2. pixi install ROS2

0
1
1

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?