ROS2 Foxy と Gazebo 11 を使用した GPU サンプルアプリケーションの実行 - AWS RoboMaker

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

ROS2 Foxy と Gazebo 11 を使用した GPU サンプルアプリケーションの実行

このチュートリアルでは、以下の例に概要が示されている 3 つのコンテナイメージを使用して Hello World のロボットアプリケーションとシミュレーションアプリケーションを作成し、実行することにより、コンテナイメージ内で GPU ドライバーを使用して ROS 2 Foxy と Gazebo 11 で開発する方法について説明します。

├── SampleGPUBaseApp // Base Image │ └── Dockerfile ├── SampleGPURobotApp // Image for Robot App │ ├── Dockerfile │ └── robot-entrypoint.sh ├── SampleGPUSimulationApp // Image for Simulation App │ ├── Dockerfile │ └── simulation-entrypoint.sh

各 Dockerfile には、各イメージのビルドに必要な指示があります。

  • ベースイメージの Dockerfile には、ROS、Gazebo、GPU ドライバーを設定するためのコマンドがあります。

  • ロボットアプリケーションの Dockerfile には、Hello World ロボットアプリケーションを設定するためのコマンドがあります。

  • シミュレーションアプリケーションの Dockerfile には、Hello World シミュレーションアプリケーションを設定するためのコマンドがあります。

ロボットアプリケーションとシミュレーションアプリケーションの両方に、エントリポイントスクリプトがあります。これらのスクリプトは、それぞれのアプリケーションの環境をソースにして、コマンドを実行してロボットアプリケーションとシミュレーションアプリケーションを起動するためのパスを設定します。

ベース GPU イメージの作成

次の Dockerfile には、NVIDIA OpenGL からベースイメージを作成して DCV をインストールするためのコマンドが含まれています。

  • 以下のコマンドを SampleGPUBaseApp ディレクトリの Dockerfile に保存します。

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 FROM nvidia/opengl:1.0-glvnd-runtime-ubuntu20.04 ENV DEBIAN_FRONTEND="noninteractive" ENV QT_X11_NO_MITSHM=1 RUN apt-get clean RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates \ devilspie \ gnupg2 \ mesa-utils \ sudo \ unzip \ wget \ xfce4-terminal RUN wget https://d1uj6qtbmh3dt5.cloudfront.net/NICE-GPG-KEY && gpg --import NICE-GPG-KEY && \ wget https://d1uj6qtbmh3dt5.cloudfront.net/2021.2/Servers/nice-dcv-2021.2-11048-ubuntu1804-x86_64.tgz && \ tar xvzf nice-dcv-2021.2-11048-ubuntu1804-x86_64.tgz && \ cd nice-dcv-2021.2-11048-ubuntu1804-x86_64 && \ apt install -y ./nice-dcv-gl_2021.2.944-1_amd64.ubuntu1804.deb RUN apt update && apt -y install locales && \ locale-gen en_US en_US.UTF-8 && \ update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 ENV LANG=en_US.UTF-8 RUN apt-get update && apt-get install -y --no-install-recommends curl lsb-release RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg && \ curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add - && \ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null && \ apt update && \ apt install -y ros-foxy-desktop && \ /bin/bash -c "source /opt/ros/foxy/setup.bash" RUN apt -y install ros-foxy-gazebo-ros-pkgs RUN apt-key adv --fetch-keys 'http://packages.osrfoundation.org/gazebo.key' && \ apt update && \ apt install -y python3-rosdep git RUN if [ ! -f "/etc/ros/rosdep/sources.list.d/20-default.list" ]; then \ rosdep init; \ fi RUN rosdep update RUN apt-get install -y python3-apt python3-pip python3-vcstool python3-testresources RUN pip3 install -U pytest setuptools colcon-ros-bundle RUN useradd --create-home robomaker && \ sh -c 'echo "robomaker ALL=(root) NOPASSWD:ALL" >> /etc/sudoers' RUN sh -c 'mkdir -p /home/robomaker/workspace' && \ sh -c 'cd /home/robomaker/workspace && wget https://github.com/aws-robotics/aws-robomaker-sample-application-helloworld/archive/ros2.zip && unzip ros2.zip'

Dockerfile を作成したら、ターミナルで以下のコマンドを使用してビルドします。

cd SampleGPUBaseApp docker build -t samplegpubaseapp:latest .

ベースイメージをビルドすると ROS 2 Foxy、Gazebo 11、NVIDIA OpenGL、NICE-DCV がインストールされます。

ロボットアプリケーション用イメージの作成

ベースイメージを作成したら、ロボットアプリケーションのイメージを作成できます。以下のスクリプトを SampleGPURobotApp ディレクトリの Dockerfile に保存してビルドします。このスクリプトにより、Hello World ロボットアプリケーションがダウンロードされて設定されます。

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 FROM samplegpubaseapp:latest # Build the Robot application RUN cd /home/robomaker/workspace/aws-robomaker-sample-application-helloworld-ros2/robot_ws && \ /bin/bash -c "source /opt/ros/foxy/setup.bash && vcs import < .rosinstall && rosdep install --rosdistro foxy --from-paths src --ignore-src -r -y && colcon build" COPY robot-entrypoint.sh /home/robomaker/robot-entrypoint.sh RUN sh -c 'sudo chmod +x /home/robomaker/robot-entrypoint.sh' RUN sh -c 'sudo chown robomaker:robomaker /home/robomaker/robot-entrypoint.sh' CMD ros2 launch hello_world_robot rotate.launch.py ENTRYPOINT [ "/home/robomaker/robot-entrypoint.sh" ]

robot-entrypoint.sh として保存できるスクリプトの内容を以下に示します。このスクリプトはロボットアプリケーションの環境をソースにします。

#!/bin/bash cd /home/robomaker/workspace/aws-robomaker-sample-application-helloworld-ros2/robot_ws source /opt/ros/foxy/setup.bash source /usr/share/gazebo-11/setup.sh source ./install/setup.sh printenv exec "${@:1}"

以下のコマンドにより、Dockerfile からロボットアプリケーションのイメージが作成されます。

cd SampleGPURobotApp docker build -t samplegpurobotapp:latest .

シミュレーションアプリケーション用イメージの作成

シミュレーションアプリケーション用イメージの作成

ベースイメージとロボットアプリケーション用イメージを作成すれば、シミュレーションアプリケーションのイメージを作成できます。以下のスクリプトを SampleGPUSimulationApp ディレクトリの Dockerfile に保存してビルドします。このスクリプトにより、Hello World シミュレーションアプリケーションがダウンロードされて設定されます。

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 FROM samplegpubaseapp:latest # Build the Simulation application RUN cd /home/robomaker/workspace/aws-robomaker-sample-application-helloworld-ros2/simulation_ws && \ /bin/bash -c "source /opt/ros/foxy/setup.bash && vcs import < .rosinstall && rosdep install --rosdistro foxy --from-paths src --ignore-src -r -y && colcon build" COPY simulation-entrypoint.sh /home/robomaker/simulation-entrypoint.sh RUN sh -c 'sudo chmod +x /home/robomaker/simulation-entrypoint.sh' RUN sh -c 'sudo chown robomaker:robomaker /home/robomaker/simulation-entrypoint.sh' CMD ros2 launch hello_world_simulation empty_world.launch.py ENTRYPOINT [ "/home/robomaker/simulation-entrypoint.sh" ]

simulation-entrypoint.sh として保存できるスクリプトの内容を以下に示します。このスクリプトはシミュレーションアプリケーションの環境をソースにします。

#!/bin/bash if [ ! -z $GAZEBO_MASTER_URI ]; then tmp_GAZEBO_MASTER_URI=$GAZEBO_MASTER_URI fi cd /home/robomaker/workspace/aws-robomaker-sample-application-helloworld-ros2/simulation_ws source /opt/ros/foxy/setup.bash source /usr/share/gazebo-11/setup.sh if [ ! -z $tmp_GAZEBO_MASTER_URI ]; then export GAZEBO_MASTER_URI=$tmp_GAZEBO_MASTER_URI unset tmp_GAZEBO_MASTER_URI fi source ./install/setup.sh printenv exec "${@:1}"

以下のコマンドを実行してイメージを作成します。

cd SampleGPUSimulationApp docker build -t samplegpusimulationapp:latest .

アプリケーションを実行して Amazon ECR にプッシュする

イメージを作成したら、ローカルの Linux 環境で適切に動作していることを確認します。イメージが実行されていることを確認した後、Docker イメージを Amazon ECR にプッシュしてシミュレーションジョブを作成できます。

次のコマンドを使用すると、ローカル Linux 環境で Hello World アプリケーションを実行できます。

docker run -it -e DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix/ --name gpu_robot_app \ -u robomaker -e ROBOMAKER_GAZEBO_MASTER_URI=http://localhost:5555 \ -e ROBOMAKER_ROS_MASTER_URI=http://localhost:11311 \ samplegpurobotapp:latest docker run -it -e DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix/ --name gpu_sim_app \ -u robomaker -e ROBOMAKER_GAZEBO_MASTER_URI=http://localhost:5555 \ -e ROBOMAKER_ROS_MASTER_URI=http://localhost:11311 \ samplegpusimulationapp:latest

ロボットアプリケーションコンテナとシミュレーションアプリケーションコンテナを実行すると、Gazebo GUI ツールを使用してシミュレーションを視覚化できます。以下のコマンドを使用して次の作業を行います。

  • シミュレーションアプリケーションを実行しているコンテナに接続します。

  • Gazebo グラフィカルユーザーインターフェイス (GUI) を実行することでアプリケーションを視覚化します。

# Enable access to X server to launch Gazebo from docker container $ xhost + # Check that the robot_app and sim_app containers are running. The command should list both containers $ docker container ls # Connect to the sim app container $ docker exec -it gpu_sim_app bash # Launch Gazebo from within the container $ /home/robomaker/simulation-entrypoint.sh ros2 launch gazebo_ros gzclient.launch.py

イメージにタグを追加できます。以下のコマンドによりイメージにタグを付けることができます。

docker tag samplegpurobotapp:latest accountID.dkr.ecr.us-west-2.amazonaws.com/samplegpurobotapp:latest docker tag samplegpusimulationapp:latest accountID.dkr.ecr.us-west-2.amazonaws.com/samplegpusimulationapp:latest

アプリケーションが正常に動作していることを確認したら、以下のコマンドを使用して Amazon ECR にプッシュできます。

aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin accountID.dkr.ecr.us-west-2.amazonaws.com docker push accountID.dkr.ecr.us-west-2.amazonaws.com/samplegpurobotapp:latest docker push accountID.dkr.ecr.us-west-2.amazonaws.com/samplegpusimulationapp:latest

これで、これらのイメージを使用して GPU コンピューティングでシミュレーションジョブを実行できるようになりました。シミュレーションジョブの詳細については、「AWS RoboMaker によるシミュレーション」を参照してください。