Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROS 2 Humble環境構築 #1

Open
rensanrenren opened this issue Nov 29, 2024 · 1 comment
Open

ROS 2 Humble環境構築 #1

rensanrenren opened this issue Nov 29, 2024 · 1 comment

Comments

@rensanrenren
Copy link
Contributor

rensanrenren commented Nov 29, 2024

Ubuntu 22.04 をベースに、上記の要件(ROS 2 Humble、Python 3.10 以上、Git、Colcon)を満たす Docker 環境を構築するための詳細手順を示します。


Dockerfile 作成

以下の Dockerfile を作成します。このファイルは、Ubuntu 22.04 ベースで必要なツールやパッケージをインストールし、ROS 2 Humble デスクトップ環境をセットアップします。

# ベースイメージとして Ubuntu 22.04 を使用
FROM ubuntu:22.04

# 非対話モードを設定
ENV DEBIAN_FRONTEND=noninteractive

# 必要なパッケージをインストール
RUN apt-get update && apt-get install -y \
    curl \
    gnupg \
    lsb-release \
    locales \
    git \
    python3-pip \
    build-essential \
    software-properties-common \
    tzdata \
    && apt-get clean

# ロケール設定
RUN locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8

# タイムゾーン設定
RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime && dpkg-reconfigure --frontend noninteractive tzdata

# ROS 2 Humble のインストール
RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add - && \
    sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list' && \
    apt-get update && apt-get install -y \
    ros-humble-desktop \
    python3-rosdep \
    && rm -rf /var/lib/apt/lists/*

# rosdep の初期化と更新
RUN rosdep init && rosdep update

# ROS 環境変数の設定
RUN echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc

# Python 3.10 確認とパッケージアップグレード
RUN apt-get update && apt-get install -y python3.10 && \
    pip3 install --upgrade pip

# Colcon のインストール
RUN pip3 install colcon-common-extensions

# ROS 2 ワークスペースの準備
WORKDIR /workspace
RUN mkdir -p /workspace/src

# デフォルトのエントリポイント
CMD ["bash"]

環境構築手順

1. Docker イメージのビルド

Dockerfile を作成したディレクトリで以下のコマンドを実行して Docker イメージをビルドします:

docker build -t ros2-humble .

2. コンテナの起動

ビルドしたイメージを元にコンテナを起動します:

docker run -it --rm \
    --net=host \
    -v $(pwd)/workspace:/workspace \
    ros2-humble
  • --net=host は、ネットワーク設定をホストと共有するために必要です。
  • -v $(pwd)/workspace:/workspace は、ホストとコンテナ間でワークスペースを共有します。

3. ROS 2 環境の確認

コンテナ内で以下のコマンドを実行して、ROS 2 が正しくインストールされていることを確認します:

source /opt/ros/humble/setup.bash
ros2 pkg prefix ros2cli

4. Colcon のビルド

プロジェクトを /workspace/src に配置し、以下のコマンドでビルドします:

source /opt/ros/humble/setup.bash
cd /workspace
colcon build

5. Python バージョン確認

Python 3.10 がインストールされていることを確認します:

python3 --version

6. リポジトリのクローン

リポジトリを src ディレクトリにクローンして依存関係を解決します:

cd /workspace/src
git clone https://github.com/space-station-os/space-station-os.github.io.git
cd ..
rosdep install --from-paths src --ignore-src -r -y

7. ノードの実行

ビルド後、ノードを以下のように実行します:

source install/setup.bash
ros2 launch [your_launch_file.launch]

これで、Docker 環境で要件を満たした ROS 2 Humble 環境が整います。問題があれば気軽に質問してください!

@rensanrenren
Copy link
Contributor Author

source /opt/ros/humble/setup.bash コマンドは、ROS 2 Humble の環境を現在のシェルセッションにロードするために使用されます。このコマンドを実行することで、ROS 2 を使う準備が整います。


期待される結果

  1. 環境変数の設定

    • ROS 2 に必要な環境変数が設定されます。
    • 以下の変数が有効になります:
      • ROS_DISTRO: 現在のROSディストリビューション名(例: humble)。
      • AMENT_PREFIX_PATH: ROSパッケージの検索パス。
      • COLCON_PREFIX_PATH: colcon ワークスペースのパス。
      • PATH: ROS 2 のバイナリ(ros2 コマンド)が含まれるディレクトリが追加されます。
  2. ROS 2 CLI コマンドが有効になる

    • ros2 コマンドがシェルで認識されるようになります。
      ros2 --help
      このコマンドで、ROS 2 のCLIツールの使用可能なサブコマンドが一覧表示されます。
  3. ROS 2 パッケージが利用可能になる

    • ROS 2 のワークスペース内で、ビルドされたパッケージやノードが利用できるようになります。
    • 例えば、ros2 runros2 launch を使用してノードやランチファイルを起動できます。

何も表示されない場合が正常

コマンド実行後、特にメッセージが表示されないのが通常です。何もエラーが表示されなければ、環境変数が正常に設定されたと考えられます。


確認方法

source /opt/ros/humble/setup.bash の効果を確認するには、以下を試してください:

  1. ROS 環境変数の確認

    echo $ROS_DISTRO

    出力例:

    humble
    
  2. ros2 コマンドの確認

    ros2 --help

    出力例:

    usage: ros2 [-h] Call `ros2 <command> -h` for more detailed usage.
    
  3. ROS パッケージの検索

    ros2 pkg list

    インストール済みのパッケージ一覧が表示されます。


エラーが発生する場合

source /opt/ros/humble/setup.bash 実行後にエラーが表示される場合、以下を確認してください:

  1. /opt/ros/humble/ が存在するか確認。
    ls /opt/ros/humble
  2. ROS 2 が正しくインストールされているか確認。

問題があれば詳細を教えていただければサポートします!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant