From eb57b1a12a9313e03593fb3f06a2999945200bdf Mon Sep 17 00:00:00 2001 From: stampede Date: Thu, 10 Oct 2024 00:13:49 -0500 Subject: [PATCH 1/8] fixing merge --- docker/Dockerfile | 25 ++- docker/scripts/build-librealsense.sh | 188 ++++++++++++++++++ docker/scripts/hotplug-realsense.sh | 79 ++++++++ .../scripts/install-realsense-dependencies.sh | 24 +++ .../99-realsense-libusb-custom.rules | 11 + 5 files changed, 324 insertions(+), 3 deletions(-) create mode 100644 docker/scripts/build-librealsense.sh create mode 100644 docker/scripts/hotplug-realsense.sh create mode 100644 docker/scripts/install-realsense-dependencies.sh create mode 100644 docker/udev_rules/99-realsense-libusb-custom.rules diff --git a/docker/Dockerfile b/docker/Dockerfile index 32906c9..490e01d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -62,7 +62,21 @@ RUN apt-get update \ ros-${ROS_DISTRO}-rviz2 \ && rm -rf /var/lib/apt/lists/* - # Install ROS libraries +# ARG LIBREALSENSE_SOURCE_VERSION=v2.55.1 + +# COPY scripts/build-librealsense.sh /opt/realsense/build-librealsense.sh +# COPY scripts/install-realsense-dependencies.sh /opt/realsense/install-realsense-dependencies.sh + +# RUN chmod +x /opt/realsense/install-realsense-dependencies.sh && \ +# /opt/realsense/install-realsense-dependencies.sh; \ +# chmod +x /opt/realsense/build-librealsense.sh && /opt/realsense/build-librealsense.sh -v ${LIBREALSENSE_SOURCE_VERSION}; + +# Copy hotplug script for udev rules/hotplug for RealSense +RUN mkdir -p /opt/realsense/ +COPY scripts/hotplug-realsense.sh /opt/realsense/hotplug-realsense.sh +COPY udev_rules/99-realsense-libusb-custom.rules /etc/udev/rules.d/99-realsense-libusb-custom.rules + +# Install ROS libraries RUN apt-get update \ && apt-get install -y \ ros-${ROS_DISTRO}-ros-base \ @@ -122,6 +136,13 @@ COPY scripts/*.sh /usr/local/bin/scripts/ RUN dos2unix /usr/local/bin/scripts/*.sh RUN chmod +x /usr/local/bin/scripts/*.sh +# Copy hotplug script for udev rules/hotplug for RealSense +#RUN mkdir -p /opt/realsense/ +#COPY scripts/hotplug-realsense.sh /opt/realsense/hotplug-realsense.sh +#COPY udev_rules/99-realsense-libusb-custom.rules /etc/udev/rules.d/99-realsense-libusb-custom.rules + +ARG DEBIAN_FRONTEND=dialog + ENV USERNAME=${USERNAME} ENV USER_GID=${USER_GID} ENV USER_UID=${USER_UID} @@ -131,5 +152,3 @@ USER ${USERNAME} RUN --mount=type=cache,target=/var/cache/apt \ rosdep update USER root - -ARG DEBIAN_FRONTEND=dialog \ No newline at end of file diff --git a/docker/scripts/build-librealsense.sh b/docker/scripts/build-librealsense.sh new file mode 100644 index 0000000..67fab42 --- /dev/null +++ b/docker/scripts/build-librealsense.sh @@ -0,0 +1,188 @@ +#!/bin/bash +# Builds the Intel Realsense library librealsense on a Jetson Nano Development Kit +# Copyright (c) 2016-21 Jetsonhacks +# MIT License + +LIBREALSENSE_DIRECTORY=${HOME}/librealsense +INSTALL_DIR=$PWD +NVCC_PATH=/usr/local/cuda/bin/nvcc + +USE_CUDA=true + +function usage () +{ + echo "Usage: ./build-librealsense.sh [-n | -no_cuda] [-v | -version ] [-j | --jobs ] [-h | --help] " + echo "-n | --no_cuda Build with no CUDA (Defaults to with CUDA)" + echo "-v | --version Version of librealsense to build + (defaults to latest release)" + echo "-j | --jobs Number of concurrent jobs (Default 1 on <= 4GB RAM + #of cores-1 otherwise)" + echo "-h | --help This message" + exit 2 +} + +PARSED_ARGUMENTS=$(getopt -a -n build-librealsense.sh -o nv:j:h --longoptions version:,no_cuda,jobs:,help -- "$@" ) +VALID_ARGUMENTS=$? + +if [ "$VALID_ARGUMENTS" != "0" ]; then + echo "" + usage +fi + +eval set -- "$PARSED_ARGUMENTS" + +LIBREALSENSE_VERSION="" +USE_CUDA=true +NUM_PROCS="" + +while : +do + case "$1" in + -n | --build_no_cuda) USE_CUDA=false ; shift ;; + -v | --version ) LIBREALSENSE_VERSION="$2" ; shift 2 ;; + -j | --jobs) NUM_PROCS="$2" ; + shift 2 ; + re_isanum='^[0-9]+$' + if ! [[ $NUM_PROCS =~ $re_isanum ]] ; then + echo "Number of jobs must be a positive, whole number" + usage + else + if [ $NUM_PROCS -eq "0" ]; then + echo "Number of jobs must be a positive, whole number" + fi + fi ; + ;; + -h | --help ) usage ; shift ;; + # -- means the end of arguments + --) shift; break ;; + esac +done + +# From lukechilds gist discussion: https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c +# We use wget instead of curl here +# Sample usage: +# VERSION_STRINGS=$(get_latest_release IntelRealSense/librealsense) + +function get_latest_release () { + # redirect wget to standard out and grep out the tag_name + wget -qO- https://api.github.com/repos/$1/releases/latest | + grep -Po '"tag_name": "\K.*?(?=")' +} + +if [[ $LIBREALSENSE_VERSION == "" ]] ; then + echo "Getting latest librealsense version number" + LIBREALSENSE_VERSION=$(get_latest_release IntelRealSense/librealsense) +fi + +echo "Build with CUDA: "$USE_CUDA +echo "Librealsense Version: $LIBREALSENSE_VERSION" + +red=`tput setaf 1` +green=`tput setaf 2` +reset=`tput sgr0` +# e.g. echo "${red}The red tail hawk ${green}loves the green grass${reset}" + +if [ ! -d "$LIBREALSENSE_DIRECTORY" ] ; then + # clone librealsense + cd ${HOME} + echo "${green}Cloning librealsense${reset}" + git clone https://github.com/IntelRealSense/librealsense.git +fi + +# Is the version of librealsense current enough? +cd $LIBREALSENSE_DIRECTORY +VERSION_TAG=$(git tag -l $LIBREALSENSE_VERSION) +if [ ! $VERSION_TAG ] ; then + echo "" + tput setaf 1 + echo "==== librealsense Version Mismatch! =============" + tput sgr0 + echo "" + echo "The installed version of librealsense is not current enough for these scripts." + echo "This script needs librealsense tag version: "$LIBREALSENSE_VERSION "but it is not available." + echo "Please upgrade librealsense or remove the librealsense folder before attempting to install again." + echo "" + exit 1 +fi + +# Checkout version the last tested version of librealsense +git checkout $LIBREALSENSE_VERSION + +# Install the dependencies +cd $INSTALL_DIR + +cd $LIBREALSENSE_DIRECTORY +git checkout $LIBREALSENSE_VERSION + +# Now compile librealsense and install +mkdir build +cd build +# Build examples, including graphical ones +echo "${green}Configuring Make system${reset}" +# Build with CUDA (default), the CUDA flag is USE_CUDA, ie -DUSE_CUDA=true +export CUDACXX=$NVCC_PATH +export PATH=${PATH}:/usr/local/cuda/bin +export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/cuda/lib64 + +/usr/bin/cmake ../ -DBUILD_EXAMPLES=true -DFORCE_RSUSB_BACKEND=true -DBUILD_WITH_CUDA="$USE_CUDA" -DCMAKE_BUILD_TYPE=release -DBUILD_PYTHON_BINDINGS=bool:true + +# The library will be installed in /usr/local/lib, header files in /usr/local/include +# The demos, tutorials and tests will located in /usr/local/bin. +echo "${green}Building librealsense, headers, tools and demos${reset}" + +# If user didn't set # of jobs and we have > 4GB memory then +# set # of jobs to # of cores-1, otherwise 1 +if [[ $NUM_PROCS == "" ]] ; then + TOTAL_MEMORY=$(free | awk '/Mem\:/ { print $2 }') + if [ $TOTAL_MEMORY -gt 4051048 ] ; then + NUM_CPU=$(nproc) + NUM_PROCS=$(($NUM_CPU - 1)) + else + NUM_PROCS=1 + fi +fi + +time make -j$NUM_PROCS +if [ $? -eq 0 ] ; then + echo "librealsense make successful" +else + # Try to make again; Sometimes there are issues with the build + # because of lack of resources or concurrency issues + echo "librealsense did not build " >&2 + echo "Retrying ... " + # Single thread this time + time make + if [ $? -eq 0 ] ; then + echo "librealsense make successful" + else + # Try to make again + echo "librealsense did not successfully build" >&2 + echo "Please fix issues and retry build" + exit 1 + fi +fi +echo "${green}Installing librealsense, headers, tools and demos${reset}" +sudo make install + +if grep -Fxq 'export PYTHONPATH=$PYTHONPATH:/usr/local/lib' ~/.bashrc ; then + echo "PYTHONPATH already exists in .bashrc file" +else + echo 'export PYTHONPATH=$PYTHONPATH:/usr/local/lib' >> ~/.bashrc + echo "PYTHONPATH added to ~/.bashrc. Pyhon wrapper is now available for importing pyrealsense2" +fi + +cd $LIBREALSENSE_DIRECTORY +echo "${green}Applying udev rules${reset}" +# Copy over the udev rules so that camera can be run from user space +sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/ +sudo udevadm control --reload-rules && udevadm trigger + +echo "${green}Library Installed${reset}" +echo " " +echo " -----------------------------------------" +echo "The library is installed in /usr/local/lib" +echo "The header files are in /usr/local/include" +echo "The demos and tools are located in /usr/local/bin" +echo " " +echo " -----------------------------------------" +echo " " diff --git a/docker/scripts/hotplug-realsense.sh b/docker/scripts/hotplug-realsense.sh new file mode 100644 index 0000000..60975d4 --- /dev/null +++ b/docker/scripts/hotplug-realsense.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash + +# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. +# +# NVIDIA CORPORATION and its licensors retain all intellectual property +# and proprietary rights in and to this software, related documentation +# and any modifications thereto. Any use, reproduction, disclosure or +# distribution of this software and related documentation without an express +# license agreement from NVIDIA CORPORATION is strictly prohibited. + + +# This script is triggered when a corresponding udev rule is matched with action +function usage() { + echo "Usage: hotplug-realsense.sh -a -d [options]" + echo "-a | --action Action determines whether the device has been added or removed. Valid values are 'add' or 'remove'." + echo "-d | --dev-path Device path that will be used to mount the device." + echo "-M | --major-version The kernel major number for the device. This will be used when action=add." + echo "-m | --minor-version The kernel minor number for the device. This will be used when action=add." + echo "-p | --parent-path Parent node path of the device pointed by the -d flag." + echo "-h | --help Display this message." +} + +function check_mandatory_param() { +VAR=$1 +MSG=$2 +if [[ -z ${VAR} ]] ; then + echo "${MSG}" + usage + exit 1 +fi +} + +function timestamp() { + echo [$EPOCHREALTIME] [$(date)] +} + +ARGUMENTS=$(getopt -n hotplug-realsense.sh -o a:d:M:m:p:h -l action:,dev-path:,major-version:,minor-version:,parent-path:,help -- "$@" ) + +if [[ $? -ne 0 ]]; then + usage +fi + +eval set -- "$ARGUMENTS" + +while [ : ]; do + case "$1" in + -a | --action) + ACTION=$2 ; shift 2 ;; + -d | --dev-path) + DEV_PATH=$2 ; shift 2 ;; + -M | --major-version) + MAJOR_VERSION=$2 ; shift 2 ;; + -m | --minor-version) + MINOR_VERSION=$2 ; shift 2 ;; + -p | --parent-path) + PARENT_PATH=/dev/$2 ; shift 2 ;; + -h | --help) + usage ; shift ;; + --) shift; break ;; + esac +done + +check_mandatory_param ${ACTION:-""} "Please provide valid value for action" +check_mandatory_param ${DEV_PATH:-""} "Please provide valid value for device path" + +if [[ "${ACTION}" == "add" ]]; then + check_mandatory_param ${MAJOR_VERSION:-""} "Please provide valid value for major number" + check_mandatory_param ${MINOR_VERSION:-""} "Please provide valid value for minor number" + sudo mknod -m a=rw ${DEV_PATH} c ${MAJOR_VERSION} ${MINOR_VERSION} + sudo chown root:plugdev ${DEV_PATH} + echo $(timestamp) "Added ${DEV_PATH} with major version: ${MAJOR_VERSION} and minor version: ${MINOR_VERSION} to docker" >> /tmp/docker_usb.log +elif [[ "$ACTION" == "remove" ]]; then + sudo rm ${DEV_PATH} ${PARENT_PATH} + echo $(timestamp) "Removed ${DEV_PATH} ${PARENT_PATH} from docker" >> /tmp/docker_usb.log +else + echo "Cannot recognize action=${ACTION}" + usage + exit 1 +fi \ No newline at end of file diff --git a/docker/scripts/install-realsense-dependencies.sh b/docker/scripts/install-realsense-dependencies.sh new file mode 100644 index 0000000..db81a0c --- /dev/null +++ b/docker/scripts/install-realsense-dependencies.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# install-realsense-dependencies.sh +# Install dependencies for the Intel Realsense library librealsense2 on a Jetson Nano Developer Kit +# Copyright (c) 2016-19 Jetsonhacks +# MIT License + +red=`tput setaf 1` +green=`tput setaf 2` +reset=`tput sgr0` +# e.g. echo "${red}red text ${green}green text${reset}" +echo "${green}Adding Universe repository and updating${reset}" +apt-add-repository universe +apt-get update +echo "${green}Adding dependencies, graphics libraries and tools${reset}" +apt-get install libssl-dev libusb-1.0-0-dev pkg-config -y + +# Graphics libraries - for SDK's OpenGL-enabled examples +apt-get install libgtk-3-dev libglfw3-dev libgl1-mesa-dev libglu1-mesa-dev -y + +# QtCreator for development; not required for librealsense core library +apt-get install qtcreator -y + +# Add Python 3 support +apt-get install -y python3 python3-dev diff --git a/docker/udev_rules/99-realsense-libusb-custom.rules b/docker/udev_rules/99-realsense-libusb-custom.rules new file mode 100644 index 0000000..a3b6688 --- /dev/null +++ b/docker/udev_rules/99-realsense-libusb-custom.rules @@ -0,0 +1,11 @@ +##Version=0.1## +# Device rules for Intel RealSense devices (D435 D435i D455) +# For D435 +ACTION=="add" SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0b07", MODE:="0666", GROUP:="plugdev", RUN+="/opt/realsense/hotplug-realsense.sh -a add -d '%N' -M '%M' -m '%m'" +ACTION=="remove" SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0b07", MODE:="0666", GROUP:="plugdev", RUN+="/opt/realsense/hotplug-realsense.sh -a remove -d '%N' -p '%P'" +# For D435i +ACTION=="add" SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0b3a", MODE:="0666", GROUP:="plugdev", RUN+="/opt/realsense/hotplug-realsense.sh -a add -d '%N' -M '%M' -m '%m'" +ACTION=="remove" SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0b3a", MODE:="0666", GROUP:="plugdev", RUN+="/opt/realsense/hotplug-realsense.sh -a remove -d '%N' -p '%P'" +# For D455 +ACTION=="add" SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0b5c", MODE:="0666", GROUP:="plugdev", RUN+="/opt/realsense/hotplug-realsense.sh -a add -d '%N' -M '%M' -m '%m'" +ACTION=="remove" SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0b5c", MODE:="0666", GROUP:="plugdev", RUN+="/opt/realsense/hotplug-realsense.sh -a remove -d '%N' -p '%P'" \ No newline at end of file From ec9d753d625b13484404630acfa4e6f3a698c21a Mon Sep 17 00:00:00 2001 From: stampede Date: Thu, 10 Oct 2024 12:36:52 -0500 Subject: [PATCH 2/8] build from source, untested --- docker/Dockerfile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 490e01d..c4368a4 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -62,14 +62,15 @@ RUN apt-get update \ ros-${ROS_DISTRO}-rviz2 \ && rm -rf /var/lib/apt/lists/* -# ARG LIBREALSENSE_SOURCE_VERSION=v2.55.1 +ARG LIBREALSENSE_SOURCE_VERSION=v2.55.1 -# COPY scripts/build-librealsense.sh /opt/realsense/build-librealsense.sh -# COPY scripts/install-realsense-dependencies.sh /opt/realsense/install-realsense-dependencies.sh +COPY scripts/install-realsense-dependencies.sh /opt/realsense/install-realsense-dependencies.sh +RUN chmod +x /opt/realsense/install-realsense-dependencies.sh && \ + /opt/realsense/install-realsense-dependencies.sh; -# RUN chmod +x /opt/realsense/install-realsense-dependencies.sh && \ -# /opt/realsense/install-realsense-dependencies.sh; \ -# chmod +x /opt/realsense/build-librealsense.sh && /opt/realsense/build-librealsense.sh -v ${LIBREALSENSE_SOURCE_VERSION}; +COPY scripts/build-librealsense.sh /opt/realsense/build-librealsense.sh +RUN chmod +x /opt/realsense/build-librealsense.sh +RUN /opt/realsense/build-librealsense.sh -n -v ${LIBREALSENSE_SOURCE_VERSION}; # Copy hotplug script for udev rules/hotplug for RealSense RUN mkdir -p /opt/realsense/ From e460b9b3275b998a3aad83f03d9949fa19be1d57 Mon Sep 17 00:00:00 2001 From: stampede Date: Thu, 10 Oct 2024 18:24:06 -0500 Subject: [PATCH 3/8] add build from source and new docker build system --- docker/Dockerfile | 155 ----------- docker/Dockerfile.realsense_pkg | 22 ++ docker/Dockerfile.realsense_source | 17 ++ docker/Dockerfile.ros2_humble | 55 ++++ docker/Dockerfile.tools | 13 + docker/Dockerfile.user | 49 ++++ docker/scripts/build-librealsense.sh | 4 +- docker/scripts/workspace-entrypoint.sh | 2 + scripts/build_image_layers.sh | 352 +++++++++++++++++++++++++ scripts/run_dev.sh | 24 +- scripts/run_realsense_camera.sh | 1 + scripts/save_camera_bag.sh | 3 + scripts/utils/print_color.sh | 17 ++ 13 files changed, 555 insertions(+), 159 deletions(-) delete mode 100644 docker/Dockerfile create mode 100644 docker/Dockerfile.realsense_pkg create mode 100644 docker/Dockerfile.realsense_source create mode 100644 docker/Dockerfile.ros2_humble create mode 100644 docker/Dockerfile.tools create mode 100644 docker/Dockerfile.user create mode 100755 scripts/build_image_layers.sh create mode 100755 scripts/save_camera_bag.sh create mode 100644 scripts/utils/print_color.sh diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index c4368a4..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,155 +0,0 @@ -FROM ros:humble-perception - -ENV WS_DIR="/ros2_ws" -WORKDIR ${WS_DIR} - -SHELL ["/bin/bash", "-c"] - -ARG DEBIAN_FRONTEND=noninteractive - -# Setup non-root admin user -ARG USERNAME=admin -ARG USER_UID=1000 -ARG USER_GID=1000 - -# Install prerequisites -RUN apt-get update && apt-get install -y \ - sudo \ - udev \ -&& rm -rf /var/lib/apt/lists/* \ -&& apt-get clean - -# Reuse triton-server user as 'admin' user if exists -RUN if [ $(getent group triton-server) ]; then \ - groupmod -o --gid ${USER_GID} -n ${USERNAME} triton-server ; \ - usermod -l ${USERNAME} -u ${USER_UID} -m -d /home/${USERNAME} triton-server ; \ - mkdir -p /home/${USERNAME} ; \ - sudo chown ${USERNAME}:${USERNAME} /home/${USERNAME} ; \ - fi - -# Create the 'admin' user if not already exists -RUN if [ ! $(getent passwd ${USERNAME}) ]; then \ - groupadd --gid ${USER_GID} ${USERNAME} ; \ - useradd --uid ${USER_UID} --gid ${USER_GID} -m ${USERNAME} ; \ - fi - -# Update 'admin' user -RUN echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} \ - && chmod 0440 /etc/sudoers.d/${USERNAME} \ - && adduser ${USERNAME} video && adduser ${USERNAME} plugdev && adduser ${USERNAME} sudo && adduser ${USERNAME} dialout - -ENV USERNAME=${USERNAME} -ENV USER_GID=${USER_GID} -ENV USER_UID=${USER_UID} - -# Install Realsense libraries -RUN apt-get update \ - && apt-get install -y \ - build-essential \ - cmake \ - git-all \ - software-properties-common \ - && rm -rf /var/lib/apt/lists/* - -RUN apt-get update \ - && apt-get install -y \ - ros-${ROS_DISTRO}-librealsense2* \ - ros-${ROS_DISTRO}-realsense2-* \ - && rm -rf /var/lib/apt/lists/* - -RUN apt-get update \ - && apt-get install -y \ - ros-${ROS_DISTRO}-rviz2 \ - && rm -rf /var/lib/apt/lists/* - -ARG LIBREALSENSE_SOURCE_VERSION=v2.55.1 - -COPY scripts/install-realsense-dependencies.sh /opt/realsense/install-realsense-dependencies.sh -RUN chmod +x /opt/realsense/install-realsense-dependencies.sh && \ - /opt/realsense/install-realsense-dependencies.sh; - -COPY scripts/build-librealsense.sh /opt/realsense/build-librealsense.sh -RUN chmod +x /opt/realsense/build-librealsense.sh -RUN /opt/realsense/build-librealsense.sh -n -v ${LIBREALSENSE_SOURCE_VERSION}; - -# Copy hotplug script for udev rules/hotplug for RealSense -RUN mkdir -p /opt/realsense/ -COPY scripts/hotplug-realsense.sh /opt/realsense/hotplug-realsense.sh -COPY udev_rules/99-realsense-libusb-custom.rules /etc/udev/rules.d/99-realsense-libusb-custom.rules - -# Install ROS libraries -RUN apt-get update \ - && apt-get install -y \ - ros-${ROS_DISTRO}-ros-base \ - ros-${ROS_DISTRO}-angles \ - ros-${ROS_DISTRO}-apriltag \ - ros-${ROS_DISTRO}-behaviortree-cpp-v3 \ - ros-${ROS_DISTRO}-bondcpp \ - ros-${ROS_DISTRO}-camera-calibration-parsers \ - ros-${ROS_DISTRO}-camera-info-manager \ - ros-${ROS_DISTRO}-compressed-image-transport \ - ros-${ROS_DISTRO}-compressed-depth-image-transport \ - ros-${ROS_DISTRO}-cv-bridge \ - ros-${ROS_DISTRO}-demo-nodes-cpp \ - ros-${ROS_DISTRO}-demo-nodes-py \ - ros-${ROS_DISTRO}-diagnostic-updater \ - ros-${ROS_DISTRO}-example-interfaces \ - ros-${ROS_DISTRO}-foxglove-bridge \ - ros-${ROS_DISTRO}-image-geometry \ - ros-${ROS_DISTRO}-image-pipeline \ - ros-${ROS_DISTRO}-image-transport \ - ros-${ROS_DISTRO}-image-transport-plugins \ - ros-${ROS_DISTRO}-launch-xml \ - ros-${ROS_DISTRO}-launch-yaml \ - ros-${ROS_DISTRO}-launch-testing \ - ros-${ROS_DISTRO}-launch-testing-ament-cmake \ - ros-${ROS_DISTRO}-nav2-bringup \ - ros-${ROS_DISTRO}-nav2-msgs \ - ros-${ROS_DISTRO}-nav2-mppi-controller \ - ros-${ROS_DISTRO}-navigation2 \ - ros-${ROS_DISTRO}-ompl \ - ros-${ROS_DISTRO}-resource-retriever \ - ros-${ROS_DISTRO}-rqt-graph \ - ros-${ROS_DISTRO}-rqt-reconfigure \ - ros-${ROS_DISTRO}-rqt-image-view \ - ros-${ROS_DISTRO}-rviz2 \ - ros-${ROS_DISTRO}-rviz-common \ - ros-${ROS_DISTRO}-rviz-default-plugins \ - ros-${ROS_DISTRO}-sensor-msgs \ - ros-${ROS_DISTRO}-slam-toolbox \ - ros-${ROS_DISTRO}-v4l2-camera \ - ros-${ROS_DISTRO}-vision-opencv \ - ros-${ROS_DISTRO}-vision-msgs \ -&& rm -rf /var/lib/apt/lists/* \ -&& apt-get clean - -# Install helpful tools -RUN apt-get update && apt-get install -y \ - vim \ - nano \ - dos2unix \ -&& rm -rf /var/lib/apt/lists/* \ -&& apt-get clean - -# Copy scripts -RUN mkdir -p /usr/local/bin/scripts -COPY scripts/*.sh /usr/local/bin/scripts/ -RUN dos2unix /usr/local/bin/scripts/*.sh -RUN chmod +x /usr/local/bin/scripts/*.sh - -# Copy hotplug script for udev rules/hotplug for RealSense -#RUN mkdir -p /opt/realsense/ -#COPY scripts/hotplug-realsense.sh /opt/realsense/hotplug-realsense.sh -#COPY udev_rules/99-realsense-libusb-custom.rules /etc/udev/rules.d/99-realsense-libusb-custom.rules - -ARG DEBIAN_FRONTEND=dialog - -ENV USERNAME=${USERNAME} -ENV USER_GID=${USER_GID} -ENV USER_UID=${USER_UID} - -# Switch to non-root user and return to root -USER ${USERNAME} -RUN --mount=type=cache,target=/var/cache/apt \ - rosdep update -USER root diff --git a/docker/Dockerfile.realsense_pkg b/docker/Dockerfile.realsense_pkg new file mode 100644 index 0000000..5767b5a --- /dev/null +++ b/docker/Dockerfile.realsense_pkg @@ -0,0 +1,22 @@ +ARG BASE_IMAGE +FROM ${BASE_IMAGE} + +# Install Realsense libraries +RUN apt-get update \ + && apt-get install -y \ + build-essential \ + cmake \ + git-all \ + software-properties-common \ + && rm -rf /var/lib/apt/lists/* + +RUN apt-get update \ + && apt-get install -y \ + ros-${ROS_DISTRO}-librealsense2* \ + ros-${ROS_DISTRO}-realsense2-* \ + && rm -rf /var/lib/apt/lists/* + +RUN apt-get update \ + && apt-get install -y \ + ros-${ROS_DISTRO}-rviz2 \ + && rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/docker/Dockerfile.realsense_source b/docker/Dockerfile.realsense_source new file mode 100644 index 0000000..d21e1d5 --- /dev/null +++ b/docker/Dockerfile.realsense_source @@ -0,0 +1,17 @@ +ARG BASE_IMAGE +FROM ${BASE_IMAGE} + +ARG LIBREALSENSE_SOURCE_VERSION=v2.55.1 + +COPY scripts/install-realsense-dependencies.sh /opt/realsense/install-realsense-dependencies.sh +RUN chmod +x /opt/realsense/install-realsense-dependencies.sh && \ + /opt/realsense/install-realsense-dependencies.sh; + +COPY scripts/build-librealsense.sh /opt/realsense/build-librealsense.sh +RUN chmod +x /opt/realsense/build-librealsense.sh +RUN /opt/realsense/build-librealsense.sh -n -v ${LIBREALSENSE_SOURCE_VERSION}; + +# Copy hotplug script for udev rules/hotplug for RealSense +RUN mkdir -p /opt/realsense/ +COPY scripts/hotplug-realsense.sh /opt/realsense/hotplug-realsense.sh +COPY udev_rules/99-realsense-libusb-custom.rules /etc/udev/rules.d/99-realsense-libusb-custom.udev_rules \ No newline at end of file diff --git a/docker/Dockerfile.ros2_humble b/docker/Dockerfile.ros2_humble new file mode 100644 index 0000000..89f0b50 --- /dev/null +++ b/docker/Dockerfile.ros2_humble @@ -0,0 +1,55 @@ +ARG BASE_IMAGE=ros:humble-perception +FROM ${BASE_IMAGE} + +ENV WS_DIR="/ros2_ws" +WORKDIR ${WS_DIR} + +ARG DEBIAN_FRONTEND=noninteractive +ENV SHELL /bin/bash +SHELL ["/bin/bash", "-c"] + +# Install ROS libraries +RUN apt-get update \ + && apt-get install -y \ + ros-${ROS_DISTRO}-ros-base \ + ros-${ROS_DISTRO}-angles \ + ros-${ROS_DISTRO}-apriltag \ + ros-${ROS_DISTRO}-behaviortree-cpp-v3 \ + ros-${ROS_DISTRO}-bondcpp \ + ros-${ROS_DISTRO}-camera-calibration-parsers \ + ros-${ROS_DISTRO}-camera-info-manager \ + ros-${ROS_DISTRO}-compressed-image-transport \ + ros-${ROS_DISTRO}-compressed-depth-image-transport \ + ros-${ROS_DISTRO}-cv-bridge \ + ros-${ROS_DISTRO}-demo-nodes-cpp \ + ros-${ROS_DISTRO}-demo-nodes-py \ + ros-${ROS_DISTRO}-diagnostic-updater \ + ros-${ROS_DISTRO}-example-interfaces \ + ros-${ROS_DISTRO}-foxglove-bridge \ + ros-${ROS_DISTRO}-image-geometry \ + ros-${ROS_DISTRO}-image-pipeline \ + ros-${ROS_DISTRO}-image-transport \ + ros-${ROS_DISTRO}-image-transport-plugins \ + ros-${ROS_DISTRO}-launch-xml \ + ros-${ROS_DISTRO}-launch-yaml \ + ros-${ROS_DISTRO}-launch-testing \ + ros-${ROS_DISTRO}-launch-testing-ament-cmake \ + ros-${ROS_DISTRO}-nav2-bringup \ + ros-${ROS_DISTRO}-nav2-msgs \ + ros-${ROS_DISTRO}-nav2-mppi-controller \ + ros-${ROS_DISTRO}-navigation2 \ + ros-${ROS_DISTRO}-ompl \ + ros-${ROS_DISTRO}-resource-retriever \ + ros-${ROS_DISTRO}-rqt-graph \ + ros-${ROS_DISTRO}-rqt-reconfigure \ + ros-${ROS_DISTRO}-rqt-image-view \ + ros-${ROS_DISTRO}-rviz2 \ + ros-${ROS_DISTRO}-rviz-common \ + ros-${ROS_DISTRO}-rviz-default-plugins \ + ros-${ROS_DISTRO}-sensor-msgs \ + ros-${ROS_DISTRO}-slam-toolbox \ + ros-${ROS_DISTRO}-v4l2-camera \ + ros-${ROS_DISTRO}-vision-opencv \ + ros-${ROS_DISTRO}-vision-msgs \ +&& rm -rf /var/lib/apt/lists/* \ +&& apt-get clean \ No newline at end of file diff --git a/docker/Dockerfile.tools b/docker/Dockerfile.tools new file mode 100644 index 0000000..a7c90bf --- /dev/null +++ b/docker/Dockerfile.tools @@ -0,0 +1,13 @@ +ARG BASE_IMAGE +FROM ${BASE_IMAGE} + +# Install helpful tools +RUN apt-get update && apt-get install -y \ + vim \ + nano \ + dos2unix \ + ffmpeg \ +&& rm -rf /var/lib/apt/lists/* \ +&& apt-get clean + +RUN git clone https://github.com/mlaiacker/rosbag2video.git \ No newline at end of file diff --git a/docker/Dockerfile.user b/docker/Dockerfile.user new file mode 100644 index 0000000..e91ef6d --- /dev/null +++ b/docker/Dockerfile.user @@ -0,0 +1,49 @@ +ARG BASE_IMAGE +FROM ${BASE_IMAGE} + +# Setup non-root admin user +ARG USERNAME=admin +ARG USER_UID=1000 +ARG USER_GID=1000 + +# Install prerequisites +RUN apt-get update && apt-get install -y \ + sudo \ + udev \ +&& rm -rf /var/lib/apt/lists/* \ +&& apt-get clean + +# Reuse triton-server user as 'admin' user if exists +RUN if [ $(getent group triton-server) ]; then \ + groupmod -o --gid ${USER_GID} -n ${USERNAME} triton-server ; \ + usermod -l ${USERNAME} -u ${USER_UID} -m -d /home/${USERNAME} triton-server ; \ + mkdir -p /home/${USERNAME} ; \ + sudo chown ${USERNAME}:${USERNAME} /home/${USERNAME} ; \ + fi + +# Create the 'admin' user if not already exists +RUN if [ ! $(getent passwd ${USERNAME}) ]; then \ + groupadd --gid ${USER_GID} ${USERNAME} ; \ + useradd --uid ${USER_UID} --gid ${USER_GID} -m ${USERNAME} ; \ + fi + +# Update 'admin' user +RUN echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} \ + && chmod 0440 /etc/sudoers.d/${USERNAME} \ + && adduser ${USERNAME} video && adduser ${USERNAME} plugdev && adduser ${USERNAME} sudo && adduser ${USERNAME} dialout + +# Copy scripts +RUN mkdir -p /usr/local/bin/scripts +COPY scripts/*.sh /usr/local/bin/scripts/ +RUN dos2unix /usr/local/bin/scripts/*.sh +RUN chmod +x /usr/local/bin/scripts/*.sh + +ENV USERNAME=${USERNAME} +ENV USER_GID=${USER_GID} +ENV USER_UID=${USER_UID} + +# Switch to non-root user and return to root +USER ${USERNAME} +RUN --mount=type=cache,target=/var/cache/apt \ + rosdep update +USER root diff --git a/docker/scripts/build-librealsense.sh b/docker/scripts/build-librealsense.sh index 67fab42..7f53f2a 100644 --- a/docker/scripts/build-librealsense.sh +++ b/docker/scripts/build-librealsense.sh @@ -38,7 +38,7 @@ NUM_PROCS="" while : do case "$1" in - -n | --build_no_cuda) USE_CUDA=false ; shift ;; + -n | --no_cuda) USE_CUDA=false ; shift ;; -v | --version ) LIBREALSENSE_VERSION="$2" ; shift 2 ;; -j | --jobs) NUM_PROCS="$2" ; shift 2 ; @@ -175,7 +175,7 @@ cd $LIBREALSENSE_DIRECTORY echo "${green}Applying udev rules${reset}" # Copy over the udev rules so that camera can be run from user space sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/ -sudo udevadm control --reload-rules && udevadm trigger +sudo udevadm control --reload-rules && sudo udevadm trigger echo "${green}Library Installed${reset}" echo " " diff --git a/docker/scripts/workspace-entrypoint.sh b/docker/scripts/workspace-entrypoint.sh index 98d9dfb..092e6d7 100644 --- a/docker/scripts/workspace-entrypoint.sh +++ b/docker/scripts/workspace-entrypoint.sh @@ -14,6 +14,8 @@ echo "source /usr/local/bin/scripts/setup.sh" >> ~/.bashrc source /opt/ros/${ROS_DISTRO}/setup.bash source /usr/local/bin/scripts/setup.sh +sudo udevadm control --reload-rules + # Configure git git config --global --add safe.directory /robomaster_cv diff --git a/scripts/build_image_layers.sh b/scripts/build_image_layers.sh new file mode 100755 index 0000000..5e2afc2 --- /dev/null +++ b/scripts/build_image_layers.sh @@ -0,0 +1,352 @@ +#!/bin/bash +# +# Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved. +# +# NVIDIA CORPORATION and its licensors retain all intellectual property +# and proprietary rights in and to this software, related documentation +# and any modifications thereto. Any use, reproduction, disclosure or +# distribution of this software and related documentation without an express +# license agreement from NVIDIA CORPORATION is strictly prohibited. +set -e + +ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +source $ROOT/utils/print_color.sh +DOCKER_DIR="${ROOT}/../docker" + +function usage() { + print_info "Usage: ${0##*/}" + print_info "Copyright (c) 2024, NVIDIA CORPORATION." +} + +# Initialize arguments +DOCKER_BUILDKIT=1 +IGNORE_COMPOSITE_KEYS=0 +ADDITIONAL_BUILD_ARGS=() +ADDITIONAL_DOCKER_ARGS=() +DOCKER_SEARCH_DIRS=(${DOCKER_DIR}) +SKIP_REGISTRY_CHECK=0 +BASE_DOCKER_REGISTRY_NAMES=("nvcr.io/isaac/ros") + +# Read and parse config file if exists +# +# CONFIG_DOCKER_SEARCH_DIRS (array, can be empty) + +if [[ -f "${ROOT}/.isaac_ros_common-config" ]]; then + . "${ROOT}/.isaac_ros_common-config" +fi + +# Override with config from user home directory if exists +if [[ -f ~/.isaac_ros_common-config ]]; then + . ~/.isaac_ros_common-config +fi + +# Prepend configured docker search dirs +if [ ${#CONFIG_DOCKER_SEARCH_DIRS[@]} -gt 0 ]; then + for (( i=${#CONFIG_DOCKER_SEARCH_DIRS[@]}-1 ; i>=0 ; i-- )); do + + # If the path is relative, then prefix ROOT to the path + if [[ "${CONFIG_DOCKER_SEARCH_DIRS[i]}" != /* ]]; then + CONFIG_DOCKER_SEARCH_DIRS[$i]="${ROOT}/${CONFIG_DOCKER_SEARCH_DIRS[i]}" + fi + done + + CONFIG_DOCKER_SEARCH_DIRS+=(${DOCKER_SEARCH_DIRS[@]}) + DOCKER_SEARCH_DIRS=(${CONFIG_DOCKER_SEARCH_DIRS[@]}) +fi + +# Parse command-line args +VALID_ARGS=$(getopt -o hra:b:c:ki:n:d: --long help,skip_registry_check,build_arg:,base_image:,context_dir:,disable_buildkit,image_key:,image_name:,ignore_composite_keys,docker_arg: -- "$@") +eval set -- "$VALID_ARGS" +while [ : ]; do + case "$1" in + -a | --build_arg) + ADDITIONAL_BUILD_ARGS+=("$2") + shift 2 + ;; + -b | --base_image) + BASE_IMAGE_NAME="$2" + shift 2 + ;; + -c | --context_dir) + DOCKER_CONTEXT_DIR="$2" + shift 2 + ;; + -d | --docker_arg) + ADDITIONAL_DOCKER_ARGS+=("$2") + shift 2 + ;; + -k | --disable_buildkit) + DOCKER_BUILDKIT=0 + shift + ;; + -i | --image_key) + TARGET_IMAGE_STR="$2" + shift 2 + ;; + -n | --image_name) + TARGET_IMAGE_NAME="$2" + shift 2 + ;; + -r | --skip_registry_check) + SKIP_REGISTRY_CHECK=1 + shift + ;; + -y | --ignore_composite_keys) + IGNORE_COMPOSITE_KEYS=1 + shift + ;; + -h | --help) + usage + exit 0 + ;; + --) shift; + break + ;; + esac +done + +# Check arguments +if [[ -z "$TARGET_IMAGE_STR" ]]; then + print_error "Target image not specified with -i/--image_key" + exit 1 +fi + +if [[ -z "$TARGET_IMAGE_NAME" ]]; then + TARGET_IMAGE_NAME="${TARGET_IMAGE_STR//./-}-image" + print_warning "Target image name not specified, using ${TARGET_IMAGE_NAME}" +fi + +if [[ ! -z "$DOCKER_CONTEXT_DIR" ]]; then + DOCKER_SEARCH_DIRS+=($DOCKER_CONTEXT_DIR) +fi + +# Summarize final arguments for script +print_info "Building layered image for key ${TARGET_IMAGE_STR} as ${TARGET_IMAGE_NAME}" +if [[ ! -z "${BASE_IMAGE_NAME}" ]]; then + print_info "Build image on top of base: |${BASE_IMAGE_NAME}|" +fi + +print_info "Using configured docker search paths: ${DOCKER_SEARCH_DIRS[*]}" +if [[ ! -z "${DOCKER_CONTEXT_DIR}" ]]; then + print_info "Docker context directory for final layer: ${DOCKER_CONTEXT_DIR}" +fi +for BUILD_ARG in "${ADDITIONAL_BUILD_ARGS[@]}" +do + print_info "Additional build arg: ${BUILD_ARG}" +done +for DOCKER_ARG in "${ADDITIONAL_DOCKER_ARGS[@]}" +do + print_info "Additional docker arg: ${DOCKER_ARG}" +done +if [[ $DOCKER_BUILDKIT -eq 0 ]]; then + print_warning "WARNING: Explicitly disabling BuildKit" +fi + +if [[ $IGNORE_COMPOSITE_KEYS -eq 1 ]]; then + print_warning "WARNING: Explicitly disabling matching composite image keys" +fi + +if [[ $SKIP_REGISTRY_CHECK -eq 1 ]]; then + print_warning "WARNING: Skipping remote registry check for prebuilt images" +fi + +# Setup on-exit cleanup +ON_EXIT=() +function cleanup { + for command in "${ON_EXIT[@]}" + do + $command &>/dev/null + done +} +trap cleanup EXIT + +PLATFORM="$(uname -m)" + +# Resolve Dockerfiles by matching target image ids to available files +TARGET_IMAGE_IDS=(${TARGET_IMAGE_STR//./ }) +IMAGE_IDS=(${TARGET_IMAGE_IDS[@]}) + +# Loop over components and find largest tail sequences +# For example, a target image id of 'aarch64.jp5.carter.nav' should match +# Dockerfiles with suffixes in the following order: +# ".aarch64.jp5.carter.nav", ".jp5.carter.nav", ".carter.nav", ".nav" +# If the first file found is ".carter.nav", the matching recurses by then +# looking for the preceding components ".aarch64.jp5" in the same manner +DOCKERFILES=() +DOCKERFILE_CONTEXT_DIRS=() +until [ ${#IMAGE_IDS[@]} -le 0 ]; do + UNMATCHED_ID_COUNT=${#IMAGE_IDS[@]} + + for (( i=0; i<${#IMAGE_IDS[@]}; i++ )) do + # Abort matching composite keys if disabled + if [[ $IGNORE_COMPOSITE_KEYS -gt 1 && $i -eq 1 ]]; then + break + fi + + LAYER_IMAGE_IDS=${IMAGE_IDS[@]:i} + LAYER_IMAGE_SUFFIX="${LAYER_IMAGE_IDS[@]// /.}" + + for DOCKER_SEARCH_DIR in ${DOCKER_SEARCH_DIRS[@]}; do + DOCKERFILE="${DOCKER_SEARCH_DIR}/Dockerfile.${LAYER_IMAGE_SUFFIX}" + + if [[ -f "${DOCKERFILE}" ]]; then + DOCKERFILES+=(${DOCKERFILE}) + DOCKERFILE_CONTEXT_DIRS+=(${DOCKER_SEARCH_DIR}) + IMAGE_IDS=(${IMAGE_IDS[@]:0:i}) + break 2 + fi + done + done + + if [ ${UNMATCHED_ID_COUNT} -eq ${#IMAGE_IDS[@]} ]; then + UNMATCHED_IDS=${IMAGE_IDS[@]} + MATCHED_DOCKERFILES=${DOCKERFILES[@]} + print_error "Could not resolve Dockerfiles for target image ids: ${UNMATCHED_IDS// /.}" + + if [ ${#DOCKERFILES[@]} -gt 0 ]; then + print_warning "Partially resolved the following Dockerfiles for target image: ${TARGET_IMAGE_STR}" + for DOCKERFILE in ${DOCKERFILES[@]}; do + print_warning "${DOCKERFILE}" + done + fi + exit 1 + fi +done + +# Find pre-built image if available +if [[ $SKIP_REGISTRY_CHECK -eq 0 && -z "${BASE_IMAGE_NAME}" ]]; then + # Generate the possible base image names to look for from first image key onward + BASE_IMAGE_FULLNAMES=() + BASE_DOCKERFILES=() + BASE_DOCKERFILE_CONTEXT_DIRS=() + BASE_IMAGE_DOCKERFILES_INDICES=() + for (( i=${#DOCKERFILES[@]}-1 ; i>=0 ; i-- )); do + BASE_DOCKERFILES+=(${DOCKERFILES[i]}) + BASE_DOCKERFILE_CONTEXT_DIRS+=(${DOCKERFILE_CONTEXT_DIRS[i]}) + BASE_IMAGE_KEYS=() + + DOCKER_HASH_FILE=$(mktemp) + ON_EXIT+=("rm -Rf ${DOCKER_HASH_FILE}") + + # Determine hash of all Dockerfiles for this base image name + for (( j=0 ; j<${#BASE_DOCKERFILES[@]} ; j++ )); do + BASE_DOCKERFILE=${BASE_DOCKERFILES[j]} + BASE_DOCKERFILE_CONTEXT_DIR=${BASE_DOCKERFILE_CONTEXT_DIRS[j]} + LAYER_IMAGE_SUFFIX=${BASE_DOCKERFILE#*"/Dockerfile."} + BASE_IMAGE_KEYS+=(${LAYER_IMAGE_SUFFIX//./ }) + + pushd . >/dev/null + cd $BASE_DOCKERFILE_CONTEXT_DIR + BASE_DOCKERFILE="Dockerfile.${LAYER_IMAGE_SUFFIX}" + md5sum ${BASE_DOCKERFILE} >> $DOCKER_HASH_FILE + popd >/dev/null + done + SOURCE_DOCKERFILE_HASH=($(md5sum $DOCKER_HASH_FILE)) + + # Determine base image name + for (( j=${#BASE_DOCKER_REGISTRY_NAMES[@]}-1 ; j>= 0; j-- )); do + BASE_DOCKER_REGISTRY_NAME=${BASE_DOCKER_REGISTRY_NAMES[j]} + BASE_IMAGE_TAG=${BASE_IMAGE_KEYS[*]} + BASE_IMAGE_TAG=${BASE_IMAGE_TAG// /.} + BASE_IMAGE_FULLNAME="${BASE_DOCKER_REGISTRY_NAME}:${BASE_IMAGE_TAG//./-}_${SOURCE_DOCKERFILE_HASH}" + BASE_IMAGE_FULLNAMES+=(${BASE_IMAGE_FULLNAME}) + + # Remember which index goes with this base image so we can skip those Dockerfiles + # if this image exists + BASE_IMAGE_DOCKERFILES_INDICES+=($i) + done + done + + for (( i=${#BASE_IMAGE_FULLNAMES[@]}-1 ; i>=0 ; i-- )); do + BASE_IMAGE_FULLNAME=${BASE_IMAGE_FULLNAMES[i]} + + # Check if image exists on remote server + print_info "Checking if base image ${BASE_IMAGE_FULLNAME} exists on remote registry" + OUTPUT=$(docker manifest inspect ${BASE_IMAGE_FULLNAME} >/dev/null 2>&1 ; echo $?) + if [[ ${OUTPUT} -eq 0 ]]; then + BASE_IMAGE_NAME=${BASE_IMAGE_FULLNAME} + DOCKERFILES=(${DOCKERFILES[@]:0:${BASE_IMAGE_DOCKERFILES_INDICES[i]-1}}) + print_info "Found pre-built base image: ${BASE_IMAGE_FULLNAME}" + docker pull ${BASE_IMAGE_FULLNAME} + print_info "Finished pulling pre-built base image: ${BASE_IMAGE_FULLNAME}" + break + fi + done +fi + +# Arguments for docker build +BUILD_ARGS+=("--build-arg" "USERNAME="admin"") +BUILD_ARGS+=("--build-arg" "USER_UID=`id -u`") +BUILD_ARGS+=("--build-arg" "USER_GID=`id -g`") +BUILD_ARGS+=("--build-arg" "PLATFORM=$PLATFORM") + +for BUILD_ARG in ${ADDITIONAL_BUILD_ARGS[@]} +do + BUILD_ARGS+=("--build-arg" "${BUILD_ARG}") +done + +# Check if GPU is installed +if [[ $PLATFORM == "x86_64" ]]; then + GPU_ATTACHED=(`nvidia-smi -a | grep "Attached GPUs" || true`) + if [ -z $GPU_ATTACHED ]; then + print_warning "No GPU detected! Not setting build args for HAS_GPU" + else + BUILD_ARGS+=("--build-arg" "HAS_GPU="true"") + fi +fi + +if [ ${#DOCKERFILES[@]} -gt 0 ]; then + print_info "Resolved the following ${#DOCKERFILES[@]} Dockerfiles for target image: ${TARGET_IMAGE_STR}" + for DOCKERFILE in ${DOCKERFILES[@]}; do + print_info "${DOCKERFILE}" + done +else + docker tag ${BASE_IMAGE_NAME} ${TARGET_IMAGE_NAME} + print_info "Nothing to build, retagged ${BASE_IMAGE_NAME} as ${TARGET_IMAGE_NAME}" + exit 0 +fi + +# Build image layers +for (( i=${#DOCKERFILES[@]}-1 ; i>=0 ; i-- )); do + DOCKERFILE=${DOCKERFILES[i]} + DOCKERFILE_CONTEXT_DIR=${DOCKERFILE_CONTEXT_DIRS[i]} + IMAGE_NAME=${DOCKERFILE#*"/Dockerfile."} + IMAGE_NAME="${IMAGE_NAME//./-}-image" + + # Build the base images in layers first + BASE_IMAGE_ARG= + if [ $i -eq $(( ${#DOCKERFILES[@]} - 1 )) ]; then + if [[ ! -z "${BASE_IMAGE_NAME}" ]] ; then + BASE_IMAGE_ARG="--build-arg BASE_IMAGE="${BASE_IMAGE_NAME}"" + fi + fi + + if [ $i -lt $(( ${#DOCKERFILES[@]} - 1 )) ]; then + BASE_DOCKERFILE=${DOCKERFILES[i+1]} + BASE_IMAGE_NAME=${BASE_DOCKERFILE#*"/Dockerfile."} + BASE_IMAGE_NAME="${BASE_IMAGE_NAME//./-}-image" + + BASE_IMAGE_ARG="--build-arg BASE_IMAGE="${BASE_IMAGE_NAME}"" + fi + + # The last image should be the target image name + # Use docker context dir script arg only for last image + DOCKER_CONTEXT_ARG=${DOCKERFILE_CONTEXT_DIR} + if [ $i -eq 0 ]; then + IMAGE_NAME=${TARGET_IMAGE_NAME} + if [[ ! -z "${DOCKER_CONTEXT_DIR}" ]]; then + DOCKER_CONTEXT_ARG=${DOCKER_CONTEXT_DIR} + fi + fi + + print_warning "Building ${DOCKERFILE} as image: ${IMAGE_NAME} with base: ${BASE_IMAGE_NAME}" + + DOCKER_BUILDKIT=${DOCKER_BUILDKIT} docker build -f ${DOCKERFILE} \ + --network host \ + -t ${IMAGE_NAME} \ + ${BASE_IMAGE_ARG} \ + "${BUILD_ARGS[@]}" \ + "${ADDITIONAL_DOCKER_ARGS[@]}" \ + $@ \ + ${DOCKER_CONTEXT_ARG} +done \ No newline at end of file diff --git a/scripts/run_dev.sh b/scripts/run_dev.sh index 9a26f7f..5d7549e 100755 --- a/scripts/run_dev.sh +++ b/scripts/run_dev.sh @@ -24,6 +24,7 @@ DOCKER_DIR="${ROOT}/../docker" BASE_NAME="robomaster-cv" IMAGE_NAME="$BASE_NAME-image" +IMAGE_KEY="ros2_humble.realsense_source.tools.user" CONTAINER_NAME="$BASE_NAME-container" DEV_DIR="../" PLATFORM="$(uname -m)" @@ -95,8 +96,27 @@ if [[ $PLATFORM == "x86_64" ]]; then fi fi -docker build --network host -t ${IMAGE_NAME} "${BUILD_ARGS[@]}" "${DOCKER_DIR}" \ -&& \ +print_info "Building $IMAGE_KEY base as image: $BASE_NAME" +$ROOT/build_image_layers.sh --image_key "$IMAGE_KEY" --image_name "$BASE_NAME" + +# Check result +if [ $? -ne 0 ]; then + if [[ -z $(docker image ls --quiet $BASE_NAME) ]]; then + print_error "Building image failed and no cached image found for $BASE_NAME, aborting." + exit 1 + else + print_warning "Unable to build image, but cached image found." + fi +fi + +# Check image is available +if [[ -z $(docker image ls --quiet $BASE_NAME) ]]; then + print_error "No built image found for $BASE_NAME, aborting." + exit 1 +fi + +# docker build --network host -t ${IMAGE_NAME} "${BUILD_ARGS[@]}" "${DOCKER_DIR}" \ +# && \ MSYS_NO_PATHCONV=1 \ docker run -it --rm \ --privileged \ diff --git a/scripts/run_realsense_camera.sh b/scripts/run_realsense_camera.sh index cab34b3..5553513 100755 --- a/scripts/run_realsense_camera.sh +++ b/scripts/run_realsense_camera.sh @@ -1,4 +1,5 @@ ros2 launch realsense2_camera rs_launch.py rgb_camera.profile:=1280x720x30 depth_module.profile:=1280x720x30 enable_color:=true enable_depth:=true enable_sync:=true camera_namespace:=robot camera_name:=rs2 align_depth.enable:=true enable_rgbd:=true +# ros2 launch realsense2_camera rs_launch.py rgb_camera.profile:=1280x720x30 depth_module.profile:=1280x720x30 enable_color:=true enable_depth:=true enable_sync:=true camera_namespace:=robot camera_name:=rs2 align_depth.enable:=true enable_rgbd:=true rgb_camera.exposure:=15 # ros2 launch realsense2_camera rs_launch.py rgb_camera.profile:=1280x720x30 depth_module.profile:=1280x720x6 enable_color:=true enable_depth:=true camera_namespace:=robot camera_name:=rs2 # ros2 launch realsense2_camera rs_launch.py rgb_camera.profile:=1280x720x30 depth_module.profile:=1280x720x30 enable_rgbd:=true enable_sync:=true align_depth.enable:=true enable_color:=true enable_depth:=true camera_namespace:=robot camera_name:=rs2 # ros2 launch realsense2_camera rs_launch.py rgb_camera.profile:=960x540x60 depth_module.profile:=1280x720x30 enable_rgbd:=true enable_sync:=true align_depth.enable:=true enable_color:=true enable_depth:=true camera_namespace:=robot camera_name:=rs2 diff --git a/scripts/save_camera_bag.sh b/scripts/save_camera_bag.sh new file mode 100755 index 0000000..1a03ba0 --- /dev/null +++ b/scripts/save_camera_bag.sh @@ -0,0 +1,3 @@ +#!/bin/bash +NOW=$( date '+%Y%m%d_%H%M%S' ) +ros2 bag record -e /robot --start-paused -o "$NOW-rosbag" \ No newline at end of file diff --git a/scripts/utils/print_color.sh b/scripts/utils/print_color.sh new file mode 100644 index 0000000..89f8941 --- /dev/null +++ b/scripts/utils/print_color.sh @@ -0,0 +1,17 @@ +function print_color { + tput setaf $1 + echo "$2" + tput sgr0 +} + +function print_error { + print_color 1 "$1" +} + +function print_warning { + print_color 3 "$1" +} + +function print_info { + print_color 2 "$1" +} \ No newline at end of file From a9b52970882733ed3ed87c48832ebfc083b6c428 Mon Sep 17 00:00:00 2001 From: stampede Date: Thu, 10 Oct 2024 18:58:12 -0500 Subject: [PATCH 4/8] allow running on host machine without building from source --- .gitignore | 3 +- scripts/record_rosbag.sh | 3 ++ scripts/run_dev.sh | 71 +++++++++++++++++++++----------------- scripts/save_camera_bag.sh | 3 -- 4 files changed, 45 insertions(+), 35 deletions(-) create mode 100755 scripts/record_rosbag.sh delete mode 100755 scripts/save_camera_bag.sh diff --git a/.gitignore b/.gitignore index 16d4172..5e0b418 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ log/ rosbags/ resources/ src/ros2_benchmark/ -CMakeFiles \ No newline at end of file +CMakeFiles +rosbags/ \ No newline at end of file diff --git a/scripts/record_rosbag.sh b/scripts/record_rosbag.sh new file mode 100755 index 0000000..cd44d04 --- /dev/null +++ b/scripts/record_rosbag.sh @@ -0,0 +1,3 @@ +#!/bin/bash +NOW=$( date '+%Y_%m_%d-%H_%M_%S' ) +ros2 bag record -e /robot --start-paused -o "/robomaster_cv/rosbags/rosbag2_$NOW" \ No newline at end of file diff --git a/scripts/run_dev.sh b/scripts/run_dev.sh index 5d7549e..45c2096 100755 --- a/scripts/run_dev.sh +++ b/scripts/run_dev.sh @@ -24,15 +24,20 @@ DOCKER_DIR="${ROOT}/../docker" BASE_NAME="robomaster-cv" IMAGE_NAME="$BASE_NAME-image" -IMAGE_KEY="ros2_humble.realsense_source.tools.user" CONTAINER_NAME="$BASE_NAME-container" DEV_DIR="../" PLATFORM="$(uname -m)" +MODEL="PC" +if [ -f /proc/device-tree/model ] && [[ "$(cat /proc/device-tree/model)" =~ "Jetson Orin Nano" ]]; then + print_info "Detected Jetson Orin Nano, building librealsense from source" + IMAGE_KEY="ros2_humble.realsense_source.tools.user" + MODEL="JON" +else + print_info "Did not detect Jetson Orin Nano, installing librealsense from package" + IMAGE_KEY="ros2_humble.realsense_pkg.tools.user" +fi + -# Map host's display socket to docker -# This should only happen for non-windows -# DOCKER_ARGS+=("-v /tmp/.X11-unix:/tmp/.X11-unix") -# DOCKER_ARGS+=("-v $HOME/.Xauthority:/home/admin/.Xauthority:rw") DOCKER_ARGS+=("-e DISPLAY") DOCKER_ARGS+=("-e NVIDIA_VISIBLE_DEVICES=all") DOCKER_ARGS+=("-e NVIDIA_DRIVER_CAPABILITIES=all") @@ -41,32 +46,36 @@ DOCKER_ARGS+=("-e USER") # DOCKER_ARGS+=("-e FASTRTPS_DEFAULT_PROFILES_FILE=/usr/local/share/middleware_profiles/rtps_udp_profile.xml") -# TODO @arthur find a way to determine jetson vs not jetson, potentially env variable -# if [[ $PLATFORM == "aarch64" ]]; then -# DOCKER_ARGS+=("-v /usr/bin/tegrastats:/usr/bin/tegrastats") -# DOCKER_ARGS+=("-v /tmp/argus_socket:/tmp/argus_socket") -# DOCKER_ARGS+=("-v /usr/local/cuda-11.4/targets/aarch64-linux/lib/libcusolver.so.11:/usr/local/cuda-11.4/targets/aarch64-linux/lib/libcusolver.so.11") -# DOCKER_ARGS+=("-v /usr/local/cuda-11.4/targets/aarch64-linux/lib/libcusparse.so.11:/usr/local/cuda-11.4/targets/aarch64-linux/lib/libcusparse.so.11") -# DOCKER_ARGS+=("-v /usr/local/cuda-11.4/targets/aarch64-linux/lib/libcurand.so.10:/usr/local/cuda-11.4/targets/aarch64-linux/lib/libcurand.so.10") -# DOCKER_ARGS+=("-v /usr/local/cuda-11.4/targets/aarch64-linux/lib/libcufft.so.10:/usr/local/cuda-11.4/targets/aarch64-linux/lib/libcufft.so.10") -# DOCKER_ARGS+=("-v /usr/local/cuda-11.4/targets/aarch64-linux/lib/libnvToolsExt.so:/usr/local/cuda-11.4/targets/aarch64-linux/lib/libnvToolsExt.so") -# DOCKER_ARGS+=("-v /usr/local/cuda-11.4/targets/aarch64-linux/lib/libcupti.so.11.4:/usr/local/cuda-11.4/targets/aarch64-linux/lib/libcupti.so.11.4") -# DOCKER_ARGS+=("-v /usr/local/cuda-11.4/targets/aarch64-linux/lib/libcudla.so.1:/usr/local/cuda-11.4/targets/aarch64-linux/lib/libcudla.so.1") -# DOCKER_ARGS+=("-v /usr/local/cuda-11.4/targets/aarch64-linux/include/nvToolsExt.h:/usr/local/cuda-11.4/targets/aarch64-linux/include/nvToolsExt.h") -# DOCKER_ARGS+=("-v /usr/lib/aarch64-linux-gnu/tegra:/usr/lib/aarch64-linux-gnu/tegra") -# DOCKER_ARGS+=("-v /usr/src/jetson_multimedia_api:/usr/src/jetson_multimedia_api") -# DOCKER_ARGS+=("-v /opt/nvidia/nsight-systems-cli:/opt/nvidia/nsight-systems-cli") -# DOCKER_ARGS+=("--pid=host") -# DOCKER_ARGS+=("-v /opt/nvidia/vpi2:/opt/nvidia/vpi2") -# DOCKER_ARGS+=("-v /usr/share/vpi2:/usr/share/vpi2") - -# # If jtop present, give the container access -# if [[ $(getent group jtop) ]]; then -# DOCKER_ARGS+=("-v /run/jtop.sock:/run/jtop.sock:ro") -# JETSON_STATS_GID="$(getent group jtop | cut -d: -f3)" -# DOCKER_ARGS+=("--group-add $JETSON_STATS_GID") -# fi -# fi +if [[ $MODEL == "JON" ]]; then + # Map host's display socket to docker + # This should only happen for non-windows + DOCKER_ARGS+=("-v /tmp/.X11-unix:/tmp/.X11-unix") # TODO @arthur can probably forward for linux and/or macOS too + DOCKER_ARGS+=("-v $HOME/.Xauthority:/home/admin/.Xauthority:rw") + + DOCKER_ARGS+=("-v /usr/bin/tegrastats:/usr/bin/tegrastats") + DOCKER_ARGS+=("-v /tmp/argus_socket:/tmp/argus_socket") + DOCKER_ARGS+=("-v /usr/local/cuda-11.4/targets/aarch64-linux/lib/libcusolver.so.11:/usr/local/cuda-11.4/targets/aarch64-linux/lib/libcusolver.so.11") + DOCKER_ARGS+=("-v /usr/local/cuda-11.4/targets/aarch64-linux/lib/libcusparse.so.11:/usr/local/cuda-11.4/targets/aarch64-linux/lib/libcusparse.so.11") + DOCKER_ARGS+=("-v /usr/local/cuda-11.4/targets/aarch64-linux/lib/libcurand.so.10:/usr/local/cuda-11.4/targets/aarch64-linux/lib/libcurand.so.10") + DOCKER_ARGS+=("-v /usr/local/cuda-11.4/targets/aarch64-linux/lib/libcufft.so.10:/usr/local/cuda-11.4/targets/aarch64-linux/lib/libcufft.so.10") + DOCKER_ARGS+=("-v /usr/local/cuda-11.4/targets/aarch64-linux/lib/libnvToolsExt.so:/usr/local/cuda-11.4/targets/aarch64-linux/lib/libnvToolsExt.so") + DOCKER_ARGS+=("-v /usr/local/cuda-11.4/targets/aarch64-linux/lib/libcupti.so.11.4:/usr/local/cuda-11.4/targets/aarch64-linux/lib/libcupti.so.11.4") + DOCKER_ARGS+=("-v /usr/local/cuda-11.4/targets/aarch64-linux/lib/libcudla.so.1:/usr/local/cuda-11.4/targets/aarch64-linux/lib/libcudla.so.1") + DOCKER_ARGS+=("-v /usr/local/cuda-11.4/targets/aarch64-linux/include/nvToolsExt.h:/usr/local/cuda-11.4/targets/aarch64-linux/include/nvToolsExt.h") + DOCKER_ARGS+=("-v /usr/lib/aarch64-linux-gnu/tegra:/usr/lib/aarch64-linux-gnu/tegra") + DOCKER_ARGS+=("-v /usr/src/jetson_multimedia_api:/usr/src/jetson_multimedia_api") + DOCKER_ARGS+=("-v /opt/nvidia/nsight-systems-cli:/opt/nvidia/nsight-systems-cli") + DOCKER_ARGS+=("--pid=host") + DOCKER_ARGS+=("-v /opt/nvidia/vpi2:/opt/nvidia/vpi2") + DOCKER_ARGS+=("-v /usr/share/vpi2:/usr/share/vpi2") + + # If jtop present, give the container access + if [[ $(getent group jtop) ]]; then + DOCKER_ARGS+=("-v /run/jtop.sock:/run/jtop.sock:ro") + JETSON_STATS_GID="$(getent group jtop | cut -d: -f3)" + DOCKER_ARGS+=("--group-add $JETSON_STATS_GID") + fi +fi # Remove any exited containers. if [ "$(docker ps -a --quiet --filter status=exited --filter name=$CONTAINER_NAME)" ]; then diff --git a/scripts/save_camera_bag.sh b/scripts/save_camera_bag.sh deleted file mode 100755 index 1a03ba0..0000000 --- a/scripts/save_camera_bag.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -NOW=$( date '+%Y%m%d_%H%M%S' ) -ros2 bag record -e /robot --start-paused -o "$NOW-rosbag" \ No newline at end of file From d44d7c24f0d5c58f8dc0739e8376be6db0c5b7e9 Mon Sep 17 00:00:00 2001 From: Arthur Zhang Date: Thu, 10 Oct 2024 19:26:24 -0500 Subject: [PATCH 5/8] fixes to run on macOS --- scripts/build_image_layers.sh | 11 ++++++++--- scripts/run_dev.sh | 24 ++++-------------------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/scripts/build_image_layers.sh b/scripts/build_image_layers.sh index 5e2afc2..c8c5dea 100755 --- a/scripts/build_image_layers.sh +++ b/scripts/build_image_layers.sh @@ -55,9 +55,9 @@ if [ ${#CONFIG_DOCKER_SEARCH_DIRS[@]} -gt 0 ]; then fi # Parse command-line args -VALID_ARGS=$(getopt -o hra:b:c:ki:n:d: --long help,skip_registry_check,build_arg:,base_image:,context_dir:,disable_buildkit,image_key:,image_name:,ignore_composite_keys,docker_arg: -- "$@") -eval set -- "$VALID_ARGS" -while [ : ]; do +# VALID_ARGS=$(getopt -o hra:b:c:ki:n:d: --long help,skip_registry_check,build_arg:,base_image:,context_dir:,disable_buildkit,image_key:,image_name:,ignore_composite_keys,docker_arg: -- "$@") +# eval set -- "$VALID_ARGS" +while [[ $# -gt 0 ]]; do case "$1" in -a | --build_arg) ADDITIONAL_BUILD_ARGS+=("$2") @@ -102,10 +102,15 @@ while [ : ]; do --) shift; break ;; + *) + usage + exit 1 + ;; esac done # Check arguments +echo $TARGET_IMAGE_STR if [[ -z "$TARGET_IMAGE_STR" ]]; then print_error "Target image not specified with -i/--image_key" exit 1 diff --git a/scripts/run_dev.sh b/scripts/run_dev.sh index 45c2096..a60fb5d 100755 --- a/scripts/run_dev.sh +++ b/scripts/run_dev.sh @@ -1,24 +1,7 @@ #!/bin/bash -function print_color { - tput setaf $1 - echo "$2" - tput sgr0 -} - -function print_error { - print_color 1 "$1" -} - -function print_warning { - print_color 3 "$1" -} - -function print_info { - print_color 2 "$1" -} - ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +source $ROOT/utils/print_color.sh WORKSPACE_ROOT="${ROOT}/.." DOCKER_DIR="${ROOT}/../docker" @@ -27,7 +10,6 @@ IMAGE_NAME="$BASE_NAME-image" CONTAINER_NAME="$BASE_NAME-container" DEV_DIR="../" PLATFORM="$(uname -m)" -MODEL="PC" if [ -f /proc/device-tree/model ] && [[ "$(cat /proc/device-tree/model)" =~ "Jetson Orin Nano" ]]; then print_info "Detected Jetson Orin Nano, building librealsense from source" IMAGE_KEY="ros2_humble.realsense_source.tools.user" @@ -35,6 +17,7 @@ if [ -f /proc/device-tree/model ] && [[ "$(cat /proc/device-tree/model)" =~ "Jet else print_info "Did not detect Jetson Orin Nano, installing librealsense from package" IMAGE_KEY="ros2_humble.realsense_pkg.tools.user" + MODEL="PC" fi @@ -106,7 +89,8 @@ if [[ $PLATFORM == "x86_64" ]]; then fi print_info "Building $IMAGE_KEY base as image: $BASE_NAME" -$ROOT/build_image_layers.sh --image_key "$IMAGE_KEY" --image_name "$BASE_NAME" +print_info "Running $ROOT/build_image_layers.sh -i \"$IMAGE_KEY\" --image_name \"$BASE_NAME\"" +$ROOT/build_image_layers.sh -i "$IMAGE_KEY" --image_name "$BASE_NAME" -r # Check result if [ $? -ne 0 ]; then From 566f464e5d58c6b4115eba0019e1026716d786af Mon Sep 17 00:00:00 2001 From: stampede Date: Fri, 1 Nov 2024 15:35:08 -0500 Subject: [PATCH 6/8] get realsense working on jon --- docker/Dockerfile.realsense_source | 4 +++- docker/Dockerfile.tools | 3 ++- scripts/run_dev.sh | 7 ++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docker/Dockerfile.realsense_source b/docker/Dockerfile.realsense_source index d21e1d5..a42e150 100644 --- a/docker/Dockerfile.realsense_source +++ b/docker/Dockerfile.realsense_source @@ -14,4 +14,6 @@ RUN /opt/realsense/build-librealsense.sh -n -v ${LIBREALSENSE_SOURCE_VERSION}; # Copy hotplug script for udev rules/hotplug for RealSense RUN mkdir -p /opt/realsense/ COPY scripts/hotplug-realsense.sh /opt/realsense/hotplug-realsense.sh -COPY udev_rules/99-realsense-libusb-custom.rules /etc/udev/rules.d/99-realsense-libusb-custom.udev_rules \ No newline at end of file +RUN chmod +x /opt/realsense/hotplug-realsense.sh +COPY udev_rules/99-realsense-libusb-custom.rules /etc/udev/rules.d/99-realsense-libusb-custom.rules +RUN sudo cp /root/librealsense/config/99-realsense-libusb.rules /etc/udev/rules.d/ \ No newline at end of file diff --git a/docker/Dockerfile.tools b/docker/Dockerfile.tools index a7c90bf..e9d16e1 100644 --- a/docker/Dockerfile.tools +++ b/docker/Dockerfile.tools @@ -7,7 +7,8 @@ RUN apt-get update && apt-get install -y \ nano \ dos2unix \ ffmpeg \ + python3-pip \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean -RUN git clone https://github.com/mlaiacker/rosbag2video.git \ No newline at end of file +RUN pip3 install zstandard \ No newline at end of file diff --git a/scripts/run_dev.sh b/scripts/run_dev.sh index a60fb5d..49f0709 100755 --- a/scripts/run_dev.sh +++ b/scripts/run_dev.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" source $ROOT/utils/print_color.sh WORKSPACE_ROOT="${ROOT}/.." @@ -108,8 +110,6 @@ if [[ -z $(docker image ls --quiet $BASE_NAME) ]]; then exit 1 fi -# docker build --network host -t ${IMAGE_NAME} "${BUILD_ARGS[@]}" "${DOCKER_DIR}" \ -# && \ MSYS_NO_PATHCONV=1 \ docker run -it --rm \ --privileged \ @@ -121,8 +121,9 @@ docker run -it --rm \ --user="admin" \ --entrypoint /usr/local/bin/scripts/workspace-entrypoint.sh \ --workdir /robomaster_cv/ \ + --runtime nvidia \ $@ \ - $IMAGE_NAME \ + $BASE_NAME \ /bin/bash # If we run on jetson, we should add this back From f903f6505a2b74ce29fde2a9adab65db05fa49aa Mon Sep 17 00:00:00 2001 From: Arthur Zhang Date: Sun, 3 Nov 2024 19:10:59 -0600 Subject: [PATCH 7/8] fix runtime --- scripts/run_dev.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/run_dev.sh b/scripts/run_dev.sh index 49f0709..8302eae 100755 --- a/scripts/run_dev.sh +++ b/scripts/run_dev.sh @@ -32,6 +32,8 @@ DOCKER_ARGS+=("-e USER") # DOCKER_ARGS+=("-e FASTRTPS_DEFAULT_PROFILES_FILE=/usr/local/share/middleware_profiles/rtps_udp_profile.xml") if [[ $MODEL == "JON" ]]; then + DOCKER_ARGS+=("--runtime nvidia") + # Map host's display socket to docker # This should only happen for non-windows DOCKER_ARGS+=("-v /tmp/.X11-unix:/tmp/.X11-unix") # TODO @arthur can probably forward for linux and/or macOS too @@ -121,10 +123,6 @@ docker run -it --rm \ --user="admin" \ --entrypoint /usr/local/bin/scripts/workspace-entrypoint.sh \ --workdir /robomaster_cv/ \ - --runtime nvidia \ $@ \ $BASE_NAME \ - /bin/bash - -# If we run on jetson, we should add this back -# --runtime nvidia + /bin/bash \ No newline at end of file From 42d03087d181cf7dbaf0f09aa939a3dc6fdaf30a Mon Sep 17 00:00:00 2001 From: Arthur Zhang <29466864+azhangvo@users.noreply.github.com> Date: Fri, 8 Nov 2024 18:41:53 -0500 Subject: [PATCH 8/8] remove bogus code --- scripts/run_realsense_camera.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/run_realsense_camera.sh b/scripts/run_realsense_camera.sh index 5553513..6a9305f 100755 --- a/scripts/run_realsense_camera.sh +++ b/scripts/run_realsense_camera.sh @@ -1,5 +1,4 @@ ros2 launch realsense2_camera rs_launch.py rgb_camera.profile:=1280x720x30 depth_module.profile:=1280x720x30 enable_color:=true enable_depth:=true enable_sync:=true camera_namespace:=robot camera_name:=rs2 align_depth.enable:=true enable_rgbd:=true -# ros2 launch realsense2_camera rs_launch.py rgb_camera.profile:=1280x720x30 depth_module.profile:=1280x720x30 enable_color:=true enable_depth:=true enable_sync:=true camera_namespace:=robot camera_name:=rs2 align_depth.enable:=true enable_rgbd:=true rgb_camera.exposure:=15 # ros2 launch realsense2_camera rs_launch.py rgb_camera.profile:=1280x720x30 depth_module.profile:=1280x720x6 enable_color:=true enable_depth:=true camera_namespace:=robot camera_name:=rs2 # ros2 launch realsense2_camera rs_launch.py rgb_camera.profile:=1280x720x30 depth_module.profile:=1280x720x30 enable_rgbd:=true enable_sync:=true align_depth.enable:=true enable_color:=true enable_depth:=true camera_namespace:=robot camera_name:=rs2 # ros2 launch realsense2_camera rs_launch.py rgb_camera.profile:=960x540x60 depth_module.profile:=1280x720x30 enable_rgbd:=true enable_sync:=true align_depth.enable:=true enable_color:=true enable_depth:=true camera_namespace:=robot camera_name:=rs2 @@ -78,4 +77,4 @@ ros2 launch realsense2_camera rs_launch.py rgb_camera.profile:=1280x720x30 depth # 848x480x30 # 848x480x6 # 848x480x60 -# 848x480x90 \ No newline at end of file +# 848x480x90