Skip to content

Add refereed multi-robot matches - #38

Merged
papazed merged 22 commits into
NUbots:mainfrom
papazed:layton/sim-match
Nov 14, 2026
Merged

papazed merged 22 commits into
NUbots:mainfrom
papazed:layton/sim-match

Conversation

@papazed

@papazed papazed commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Part of #10.

./b match --game N runs an N-a-side match (1 to 3) with stock NUbots players, an embedded GameController and an automatic referee. See mujoco/module/MatchReferee/README.md and the "Refereed matches" section of the root README.

Built on the multi-robot work by Oliver Obst and Zijie Li (rUNSWift), from UNSWComputing/NUSim branch feature/multi-robot-ground-truth, which isn't on main yet. Thanks to both of them.

A follow-up PR will change a lot of this code, so detailed review can wait for that one.

test_supervisor fails here the same way it does on main since #37.

🤖 Generated with Claude Code

vincenttumminello and others added 20 commits September 19, 2026 17:27
Merging main (e4acc8b) spliced a second, older copy of the file into the
middle of publish(), nesting function definitions inside it, so the sdkbridge
module no longer compiled. Restore the pre-merge contents (rt/odom included)
in main's formatting.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DyRrq9GsES4TwVCpGM4rLF
The scene keeps the ball body at the world origin and its sphere geom 1.38 m
away, so zero-padded inherited keyframes still put the ball on its spot.
MuJoCo integrates a free body's origin linearly and its rotation separately,
so a spinning ball's centre drifts ~0.5 (w dt)^2 |offset| per step: a ball
rolled at 3 m/s sank into the floor within 50 ms and the contact launched it
to 68 m/s. Kicked balls in NUSim hit the same failure.

SimCore now loads every scene through mjSpec (robots == 1 attaches no
copies) and moves the ball body's origin onto its sphere before compiling,
so the collision bounding volumes stay consistent, then shifts each
keyframe's ball position by the rotated offset so every keyframe still rests
the ball exactly where it did. The supervisor test loads the scene the same
way and checks that no keyframe moved the ball.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DyRrq9GsES4TwVCpGM4rLF
NUSim-only test surface (PROTOCOL.md §6), all nav_msgs/Odometry so no new
IDL on either side:

- rt/nusim/gt/ball, rt/nusim/gt/robot: world-frame pose and twist at the
  50 Hz state cadence, stamped with the wall clock of the physics snapshot,
  for validating NUbots estimators against the simulator.
- rt/nusim/ball_command: place the ball and set its velocity in the world
  or the robot's yaw frame, optionally with the spin for rolling without
  slipping. The Supervisor applies it under the sim mutex, whether or not
  GameController placement is enabled.

The ball's centre velocity is computed from qpos/qvel through the geom
offset (freebody::geom_centre_state), so it stays exact however the body is
laid out. The supervisor test covers placement, the robot frame, rolling
spin, agreement with mj_objectVelocity, and that a rolled ball keeps its
speed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DyRrq9GsES4TwVCpGM4rLF
The real K1 head camera ("Left Camera") is 544x448, rectilinear, with a
normalised focal length of 0.3725: 106.6 deg horizontal, 95.7 deg vertical and
120.2 deg diagonal field of view. NUSim rendered 640x480 at fovy 70 (about
86 deg horizontal), so the robot saw a narrower, differently framed image than
on hardware, which biases anything validated through the vision chain (ball
detection range, how long a ball stays in view). Set the MJCF camera's fovy to
95.7 and the render size to 544x448; the camera now reports focal_length_norm
0.3727 and a 120.2 deg diagonal.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DyRrq9GsES4TwVCpGM4rLF
Every visual mesh was near-white (0.92), so when the head looked down to the
side the robot's own white hand and forearm filled the corner of the image and
YOLO took it for a ball: 55% of detections in the ball-localisation benchmark
were this self-detection, and the ball filter locked onto it. The real K1's
arms, legs, feet and head are black; only the chest is light. Colour the arm,
leg, foot and Head_1 meshes dark (as Head_2 already was) and keep the trunk
light. False positives in the benchmark drop to 4.7%.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DyRrq9GsES4TwVCpGM4rLF
…-shooter'

# Conflicts:
#	mujoco/module/SdkBridge/CMakeLists.txt
Keep the default network and shared-memory transport unchanged. Exercise the loopback option alongside the existing modes in the DDS transport test.

Validation: all 12 native NUSim CTests passed.
SdkBridge now loads the odometry error model on startup, so the test's
isolated config directory needs it too.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
rt/nusim/gt/robot in each robot domain must carry only that robot's pose
(the robots spawn ~3 m apart, so a leaked sample lands on the wrong side),
and the shared ball reaches every domain. test_ground_truth now asserts
the ball body origin is on its sphere, as Tum's re-origination guarantees.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Run a game inside the sim: sim/match embeds the GameController and its
automatic referee, and ./b match starts a hidden NUbots process for each
robot, with no NUbots_K1 changes. Each container gets a FastDDS portBase
for the robot's domain, its own camera segment and the sim's field.

MatchCameras renders a head camera per robot on the GPU, through EGL's
device platform, as EGL_DEFAULT_DISPLAY falls back to the CPU on Wayland.
The window gains a panel with the score and buttons, robot labels and a
message box. Under --game, odometry starts from each robot's start pose,
as NUbots otherwise reverses a robot that starts facing -x.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013cqGHWCjYQTmXB156komSD
Explain where this branch comes from (rUNSWift's multi-robot work), which
repositories a match needs, and how to set up and run ./b match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@sebastianbrooker2 sebastianbrooker2 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved as its a prerequisuite for my pr

@papazed
papazed merged commit 5e5ce2a into NUbots:main Nov 14, 2026
1 of 2 checks passed
papazed and others added 2 commits November 15, 2026 02:16
The rUNSWift branch carried an early copy of NUbots#18 (ball ground truth and
ball commands). Conflicts keep rUNSWift's per-robot versions and take
main's formatting, comments and BallCommandReader teardown fix. NUbots#37's
place_ball() replaces the old centre-mark placement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since NUbots#37 the scene ball sits on its geom at the rest point and the
keyframes zero-pad it, with SimCore::place_ball putting it back. The
old test still expected the geom offset and failed on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants