diff --git a/.dockerignore b/.dockerignore index 98f5b7a..3ae2e6f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,6 +7,7 @@ # docker/scripts/package_humble_runtime.py IsaacDockerfile # docker/locks/** every Dockerfile # docker/patches/** RobocasaDockerfile +# docker/mac/vnc_display.sh mac/RosDockerfile # Their .git entries stay out. * !core_ws @@ -30,3 +31,6 @@ docker/scripts/* !docker/locks/** !docker/patches !docker/patches/** +!docker/mac +docker/mac/* +!docker/mac/vnc_display.sh diff --git a/CLAUDE.md b/CLAUDE.md index a54657c..0eea89d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -94,7 +94,7 @@ launch bringup**. `docker/scripts/docker_common.sh` owns this, and the platform too: on Darwin arm64 (or `GOLEM_PLATFORM=mac`) every wrapper adds `docker-compose.mac.yml` (the arm64 images of `docker/mac/`, no NVIDIA runtime, `GOLEM_RENDER=cpu`, -`GOLEM_LIDAR_POINTS` 6000 for the H1-2 and 10000 for the G1 unless set), refuses Isaac, and `docker_stack.sh` starts `h12_mac_sim` or +`GOLEM_LIDAR_POINTS` 6000 for the H1-2 and 10000 for the G1 unless set; RViz on a virtual display, at `http://localhost:6080/vnc.html`), refuses Isaac, and `docker_stack.sh` starts `h12_mac_sim` or `g1_mac_sim`; on Linux nothing changes (`docs/MAC.md`). On simulator and stack wrappers, the robot is `--g1`/`--h12` on the wrapper, else `GOLEM_ROBOT` from the shell, else from `docker/.env`, else `h12`. The selection means "which robot is diff --git a/core_ws/src/golem_bringup/launch/g1/g1_mac_sim.launch.py b/core_ws/src/golem_bringup/launch/g1/g1_mac_sim.launch.py index 3d1052a..552aeab 100644 --- a/core_ws/src/golem_bringup/launch/g1/g1_mac_sim.launch.py +++ b/core_ws/src/golem_bringup/launch/g1/g1_mac_sim.launch.py @@ -1,7 +1,7 @@ """ Start the G1 against the Mac's RoboCasa sim: g1_sim without skills or the hand driver. - ros2 launch golem_bringup g1_mac_sim.launch.py [use_hands:=true] [use_rviz:=true] + ros2 launch golem_bringup g1_mac_sim.launch.py [use_hands:=true] [use_rviz:=false] The Mac sim (docker/docker-compose.mac.yml, docs/MAC.md) renders on the CPU and casts its MID-360 on the CPU, and an 8-core Mac holds real time only without the Dex3-1 hand @@ -23,8 +23,9 @@ def generate_launch_description(): """Declare the Mac bringup's arguments and include g1_sim without skills.""" return LaunchDescription([ - DeclareLaunchArgument('use_rviz', default_value='false', - description='true: start RViz (needs a display in golem_ros)'), + DeclareLaunchArgument('use_rviz', default_value='true', + description='true: start RViz, on the Mac golem_ros display ' + '(http://localhost:6080/vnc.html); false: none'), DeclareLaunchArgument('use_hands', default_value='false', description='true: start dex3_hands, the Dex3-1 hand driver ' '(about a quarter of a core: the stack then falls ' diff --git a/core_ws/src/golem_bringup/launch/h12/h12_mac_sim.launch.py b/core_ws/src/golem_bringup/launch/h12/h12_mac_sim.launch.py index 41f336d..a1ea6a3 100644 --- a/core_ws/src/golem_bringup/launch/h12/h12_mac_sim.launch.py +++ b/core_ws/src/golem_bringup/launch/h12/h12_mac_sim.launch.py @@ -28,8 +28,9 @@ def generate_launch_description(): """Declare the Mac bringup's arguments and include h12_sim without vision.""" return LaunchDescription([ - DeclareLaunchArgument('use_rviz', default_value='false', - description='true: start RViz (needs a display in golem_ros)'), + DeclareLaunchArgument('use_rviz', default_value='true', + description='true: start RViz, on the Mac golem_ros display ' + '(http://localhost:6080/vnc.html); false: none'), DeclareLaunchArgument('policy', default_value='almi', description='The policy golem_lowerbody_rl runs on the legs: ' 'almi, fame or walk; any other is refused'), diff --git a/core_ws/src/golem_bringup/test/test_sim_time.py b/core_ws/src/golem_bringup/test/test_sim_time.py index fb60ca4..677938a 100644 --- a/core_ws/src/golem_bringup/test/test_sim_time.py +++ b/core_ws/src/golem_bringup/test/test_sim_time.py @@ -147,9 +147,9 @@ def _packages(launch_file, args): @pytest.mark.parametrize('mac_file, sim_file, sim_args, core', [ - ('h12_mac_sim.launch.py', 'h12_sim.launch.py', {'use_rviz': 'false'}, + ('h12_mac_sim.launch.py', 'h12_sim.launch.py', {'use_rviz': 'true'}, {'golem_safety', 'golem_upper_ik', 'golem_lowerbody_rl', 'estop', 'fast_lio', 'golem_slam'}), - ('g1_mac_sim.launch.py', 'g1_sim.launch.py', {'use_rviz': 'false'}, + ('g1_mac_sim.launch.py', 'g1_sim.launch.py', {'use_rviz': 'true'}, {'golem_safety', 'golem_upper_ik', 'golem_lowerbody_rl', 'fast_lio', 'golem_slam'}), ]) def test_mac_sim_is_the_sim_bringup_without_vision(mac_file, sim_file, sim_args, core, diff --git a/docker/docker-compose.mac.yml b/docker/docker-compose.mac.yml index 643f84a..c383443 100644 --- a/docker/docker-compose.mac.yml +++ b/docker/docker-compose.mac.yml @@ -37,6 +37,14 @@ services: runtime: !reset null shm_size: 2g environment: + # RViz draws on the Xvfb display docker/mac/vnc_display.sh starts, shown + # at http://localhost:6080/vnc.html (docs/MAC.md); GOLEM_VNC=0 starts none. + DISPLAY: ":99" + GOLEM_VNC: ${GOLEM_VNC:-1} + GOLEM_VNC_SIZE: ${GOLEM_VNC_SIZE:-1280x800} + # Mesa's software OpenGL draws RViz on one thread: on every core it takes + # about 1.5 of them and the stack falls below real time (docs/MAC.md). + LP_NUM_THREADS: ${LP_NUM_THREADS:-1} # core_ws/cyclonedds.xml, then an override of its 16 MB minimum UDP # receive buffer: the minimum makes every ROS node fail to create its # domain unless the kernel's net.core.rmem_max allows it, which the diff --git a/docker/mac/RosDockerfile b/docker/mac/RosDockerfile index dd024b0..942a40a 100644 --- a/docker/mac/RosDockerfile +++ b/docker/mac/RosDockerfile @@ -159,3 +159,12 @@ RUN rm -rf /usr/local/lib/python3.10/dist-packages/setuptools \ && pip install -c /opt/golem-locks/ros-arm64-06.txt --no-cache-dir --no-deps "numpy<2" "setuptools==59.6.0" "wheel<0.44" \ && rm -f /usr/local/lib/python3.10/dist-packages/distutils-precedence.pth \ && python3 -c "import setuptools, wheel, numpy; assert setuptools.__version__ == '59.6.0', setuptools.__version__; assert numpy.__version__.startswith('1.'), numpy.__version__; print('clamp ok:', setuptools.__version__, wheel.__version__, numpy.__version__)" + +# RViz's display: Xvfb with Mesa's software OpenGL, shown over VNC (x11vnc) and +# in a browser (noVNC on websockify), started by vnc_display.sh, the entrypoint. +# A Mac has no X server a container can render OpenGL through (docs/MAC.md). +RUN apt-get update && apt-get install -y --no-install-recommends \ + xvfb x11vnc novnc python3-websockify \ + && rm -rf /var/lib/apt/lists/* +COPY docker/mac/vnc_display.sh /opt/golem/vnc_display.sh +ENTRYPOINT ["/opt/golem/vnc_display.sh"] diff --git a/docker/mac/vnc_display.sh b/docker/mac/vnc_display.sh new file mode 100755 index 0000000..e5d959b --- /dev/null +++ b/docker/mac/vnc_display.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# Start a virtual X display for RViz in the Mac golem_ros container, then run +# the container's command. +# +# Usage: the Mac golem_ros image's ENTRYPOINT (docker/mac/RosDockerfile): +# vnc_display.sh +# A Mac has no X server a container can render through (XQuartz gives no +# OpenGL on Apple Silicon), so RViz draws on Xvfb display :99 with Mesa's +# software OpenGL (llvmpipe), shown by x11vnc on port 5901 and by noVNC in a +# browser on port 6080. The containers run on the VM's host network, which +# OrbStack and Docker Desktop forward to the Mac's localhost: +# http://localhost:6080/vnc.html or vnc://localhost:5901 (Screen Sharing) +# Environment: DISPLAY (:99, docker-compose.mac.yml); GOLEM_VNC=0 starts no +# display (the command still runs); GOLEM_VNC_SIZE (default 1280x800, docker-compose.mac.yml). +# Exit status: the command's. A display that fails to start is logged and the +# command runs anyway: RViz then fails alone. +set -u + +# Start Xvfb, x11vnc and noVNC in the background, once per container. +start_display() { + local display=${DISPLAY:-:99} size=${GOLEM_VNC_SIZE:-1280x800} + local n=${display#:} + # A container restarted with `docker restart` keeps its /tmp, and a stale + # lock makes Xvfb refuse the display. + if [ -e "/tmp/.X${n}-lock" ] && ! pgrep -x Xvfb >/dev/null; then + rm -f "/tmp/.X${n}-lock" "/tmp/.X11-unix/X${n}" + fi + pgrep -x Xvfb >/dev/null && return 0 + Xvfb "$display" -screen 0 "${size}x24" -nolisten tcp >/tmp/xvfb.log 2>&1 & + # Wait up to 5 s for the display's socket. + for _ in $(seq 50); do [ -S "/tmp/.X11-unix/X${n}" ] && break; sleep 0.1; done + if [ ! -S "/tmp/.X11-unix/X${n}" ]; then + echo "vnc_display: Xvfb did not start on $display (/tmp/xvfb.log)" >&2 + return 0 + fi + # No password: the VM's network is reachable only from the Mac. + x11vnc -display "$display" -rfbport 5901 -forever -shared -nopw -quiet \ + >/tmp/x11vnc.log 2>&1 & + websockify --web /usr/share/novnc 6080 localhost:5901 >/tmp/novnc.log 2>&1 & + echo "vnc_display: RViz on http://localhost:6080/vnc.html (or vnc://localhost:5901)" >&2 +} + +[ "${GOLEM_VNC:-1}" = 0 ] || start_display +exec "$@" diff --git a/docker/scripts/docker_stack.sh b/docker/scripts/docker_stack.sh index e61dec0..8453004 100755 --- a/docker/scripts/docker_stack.sh +++ b/docker/scripts/docker_stack.sh @@ -88,7 +88,8 @@ if [ "$SIM" = robocasa ]; then "${COMPOSE[@]}" run --rm -T -e GOLEM_PREPARE_ONLY=1 robocasa fi # Add the stack overlay (wait for the sim, then bringup). -if [ -n "${DISPLAY:-}" ]; then +# The Mac's golem_ros always has a display for it (docker/mac/vnc_display.sh). +if [ -n "${DISPLAY:-}" ] || [ "$GOLEM_PLATFORM" = mac ]; then export GOLEM_USE_RVIZ=${GOLEM_USE_RVIZ:-true} else export GOLEM_USE_RVIZ=${GOLEM_USE_RVIZ:-false} diff --git a/docs/MAC.md b/docs/MAC.md index b8d182b..ad3c11e 100644 --- a/docs/MAC.md +++ b/docs/MAC.md @@ -17,7 +17,7 @@ bringup and navigation away from the lab machines; the closed-loop tests | Compose | `docker/docker-compose.yml` | the same, plus `docker/docker-compose.mac.yml` (no NVIDIA runtime) | | Sim rendering | EGL on the GPU (`GOLEM_RENDER=gpu`) | OSMesa on the CPU (`GOLEM_RENDER=cpu`); cameras off by default (`GOLEM_CAMERAS=0`) | | MID-360 lidar | cast on the GPU (`mid360.GpuCaster`), 20,000 points a frame | cast exactly on the CPU (`mid360.CpuCaster`); `GOLEM_LIDAR_POINTS` 6,000 (H1-2) or 10,000 (G1) a frame by default | -| Bringup | `h12_sim`, `g1_sim` | `h12_mac_sim`, `g1_mac_sim`: the sim bringups without model servers or skills; the G1's without the hand driver (`use_hands:=true` adds it) | +| Bringup | `h12_sim`, `g1_sim` | `h12_mac_sim`, `g1_mac_sim`: the sim bringups without model servers or skills; the G1's without the hand driver (`use_hands:=true` adds it); RViz on a virtual display, in a browser at `localhost:6080` | | Not available | — | Isaac, `golem_skills`, the model servers (GraspGenX has no CPU path) | The wrappers pick the Mac by themselves on Darwin arm64 (`GOLEM_PLATFORM=mac`; @@ -58,6 +58,16 @@ as on x86 ([Navigation demo](NAVIGATION_DEMO.md)). The three-terminal flow of [Running the stack](RUNNING.md) works too (`docker_run.sh robocasa --g1`, then `ros2 launch golem_bringup g1_mac_sim.launch.py` in `golem_ros`). +**RViz.** The Mac bringups start RViz by default (`use_rviz:=false` leaves it +out). A Mac has no X server a container can draw OpenGL through, so the +`golem_ros` container draws on a virtual display (Xvfb, Mesa's software OpenGL) +that `docker/mac/vnc_display.sh` starts with the container. Open it in a +browser at , or in Screen Sharing at +`vnc://localhost:5901`. Software OpenGL draws on one thread (`LP_NUM_THREADS=1`): +on every core RViz takes about 1.5 of them and the H1-2's stack falls to +0.78-0.83x; on one it holds 0.98-1.00x. `GOLEM_VNC=0` starts no display, and +`GOLEM_VNC_SIZE` sets its size (default `1280x800`). + ## Measured speed Measured 2026-11-19 on a MacBook Air M3 (4 performance + 4 efficiency cores,