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

AWS RoboMaker は、新規顧客には利用できなくなりました。の既存のお客様 AWS RoboMaker は、通常どおりサービスを引き続き使用できます。 AWS Batch は、コンテナ化されたシミュレーションを実行するのに推奨されるサービスになりました。詳細はこちら

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

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

以下のチュートリアルでは、Hello World ロボットアプリケーションおよびシミュレーションアプリケーションを作成して実行することにより、コンテナイメージを使用して ROS 2 Foxy および Gazebo 11 で開発する方法について説明します。本書で説明されているコマンドを実行することで、サンプルアプリケーションを動作させることができます。

このチュートリアルでは、3 つのコンテナイメージを作成して使用します。次に、このサンプルアプリケーションで使用するディレクトリ構造を示します。

├── HelloWorldSampleAppROS2FoxyGazebo11 // Base Image │ └── Dockerfile ├── HelloWorldSampleAppROS2FoxyGazebo11RobotApp // Image for Robot App │ ├── Dockerfile │ └── robot-entrypoint.sh ├── HelloWorldSampleAppROS2FoxyGazebo11SimApp // Image for Simulation App │ ├── Dockerfile │ └── simulation-entrypoint.sh

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

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

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

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

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

ベースイメージの作成

ベースイメージを作成するには、Dockerfile に環境作成用コマンドを保存します。次に Dockerfile を作成します。

  • 次のコマンドを Dockerfile に保存します。

    # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 FROM ros:foxy ENV DEBIAN_FRONTEND noninteractive RUN apt-get clean RUN apt-get update && apt-get install -y \ lsb \ unzip \ wget \ curl \ sudo \ python3-vcstool \ python3-rosinstall \ python3-colcon-common-extensions \ ros-foxy-rviz2 \ ros-foxy-rqt \ ros-foxy-rqt-common-plugins \ devilspie \ xfce4-terminal RUN wget https://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -; \ sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list' RUN apt-get update && apt-get install -y gazebo11 ENV QT_X11_NO_MITSHM=1 ARG USERNAME=robomaker RUN groupadd $USERNAME RUN useradd -ms /bin/bash -g $USERNAME $USERNAME RUN sh -c 'echo "$USERNAME ALL=(root) NOPASSWD:ALL" >> /etc/sudoers' USER $USERNAME RUN sh -c 'cd /home/$USERNAME' # Download and build our Robot and Simulation application RUN sh -c 'mkdir -p /home/robomaker/workspace' RUN sh -c 'cd /home/robomaker/workspace && wget https://github.com/aws-robotics/aws-robomaker-sample-application-helloworld/archive/3527834.zip && unzip 3527834.zip && mv aws-robomaker-sample-application-helloworld-3527834771373beff0ed3630c13479567db4149e aws-robomaker-sample-application-helloworld-ros2' RUN sh -c 'cd /home/robomaker/workspace/aws-robomaker-sample-application-helloworld-ros2' RUN sudo rosdep fix-permissions RUN rosdep update

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

cd ../HelloWorldSampleAppROS2FoxyGazebo11 docker build -t helloworldsampleappros2foxygazebo11:latest .

ベースイメージをビルドすると ROS 2 Foxy と Gazebo 11 がインストールされます。アプリケーションを正常に実行するには、両方のライブラリをインストールする必要があります。

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

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

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 FROM helloworldsampleappros2foxygazebo11: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" ]

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

cd HelloWorldSampleAppROS2FoxyGazebo11RobotApp/HelloWorldSampleAppROS2FoxyGazebo11RobotApp docker build -t helloworldsampleappros2foxygazebo11robotapp:latest .

robot-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/robot_ws source /opt/ros/foxy/setup.bash source /usr/share/gazebo-11/setup.sh source ./install/setup.sh if [ ! -z $tmp_GAZEBO_MASTER_URI ]; then export GAZEBO_MASTER_URI=$tmp_GAZEBO_MASTER_URI unset tmp_GAZEBO_MASTER_URI fi printenv exec "${@:1}"

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

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

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 FROM helloworldsampleappros2foxygazebo11: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" ]

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

cd HelloWorldSampleAppROS2FoxyGazebo11SimApp/HelloWorldSampleAppROS2FoxyGazebo11SimApp docker build -t helloworldsampleappros2foxygazebo11simapp:latest .

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 source ./install/setup.sh if [ ! -z $tmp_GAZEBO_MASTER_URI ]; then export GAZEBO_MASTER_URI=$tmp_GAZEBO_MASTER_URI unset tmp_GAZEBO_MASTER_URI fi printenv exec "${@:1}"

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

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

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

docker run -it -e DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix/ --name robot_app \ -u robomaker -e ROBOMAKER_GAZEBO_MASTER_URI=http://localhost:5555 \ -e ROBOMAKER_ROS_MASTER_URI=http://localhost:11311 \ helloworldsampleappros2foxygazebo11robotapp:latest
docker run -it -e DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix/ --name sim_app \ -u robomaker -e ROBOMAKER_GAZEBO_MASTER_URI=http://localhost:5555 \ -e ROBOMAKER_ROS_MASTER_URI=http://localhost:11311 \ helloworldsampleappros2foxygazebo11simapp:latest

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

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

  2. 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 sim_app bash # Launch Gazebo from within the container $ /home/robomaker/simulation-entrypoint.sh ros2 launch gazebo_ros gzclient.launch.py

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

docker tag helloworldsampleappros2foxygazebo11robotapp:latest accountID.dkr.ecr.us-west-2.amazonaws.com/helloworldsampleappros2foxygazebo11robotapp:latest
docker tag helloworldsampleappros2foxygazebo11simapp:latest accountID.dkr.ecr.us-west-2.amazonaws.com/helloworldsampleappros2foxygazebo11simapp: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/helloworldsampleappros2foxygazebo11robotapp:latest docker push accountID.dkr.ecr.us-west-2.amazonaws.com/helloworldsampleappros2foxygazebo11simapp:latest

その後、イメージに対してシミュレーションジョブを実行できます。シミュレーションジョブの詳細については、「AWS RoboMaker によるシミュレーション」を参照してください。