使用 ROS 2 狡猾和涼亭 11 運行示例應用程序 - AWS RoboMaker

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 ROS 2 狡猾和涼亭 11 運行示例應用程序

下列教學課程將說明如何透過建立並執行 Hello World 機器人應用程式和模擬應用程式,使用 ROS 2 Foxy 和 Gazebo 11 進行開發。您可以執行本文件中描述的指令,讓範例應用程式正常運作。

在本教學課程中,我們會建立並使用三個容器映像檔。以下顯示了我們用於此示例應用程序的目錄結構。

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

每個碼頭文件都有構建每個圖像所需的說明;

  • 對於基本圖像的碼頭文件具有設置 ROS 和涼亭的命令。

  • 自動機制應用程式的 Docker 檔案具有設定 Hello World 自動機制應用程式的指令。

  • 模擬應用程式的 Docker 檔案具有用於設置 Hello World 模擬應用程式的指令。

機器人應用程式和模擬應用程式都有入口點指令碼。這些腳本為其各自的應用程序提供環境。它們為您設定了執行指令以啟動機器人和模擬應用程式的路徑。

建立基本映像

若要建立基本影像,請儲存指令以在 Docker 檔案中建立環境。然後,您構建碼頭文件。

  • 將以下命令保存在碼頭文件中。

    # 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

創建 Docker 文件後,使用終端上的以下命令構建它。

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

構建基本映像安裝 ROS 2 狡猾的和涼亭 11. 您需要安裝兩個程式庫才能成功執行應用程式。

為自動機制應用程式建立影像

建立基本映像後,您可以為機器人應用程式建立映像。您可以將以下腳本保存在 Docker 文件中並構建它。此指令碼會下載 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" ]

下列指令會從 Docker 檔案建立自動機制應用程式的影像。

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}"

建立模擬應用程式的影像

建立自動機械手應用程式的基本影像和影像後,您可以為模擬應用程式建立影像。您可以將以下腳本保存在 Docker 文件中並構建它。此指令碼會下載 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}"

執行應用程式並將其推送至亞馬遜 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. 通過運行涼亭圖形用戶界面(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