サポート終了通知: 2025 年 9 月 10 日、 AWS は のサポートを中止します AWS RoboMaker。2025 年 9 月 10 日以降、 AWS RoboMaker コンソールまたは AWS RoboMaker リソースにアクセスできなくなります。コンテナ化されたシミュレーションの実行に役立つ AWS Batch への移行の詳細については、このブログ記事
翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
ROS Melodic と Gazebo 9 でサンプルアプリケーションを実行する
以下のチュートリアルでは、Hello World ロボットアプリケーションおよびシミュレーションアプリケーションを作成して実行することにより、コンテナイメージを使用して ROS および Gazebo 9 で開発する方法について説明します。本書で説明されているコマンドを実行することで、サンプルアプリケーションを動作させることができます。
このチュートリアルでは、3 つのコンテナイメージを作成して使用します。次に、このサンプルアプリケーションで使用するディレクトリ構造を示します。
├── HelloWorldSampleAppROSMelodicGazebo9 // Base Image │ └── Dockerfile ├── HelloWorldSampleAppROSMelodicGazebo9RobotApp // Image for Robot App │ ├── Dockerfile │ └── robot-entrypoint.sh ├── HelloWorldSampleAppROSMelodicGazebo9SimApp // 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:melodic ENV DEBIAN_FRONTEND noninteractive RUN apt-get clean RUN apt-get update && apt-get install -y \ lsb \ unzip \ wget \ curl \ sudo \ python-vcstool \ python-rosinstall \ python3-colcon-common-extensions \ ros-melodic-rviz \ ros-melodic-rqt \ ros-melodic-rqt-common-plugins \ devilspie \ xfce4-terminal \ ros-melodic-gazebo-ros-pkgs \ ros-melodic-gazebo-ros-control \ ros-melodic-turtlebot3 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/ros1.zip && unzip ros1.zip' RUN sh -c 'cd /home/robomaker/workspace/aws-robomaker-sample-application-helloworld-ros1' RUN sudo rosdep fix-permissions RUN rosdep update
-
Dockerfile を作成したら、ターミナルで以下のコマンドを使用してビルドします。
cd ../HelloWorldSampleAppROSMelodicGazebo9 docker build -t helloworldsampleapprosmelodicgazebo9:latest .
ベースイメージをビルドすると ROS Melodic と Gazebo 9 がインストールされます。アプリケーションを正常に実行するには、両方のライブラリをインストールする必要があります。
ロボットアプリケーション用イメージの作成
ベースイメージを作成したら、ロボットアプリケーションのイメージを作成できます。
-
以下のスクリプトを Dockerfile に保存してビルドします。このスクリプトにより、Hello World ロボットアプリケーションがダウンロードされて設定されます。
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 FROM helloworldsampleapprosmelodicgazebo9:latest # Build the Robot application RUN cd /home/robomaker/workspace/aws-robomaker-sample-application-helloworld-ros1/robot_ws && \ /bin/bash -c "source /opt/ros/melodic/setup.bash && vcs import < .rosinstall && rosdep install --rosdistro melodic --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 roslaunch hello_world_robot rotate.launch ENTRYPOINT [ "/home/robomaker/robot-entrypoint.sh" ]
-
以下のコマンドを使用して、Dockerfile からロボットアプリケーションのイメージが作成されます。
cd HelloWorldSampleAppROSMelodicGazebo9RobotApp/HelloWorldSampleAppROSMelodicGazebo9RobotApp docker build -t helloworldsampleapprosmelodicgazebo9robotapp:latest image/.
-
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-ros1/robot_ws source /opt/ros/melodic/setup.bash source /usr/share/gazebo-9/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 helloworldsampleapprosmelodicgazebo9:latest # Build the Simulation application RUN cd /home/robomaker/workspace/aws-robomaker-sample-application-helloworld-ros1/simulation_ws && \ /bin/bash -c "source /opt/ros/melodic/setup.bash && vcs import < .rosinstall && rosdep install --rosdistro melodic --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 roslaunch hello_world_simulation empty_world.launch 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-ros1/simulation_ws source /opt/ros/melodic/setup.bash source /usr/share/gazebo-9/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}"
アプリケーションを実行して ECR にプッシュする
イメージを作成したら、ローカルの Linux 環境で適切に動作していることを確認します。Docker イメージが実行されていることを確認した後、そのイメージを Amazon ECR にプッシュしてシミュレーションジョブを作成することができます。
-
次のコマンドを使用して、ローカル Linux 環境で Hello World アプリケーションを実行します。
docker run -it -e DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix/ \ -u robomaker -e ROBOMAKER_GAZEBO_MASTER_URI=http://localhost:5555 \ -e ROBOMAKER_ROS_MASTER_URI=http://localhost:11311 \ helloworldsampleapprosmelodicgazebo9robotapp:latest
docker run -it -e DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix/ \ -u robomaker -e ROBOMAKER_GAZEBO_MASTER_URI=http://localhost:5555 \ -e ROBOMAKER_ROS_MASTER_URI=http://localhost:11311 \ helloworldsampleapprosmelodicgazebo9simapp: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 sim_app bash # Launch Gazebo from within the container $ rosrun gazebo_ros gzclient
-
-
イメージにタグを追加して整理します。これらのイメージをタグするには、次のコマンドを使用します。
docker tag helloworldsampleapprosmelodicgazebo9robotapp:latest
accountID
.dkr.ecr.us-west-2.amazonaws.com/helloworldsampleapprosmelodicgazebo9robotapp:latestdocker tag helloworldsampleapprosmelodicgazebo9simapp:latest
accountID
.dkr.ecr.us-west-2.amazonaws.com/helloworldsampleapprosmelodicgazebo9simapp: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 pushaccountID
.dkr.ecr.us-west-2.amazonaws.com/helloworldsampleapprosmelodicgazebo9robotapp:latest docker pushaccountID
.dkr.ecr.us-west-2.amazonaws.com/helloworldsampleapprosmelodicgazebo9simapp:latest
その後、イメージに対してシミュレーションジョブを実行できます。シミュレーションジョブの詳細については、「AWS RoboMaker によるシミュレーション」を参照してください。