기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
ROS 2, Foxy, Gazebo 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
각 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 환경에서 이미지가 제대로 실행되는지 확인하세요. 이미지가 실행되는지 확인한 후, 도커 이미지를 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 도구를 사용하여 시뮬레이션을 시각화할 수 있습니다. 다음 명령을 사용하십시오.
-
시뮬레이션 애플리케이션을 실행하는 컨테이너에 연결합니다.
-
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 pushaccountID
.dkr.ecr.us-west-2.amazonaws.com/helloworldsampleappros2foxygazebo11robotapp:latest docker pushaccountID
.dkr.ecr.us-west-2.amazonaws.com/helloworldsampleappros2foxygazebo11simapp:latest
그런 다음 이미지에서 시뮬레이션 작업을 실행할 수 있습니다. 시뮬레이션 작업에 대한 자세한 내용은 AWS RoboMaker를 이용한 시뮬레이션 섹션을 참조하십시오.