From 1e2e9c8dbcec4bc040522fb9c69c11d6fb1f4ddf Mon Sep 17 00:00:00 2001 From: Luis Poveda Cano Date: Tue, 14 Apr 2026 16:49:03 +0200 Subject: [PATCH 1/2] Added `--distro` and `--rmw` arguments to `run_rviz.sh` to be able to run the example with ROS2 distros `Humble` and `Jazzy` and RMW `FastDDS` and `CycloneDDS` --- PythonAPI/examples/ros2/Dockerfile | 15 ++++ PythonAPI/examples/ros2/config/cyclonedds.xml | 10 +++ PythonAPI/examples/ros2/run_rviz.sh | 90 +++++++++++++++++-- 3 files changed, 107 insertions(+), 8 deletions(-) create mode 100644 PythonAPI/examples/ros2/Dockerfile create mode 100644 PythonAPI/examples/ros2/config/cyclonedds.xml diff --git a/PythonAPI/examples/ros2/Dockerfile b/PythonAPI/examples/ros2/Dockerfile new file mode 100644 index 00000000000..c3b10b044bc --- /dev/null +++ b/PythonAPI/examples/ros2/Dockerfile @@ -0,0 +1,15 @@ +ARG ROS_DISTRO=humble +FROM osrf/ros:${ROS_DISTRO}-desktop + +ARG ROS_DISTRO=humble +ARG RMW_IMPLEMENTATION=rmw_fastrtps_cpp + +# Install CycloneDDS middleware package when selected; FastDDS is already in the base image +RUN if [ "$RMW_IMPLEMENTATION" = "rmw_cyclonedds_cpp" ]; then \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + ros-${ROS_DISTRO}-rmw-cyclonedds-cpp \ + && rm -rf /var/lib/apt/lists/*; \ + fi + +ENV RMW_IMPLEMENTATION=${RMW_IMPLEMENTATION} diff --git a/PythonAPI/examples/ros2/config/cyclonedds.xml b/PythonAPI/examples/ros2/config/cyclonedds.xml new file mode 100644 index 00000000000..fd9817dca09 --- /dev/null +++ b/PythonAPI/examples/ros2/config/cyclonedds.xml @@ -0,0 +1,10 @@ + + + + + false + + + diff --git a/PythonAPI/examples/ros2/run_rviz.sh b/PythonAPI/examples/ros2/run_rviz.sh index 542f0e960dd..4e09f539046 100755 --- a/PythonAPI/examples/ros2/run_rviz.sh +++ b/PythonAPI/examples/ros2/run_rviz.sh @@ -1,24 +1,98 @@ #!/bin/bash +set -euo pipefail + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -function transfer_x11_permissions() { - # store X11 access rights in temp file to be passed into docker container - XAUTH=/tmp/.docker.xauth - touch $XAUTH - xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge - +# --- Defaults --- +DISTRO="humble" +RMW="fastdds" + +# --- Argument parsing --- +usage() { + cat <] [--rmw=] + +Options: + --distro ROS 2 distribution to use. Supported: humble, jazzy (default: humble) + --rmw DDS middleware to use. Supported: fastdds, cyclonedds (default: fastdds) + +Examples: + $0 --distro=humble --rmw=fastdds + $0 --distro=jazzy --rmw=cyclonedds +EOF + exit 1 +} + +for arg in "$@"; do + case "$arg" in + --distro=*) DISTRO="${arg#*=}" ;; + --rmw=*) RMW="${arg#*=}" ;; + --help|-h) usage ;; + *) echo "Unknown argument: $arg"; usage ;; + esac +done + +# --- Validate --- +case "$DISTRO" in + humble|jazzy) ;; + *) echo "Unsupported distro '${DISTRO}'. Supported values: humble, jazzy"; exit 1 ;; +esac + +case "$RMW" in + fastdds|cyclonedds) ;; + *) echo "Unsupported RMW '${RMW}'. Supported values: fastdds, cyclonedds"; exit 1 ;; +esac + +# Map short names to ROS RMW implementation identifiers +if [ "$RMW" = "cyclonedds" ]; then + RMW_IMPLEMENTATION="rmw_cyclonedds_cpp" +else + RMW_IMPLEMENTATION="rmw_fastrtps_cpp" +fi + +IMAGE_NAME="carla-rviz-${DISTRO}-${RMW}" + +# --- Build --- +function build_image() { + echo "[RViz] Building Docker image '${IMAGE_NAME}' (distro=${DISTRO}, rmw=${RMW})..." + docker build \ + --build-arg ROS_DISTRO="${DISTRO}" \ + --build-arg RMW_IMPLEMENTATION="${RMW_IMPLEMENTATION}" \ + --file "${SCRIPT_DIR}/Dockerfile" \ + --tag "${IMAGE_NAME}" \ + "${SCRIPT_DIR}" } -transfer_x11_permissions +if ! docker image inspect "${IMAGE_NAME}" &>/dev/null; then + build_image +fi + +# --- X11 permissions --- +XAUTH=/tmp/.docker.xauth +touch "$XAUTH" +xauth nlist "$DISPLAY" | sed -e 's/^..../ffff/' | xauth -f "$XAUTH" nmerge - + +# --- RMW-specific environment variables --- +EXTRA_ENV=() +if [ "$RMW" = "cyclonedds" ]; then + EXTRA_ENV+=(--env="CYCLONEDDS_URI=/config/cyclonedds.xml") +else + EXTRA_ENV+=(--env="FASTRTPS_DEFAULT_PROFILES_FILE=/config/fastrtps-profile.xml") +fi + +# --- Run --- +echo "[RViz] Launching RViz2 (distro=${DISTRO}, rmw=${RMW})..." docker run \ --rm \ --net=host \ --env="DISPLAY=$DISPLAY" \ --env="XAUTHORITY=$XAUTH" \ - --env="FASTRTPS_DEFAULT_PROFILES_FILE=/config/fastrtps-profile.xml" \ + --env="RMW_IMPLEMENTATION=${RMW_IMPLEMENTATION}" \ + "${EXTRA_ENV[@]}" \ --volume="${SCRIPT_DIR}/config:/config:ro" \ --volume="${SCRIPT_DIR}/rviz:/rviz:rw" \ --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \ --volume="$XAUTH:$XAUTH" \ - osrf/ros:humble-desktop \ + "${IMAGE_NAME}" \ ros2 run rviz2 rviz2 -d /rviz/ros2_native.rviz From 4909c66bd40e4e804976c494ab91c6a5052c82a1 Mon Sep 17 00:00:00 2001 From: Luis Poveda Cano Date: Tue, 14 Apr 2026 18:13:09 +0200 Subject: [PATCH 2/2] add udp transport to cyclonedds config file --- PythonAPI/examples/ros2/config/cyclonedds.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PythonAPI/examples/ros2/config/cyclonedds.xml b/PythonAPI/examples/ros2/config/cyclonedds.xml index fd9817dca09..c5e8783b9d4 100644 --- a/PythonAPI/examples/ros2/config/cyclonedds.xml +++ b/PythonAPI/examples/ros2/config/cyclonedds.xml @@ -6,5 +6,8 @@ false + + udp +