SBC & MCU/Jetson

[Jetson][Docker] ROS Container for Jetson and Jetpack

jstar0525 2021. 9. 28. 17:19
반응형

0. 개요


이전 글에서 jetson의 docker image에 대한 글을 남겼습니다.

이번 글에서는 ROS와 관련한 Jetson의 docker image에 대해 사용하는 방법을 정리해보고자 합니다.

 

 

 

1. 환경


실험 환경은 아래와 같습니다.

 

Jetson AGX Xavier

Jetpack 4.5 (Ubuntu 18.04)

 

위 환경에서는 docker가 기본적으로 설치되어있고,

따라서 아래의 명령들을 따라하시면 됩니다.

 

 

 

2. Docker images 설명


The following ROS containers are also provided, which can be pulled from DockerHub or built for JetPack 4.4 or newer:

  • ROS Melodic (ros:melodic-ros-base-l4t-r32.5.0)
  • ROS Noetic (ros:noetic-ros-base-l4t-r32.5.0)
  • ROS2 Eloquent (ros:eloquent-ros-base-l4t-r32.5.0)
  • ROS2 Foxy (ros:foxy-ros-base-l4t-r32.5.0)
  • ROS2 Galactic (ros:galactic-ros-base-l4t-r32.5.0)

 

 

Note that Noetic, Foxy, and Galactic are built from source for Ubuntu 18.04,
while Melodic and Eloquent are installed from Debian packages into the containers.

 

 

 

3. Docker Default Runtime


To enable access to the CUDA compiler (nvcc) during docker build operations, add "default-runtime": "nvidia" to your /etc/docker/daemon.json configuration file before attempting to build the containers:

$ sudo gedit /etc/docker/daemon.json
{
    "runtimes": {
        "nvidia": {
            "path": "nvidia-container-runtime",
            "runtimeArgs": []
        }
    },

    "default-runtime": "nvidia"
}

You will then want to restart the Docker service or reboot your system before proceeding.

 

 

 

4. Building the Containers


To rebuild the containers from a Jetson device running JetPack 4.4 or newer, first clone this repo:

$ git clone https://github.com/dusty-nv/jetson-containers
$ cd jetson-containers

Before proceeding, make sure you have set your Docker Default Runtime to nvidia as shown above.

 

 

Build ROS Containers

 

To build the ROS containers, use scripts/docker_build_ros.sh with the --distro option to specify the name of the ROS distro to build:

$ ./scripts/docker_build_ros.sh --distro all       # build all of the below (default)
$ ./scripts/docker_build_ros.sh --distro melodic   # build only melodic
$ ./scripts/docker_build_ros.sh --distro noetic    # build only noetic
$ ./scripts/docker_build_ros.sh --distro eloquent  # build only eloquent
$ ./scripts/docker_build_ros.sh --distro foxy      # build only foxy
$ ./scripts/docker_build_ros.sh --distro galactic  # build only galactic

You can also specify --with-pytorch and --with-slam to build variants with support for PyTorch and GPU-accelerated SLAM nodes (including ORBSLAM2 and RTABMAP).

 

 

 

5. Run the Container for melodic


1) build the ros image

$ ./scripts/docker_build_ros.sh --distro melodic --package desktop
usage: Builds various ROS Docker containers for Jetson / JetPack-L4T
    
   ./scripts/docker_build_ros.sh --distro DISTRO"
                                 --package PACKAGE"
                                 --with-pytorch"
                                 --with-slam"
   
   --distro DISTRO Specifies the ROS distro to build, one of:"
                   'melodic', 'noetic', 'eloquent', 'foxy', 'galactic'"
                   Or the default of 'all' will build all distros."

   --package PKG   Specifies the ROS meta-package to install, one of:"
                   'ros_base', 'ros_core', 'desktop', 'all'"
                    The default is 'ros_base'.  Note that 'desktop' may"
                   have issues on some distros that are built from source."
   
   --with-pytorch  Builds additional container with PyTorch support."
                   This only applies to noetic, foxy, and galactic."
  
   --with-slam     Builds additional container with VSLAM packages,"
                   including ORBSLAM2, RTABMAP, ZED, and Realsense."
                   This only applies to foxy and galactic and implies"
                   --with-pytorch as these containers use PyTorch."

 

2) check docker images

$ sudo docker images
REPOSITORY                TAG                            IMAGE ID       CREATED          SIZE
ros                       melodic-desktop-l4t-r32.5.1    85cf38c78721   40 seconds ago   2.15GB

 

3) docker run

$ ./scripts/docker_run.sh -c ros:melodic-desktop-l4t-r32.5.1
localuser:root being added to access control list
sourcing   /opt/ros/melodic/setup.bash
ROS_ROOT   /opt/ros/melodic/share/ros
ROS_DISTRO melodic
root@user:/#
root@user:/# ls
bin  boot  dev  dst  etc  home  lib  media  mnt  opt  proc  root  ros_entrypoint.sh  run  sbin  srv  sys  tmp  usr  var  workspace
usage: Starts the Docker container and runs a user-specified command
  
   ./scripts/docker_run.sh --container DOCKER_IMAGE"
                           --volume HOST_DIR:MOUNT_DIR"
                           --run RUN_COMMAND"

   -c, --container DOCKER_IMAGE Specifies the name of the Docker container"
                                image to use (default: 'nvidia-l4t-base')"
   
   -v, --volume HOST_DIR:MOUNT_DIR Mount a path from the host system into"
                                   the container.  Should be specified as:"
   
                                      -v /my/host/path:/my/container/path"
  
   -r, --run RUN_COMMAND  Command to run once the container is started."
                          Note that this argument must be invoked last,"
                          as all further arguments will form the command."
                          If no run command is specified, an interactive"
                          terminal into the container will be provided."

 

4) check docker container

$ sudo docker ps -a
CONTAINER ID   IMAGE                             COMMAND                  CREATED          STATUS          PORTS     NAMES
ec5b03d77bbf   ros:melodic-desktop-l4t-r32.5.1   "/ros_entrypoint.sh …"   44 seconds ago   Up 43 seconds             boring_keldysh

 

5) 아래의 명령을 통해서 해당 container에 접속할 수 있습니다.

$ sudo docker exec -it ec5b /bin/bash
root@user:/#

 

6) Check GUI tool

 

X server를 이용하여 아래와 같은 GUI 도구들을 사용할 수 있다.

[새로운 터미널 접속은 5)번 명령어 참조]

# 1st terminal

$ roscore
# 2nd terminal

$ rosrun turtlesim turtlesim_node

# 3rd terminal

$ rqt

# 4th terminal

$ rviz

# 5th terminal

$ apt-get update
$ apt-get install ros-melodic-gazebo-ros-pkgs \
                  ros-melodic-gazebo-ros-control \
                  ros-melodic-joint-state-controller \
                  ros-melodic-effort-controllers \
                  ros-melodic-position-controllers \
                  ros-melodic-joint-trajectory-controller
$ gazebo

반응형