A video-game-style driver trainer for FRC 5735's 2026 robot (REBUILT). The driver drives the real robot code — same controller, same bindings, same drive tuning — in WPILib simulation, while a Unity game shows the field from the driver station, simulates fuel and scoring, and runs matches.
Unity game (unity/DriverSim): menus, controller / keyboard input, field, fuel, scoring, HUD, driver-station camera,
collisions (optional: the sim runs without it)
▲ NetworkTables 4 (/DriverSim/*): true robot state, robot's own estimate, │ virtual Xbox controller, commands,
│ match state, rumble │ collision corrections (move + turn)
│ ▼
FRC-2026 robot code in WPILib sim; each subsystem's simulationPeriodic() = ground truth (no Unity knowledge)
• DrivetrainSubsystem: the true pose, from the simulated swerve modules; pushed by Unity's collisions
• Turret, Hood, Launcher, Intake, SpinDex, Climber subsystems: WPILib sims -> Talon / Spark / DIO / analog sensors
• LimelightSubsystem: true pose + noise -> Limelight NetworkTables
+ Fieldrunner bridge (this repo, sim-only Java) = the driver station and the game link
• driver station: the game's controller becomes joystick port 0; enable, mode, alliance station, pauses
• field system: match timing, game message, hub shifts
• game hooks: robot placement, collision corrections into the true pose, flywheel loss per shot
The robot code owns robot motion (CTRE's swerve sim), so drive feel matches the real robot. The sim in the robot code
owns what is true (where the robot really is, how every mechanism really moves); the robot code only sees sensors, so
its pose estimate can be wrong (a reset, a wall hit, gyro drift) without moving the real robot. The game owns the rest
of the world (fuel, field, collisions, scoring) and feeds collisions back into the truth. Plain ./gradlew simulateJava
runs the same sim with no Unity: SimTruth and the robot's estimate show up side by side in Glass or AdvantageScope.
Bridge Java and Unity C# follow the team style guide, FRC/STYLE.md; Java is formatted with
clang-format and the team's .clang-format (scripts/format.java.sh). See CLAUDE.md for how the rules map to C#. Code
added to the robot repo (each subsystem's sim) follows that repo's own style, written down in
docs/specs/frc-2026-style.md.
| Phase | What | State |
|---|---|---|
| 1 | Repo, Gradle hook, bridge, mechanism sim, match control, self-test | done |
| 2 | Unity core: NT4 client, field, robot, driver-station camera | done |
| 3 | Collisions: walls, hub, tower, trench, bumps | done |
| 3b | Game shell: title, station picker, pause, controls and options screens; controller and keyboard input; the bridge is the driver station (no sim GUI) | done |
| 3c | Controllers screen: choose which device drives (keyboard or one controller) | done |
| 3d | Sim truth: ground truth (pose, mechanisms, Limelight) in each robot-code subsystem's simulationPeriodic(); collisions turn and slow the true robot; the bridge is only the game link |
done |
| 4 | Gameplay: fuel, intake, shooting, scoring, HUD | done |
| 5 | Packaging: Windows/Linux builds, run scripts |
bridge/src/main/java/driversim/ bridge (compiled inside the robot project as the "driverSim" source set)
DriverSimMain.java entry point: builds Robot like frc.robot.Main, attaches the bridge
DriverSimBridge.java per-loop glue: commands, placement, corrections, DS, publishing
SelfTest.java scripted headless check against the real robot code
InputOwner.java who supplies joystick input: game, gui or selftest
game/ match controller, NT topics and layouts, command parser, joystick link, pose corrector
tools/NtProbe.java CLI that connects like the game does
bridge/src/test/java/ unit tests for the pure logic
../FRC-2026/src/main/java/frc/robot/subsystems/ ground truth in the robot code: each subsystem's simulationPeriodic() and fr methods
gradle/driversim.gradle applied from the robot project's build.gradle
unity/DriverSim/ Unity 6 (6000.6.8f1) URP project
Assets/DriverSim/Scripts/ game code: Net/ (NT4 client, protocol), Field/ (frame, obstacle layout), Robot/ (model, collision, pusher), Game/ (flow, input, menus, fuel, shot model, scoring, HUD), Util/
Assets/DriverSim/UI/ menu layout (DriverSim.uxml), style (DriverSim.uss), panel settings
Assets/DriverSim/Input/ DriverControls.inputactions (generated by DriverControlsBuilder from RobotControlsLayout)
Assets/DriverSim/Editor/ SceneBuilder (scene is generated from code), DriverControlsBuilder, BuildPlayers
Assets/ThirdParty/AdvantageScope/ 2026 field model (BSD-3, see its LICENSE.txt)
scripts/build-unity.sh batch-mode build: linux | windows | mac | all | scene
scripts/capture-screenshots.sh run sim + game, drive with probe commands, save screenshots
docs/screenshots/ current renders
- Clone this repo (https://github.com/team5735/Fieldrunner) as
Fieldrunnernext toFRC-2026(same parent folder). On FRC-2026, use branchfeature/driver-sim, which carries the per-subsystem sims and whosebuild.gradleends with one guarded line:if (file('../Fieldrunner/gradle/driversim.gradle').exists()) { apply from: '../Fieldrunner/gradle/driversim.gradle' } - A JDK 17 (the WPILib 2026 one is fine). Gradle downloads everything else.
- For the game (phase 2+): Unity Hub + Unity 6 LTS (6000.0.x) with Linux, Windows and/or Mac Build Support (Mono).
More renders, in build order: docs/screenshots.
./gradlew simulateDriverSim opens one window, the game, at a title screen: Start Match or Free Practice (each asks
for a driver station first), Controls, Controllers, Options, Quit. The camera stands behind the selected station and faces the field
center. Esc (or Start then Back on a controller, held half a second) pauses; the pause menu has Resume, Restart Match,
Reset Robot, Controls, Controllers, Options and Quit to Title. Closing the game (Quit, F10 or the window) ends the
simulateDriverSim session: the game sends quit and the robot sim exits cleanly.
Build it with scripts/build-unity.sh (Linux; windows / mac / all for the others) — the project must not be
open in the editor. Any host builds all three; the Mac app is universal (Intel and Apple Silicon). ./gradlew simulateDriverSim then starts it automatically.
Game hotkeys (kept off the keys the robot uses, since the keyboard is also a robot controller): Esc pause / back,
F1 details panel, F2 obstacle collider overlay, F3 driver / overhead view, F4 / F5 field of view narrower / wider,
F6 reset robot to its start spot, F7 respawn all fuel (free practice), F8 drop a ball a meter in front of the robot
(development builds only), F10 quit. Game arguments (also via DRIVERSIM_GAME_ARGS): --nt-host <host>,
--start-in title|practice|match (default title; practice and match skip the menus), --station <B1..R3>,
--view overhead, --show-colliders, --screenshot-menu title|station|controls|controllers|options|pause|disconnected|toast
(opens that screen, for captures), --collision-selftest (feeds synthetic poses to the collision code, logs
[Driver-Sim collision-selftest] PASS|FAIL ... to the player log and exits 0/1), --gameplay-selftest (the same for
the fuel game, with no robot sim: the robot code's shot table, intake, launcher, hub bounce, returns and scoring; logs
[Driver-Sim gameplay-selftest] PASS|FAIL ...),
--screenshot <png> [--screenshot-delay s] [--screenshot-count n] [--screenshot-interval s] [--quit-after-screenshot].
Arguments override the options saved in PlayerPrefs.
| Platform | Graphics API (first supported wins) | Discrete GPU on hybrid laptops |
|---|---|---|
| Linux | Vulkan, then OpenGL Core | simulateDriverSim sets NVIDIA PRIME offload (or Mesa DRI_PRIME=1) for the game only |
| Windows | Direct3D 11, then 12, then Vulkan | automatic: the Unity player exports NvOptimusEnablement / AmdPowerXpressRequestHighPerformance |
| macOS | Metal | macOS chooses |
The player skips software renderers (llvmpipe) and falls back to the next API, so a machine without a GPU driver still
runs. The player log's [Driver-Sim] graphics: <device> (<API>) line shows what was picked. DRIVERSIM_GPU=integrated
turns off the Linux offload. On Linux, NVIDIA Vulkan needs the driver's ICD manifest (nvidia_icd.json); without it the
game uses NVIDIA OpenGL. The Mac app is unsigned: on first launch, right-click > Open (or
xattr -dr com.apple.quarantine Fieldrunner.app).
Field2026.glb is raw CAD (about 4.3 million triangles in 2,929 meshes). The scene builder disables parts whose
largest side is under 0.15 m (1,168 parts, 2.07 million triangles) and at startup FieldSetup merges the rest by
material and field region (about 40 ms), so the field draws as 384 renderers and 1.9 million triangles. The startup log
([Driver-Sim] field: ...) and the details panel (F1) show the counts. Staged fuel, driver station acrylic, bumps and
transparent parts are not merged.
The scene is generated by SceneBuilder (menu Fieldrunner > Rebuild Scene); change the code, not the scene file.
Unity world = field center origin, X = field x, Z = field y, Y = up (Field/FieldFrame.cs).
| Command | What it does |
|---|---|
./gradlew simulateDriverSim |
Robot code + bridge in WPILib sim and the Unity game (if built): one window, the game. The bridge is the driver station; no sim GUI. |
./gradlew simulateDriverSim -PdriverSimGui |
The same plus the WPILib sim GUI, which then supplies joysticks and enable (for debugging; the game's controller and enable commands are ignored; matches still run from the game). Standalone Glass or AdvantageScope can attach to NT without it. |
./gradlew selfTestDriverSim |
Headless scripted check (turret zero, intake, flywheel, hood, climber, driving, Back leaves the true pose alone, shot gating, match). Fails on any step. 15 steps. Also prints a drive-feel measurement (see Drivetrain sim). |
./gradlew selfTestDriverSimWithGame |
The self-test plus the built Unity game (headless): waits for the game's hello, then checks walls, hub, trench and bumps against the true pose, that the robot code's estimate recovers after a wall, that a corner hit turns the truth but not the gyro, and the fuel game (the intake takes a ball, the robot code's launch scores in our hub, a ball dropped into the other hub does not count). 26 steps. |
./gradlew testDriverSim |
Bridge unit tests. |
./gradlew probeDriverSim -Pargs="30,station R1,start" |
While a sim runs: print /DriverSim state, send game commands. |
./gradlew simulateJava runs the robot code with its own sim (each subsystem's simulationPeriodic(): truth, mechanisms, Limelights) but without the bridge or the game.
The game is the driver station. It reads one driver device, the keyboard or one controller (Xbox, PlayStation and
Switch Pro controllers work through Unity's gamepad mapping), and sends a virtual Xbox controller to the bridge, which
writes it to driver station port 0 where the robot code reads it. At startup the driver is the first controller, or
the keyboard with none; a controller plugged in while the keyboard drives takes over (a toast says so), one plugged in
while another controller drives waits in the Controllers screen. Only the driver device drives; every device still
works in the menus. The title screen's "Driver:" line shows who it is. The Controls screen (title or pause
menu) shows what every input does, with labels that follow the connected controller (A/B/X/Y, Cross/Circle/Square/
Triangle, or South/East/West/North), and rebinds any of them: pick an input, press the new one. Changes are saved to
bindings.json in the game's persistent data folder. Unplugging the driver controller during play pauses at once; a
key press switches to the keyboard, reconnecting the controller returns to it. An unrecognized joystick (flight stick,
unusual HID) has no default bindings: the game opens the Controls screen so you can bind its inputs. The robot code's
rumble requests drive the controller's motors.
| Xbox input | Robot action | Keyboard default |
|---|---|---|
| Left stick | drive (field-centric, 3 m/s) | W A S D |
| Left / right trigger | rotate left / right | Q / E |
| A | face hub (hold) | R |
| B | launch: score (hold); unclog on release | Space |
| X | launch: ferry + intake (hold) | F |
| Y | slow mode (hold) | C |
| Start | turbo, 5 m/s (hold) | Left Alt |
| Back | reset field-centric heading | Tab |
| Right / left bumper | intake in / out (hold) | Left Shift / Left Ctrl |
| D-pad down / up | intake slapdown / lift (hold) | Down / Up arrow |
| D-pad left | spindex backwards (hold) | Left arrow |
Controllers screen (title or pause menu): every detected gamepad, joystick and the keyboard is a card, and one
large Driver slot sits on the left. Press left on a device (D-pad or left stick; Left arrow or A on the keyboard)
to make it the driver; the previous driver drops back to the middle. Press right on the driver to step out: the
slot empties and shows a dimmed keyboard card, because the keyboard drives if nobody takes the slot before the screen
closes. Cards light up when their device has input, and can be clicked. B / Esc go back. Unplugging the driver while
the screen is open just empties the slot. A joystick without saved bindings moved into the slot opens the Controls
screen to bind it first. The choice is not remembered across restarts. The log's [Driver-Sim] input devices: ...
line lists the devices and the driver at startup and on every connect, disconnect and takeover.
The table mirrors Robot.setupDriverBindings() (Game/RobotControlsLayout.cs). While Start is held, Back is withheld
from the robot, so the pause chord never resets the field-centric heading.
The bridge has one input owner, set by simulateDriverSim / the self-tests through DRIVERSIM_INPUT:
| Owner | When | Joysticks and enable come from |
|---|---|---|
game |
default simulateDriverSim |
the game |
gui |
simulateDriverSim -PdriverSimGui |
the WPILib sim GUI; the game shows a notice and sends no controller values. In gui mode, drag your Xbox controller onto Joystick 0 in the sim GUI's System Joysticks panel and check Map gamepad |
selftest |
selfTestDriverSim* |
the self-test script (and the game's joystick topic during its one joystick step) |
The bridge publishes the owner in bridge/info (version=6 input=game).
In game mode the bridge owns enable: free practice starts disabled, practice enables teleop, pause / disable
disable. When the game sends start, the bridge acts as the field system: 20 s autonomous, 3 s disabled, 2:20
teleop, then disabled. It sets match time and the game-specific message (autonomous winner, which drives the hub
shifts). Pausing (menu, controller disconnect) holds the match clock and disables the robot; resuming continues with
the same time left. If the game stops sending input for 2 s (crashed or killed) the bridge pauses the same way
and logs it; a game that connects later opens the pause menu so the player can resume. In gui mode the bridge leaves
free-play enable to the sim GUI and drives the driver station only during a match (it re-asserts the enable state every
loop, so stop a match from the game with abort, not the GUI).
| Topic | Type | Direction | Contents |
|---|---|---|---|
robot/state |
double[] | bridge → game | true pose and velocity, mechanisms, enable/mode, the robot code's own pose estimate — game/RobotStateLayout.java |
match/state |
double[] | bridge → game | phase, match time, hub activity, station, auto winner, is-paused — game/MatchStateLayout.java |
robot/rumble |
double[2] | bridge → game | {left, right} controller rumble, 0..1, published on change |
bridge/info |
string | bridge → game | "version=6 input=<game|gui|selftest>" |
game/joystick0 |
double[8] | game → bridge | {leftX, leftY, leftTrigger, rightTrigger, rightX, rightY, buttonBits, povDeg} in WPILib Xbox conventions (forward stick negative; buttons bit 0..9 = A B X Y LB RB Back Start stick-presses; POV degrees clockwise from up, -1 released), every frame at most 100 Hz; sent only when input=game |
game/command |
string | game → bridge | "<seq> <verb> [args]": hello (on every connect), start, abort, station R2, autoWinner B, resetPose x y heading, ballLaunched, quit; practice, disable, pause, resume (only with owner game); spawnFuel x y [height] is for the game itself: any client (the self-test, the probe) can put one ball on the field through this topic, the bridge ignores it |
game/state |
double[6] | game → bridge | {protocolVersion, hopperCount, ourScore, autoScore, opponentAutoScore, fieldFuelCount} about 20 times a second — game/GameStateLayout.java; the bridge only reads it (self-test, probe) |
game/poseCorrection |
double[4] | game → bridge | {robotTimestampS, xFieldM, yFieldM, headingFieldRad}: where the robot should have been at that robot-clock time after Unity resolved collisions |
Unity owns the world: every frame it resolves the robot's reported (true) pose against obstacle colliders
(FieldObstacle; table in Field/FieldObstacleLayout.cs), draws the constrained pose, and sends a poseCorrection when
it moved the robot. A push also turns the robot about its deepest corner (a robot driven corner-first into a wall swings
flush), and the robot's slide along a wall it is pushed into is slowed (wall friction). The bridge's game/PoseCorrector
keeps 2 s of true-pose history and the total offset (translation and heading) it has applied, and moves the robot code's
simulated truth (DrivetrainSubsystem.frSimPush) so it matches Unity's decision at the correction's timestamp (absolute offsets, so
corrections still in flight are not counted twice). The robot code's pose estimate is never set by a collision: its
odometry keeps going through a wall, its gyro does not feel the turn, and the Limelight sim (fed by the truth) pulls the
estimate back once the robot is clear of the wall. While the robot pushes into something, the true pose can sit about
speed x round trip (10-20 cm at full speed) inside it. A trench bar blocks the robot only with the hood above 12 deg.
Bumps are visual only: the drawn robot rises and tilts over them; the robot code is not told. Placing the robot (match or
practice start, reset) sets the truth and also resets the robot code's estimate, as the drive team would by starting from
a known spot.
Field frame is WPILib's blue-origin frame (x along the field's length from the blue wall, CCW-positive headings).
The game owns fuel, the hopper and scoring; the robot code never learns the count (it has no ball sensors). Everything is simple rules with clear feedback; the only physics is the field fuel and the robot pushing it.
- Fuel (
Game/FuelField.cs): theFuel.glbball, 0.15 m. At the start of free practice and of each match 456 balls spawn at the field model's staged positions, and the robot gets 8 preloaded. Balls on the field are Rigidbody spheres (high damping, speed cap, ball-ball collisions) that collide with the carpet, solid obstacles, the hubs, the bump surfaces and the robot, and roll under the trench bars. A kinematic box the size of the bumpers (Robot/RobotPusher.cs) follows the drawn robot, so the robot shoves balls; fuel never pushes the robot. - Hopper (
Game/RobotFuel.cs): holds 20. Intake: a ball touching the zone across the front bumper (frame width, 0.25 m deep, 0.2 m tall) goes in while the arm is down (below 40 degrees) and the roller pulls in (above +2 V); a full hopper leaves the ball to be pushed. - Shooting: while the spindex feeds (feed volts below -1), the hopper has fuel and the flywheel is above 500 RPM,
one ball leaves the drawn turret (0.5 m up) every 0.125 s and the game sends
ballLaunched(the flywheel loses speed). The shot is honest to the robot code: exit speed = RPM x 0.0021 m/s per RPM, elevation = 90 degrees - (hood + 2 degrees) (a low hood is a steep shot), direction = robot heading + turret angle, plus the robot's own velocity (Game/ShotModel.cs). The two constants are fitted so every row of the robot code's score table (56 to 216 in) lands in the hub opening: the worst row is 0.43 m from the hub center (the opening is 0.53 m in radius). - Flight is a scripted drag-free arc. A ball scores when it crosses the hub opening height (1.83 m) going down within 0.53 m plus a 0.15 m aim-assist margin of the hub center (the last 0.2 s of a scoring arc eases to the center); it bounces off a hub's body (a physics ball with its velocity reflected and scaled by 0.3); otherwise it lands below 0.6 m as a physics ball. A scored ball reappears 1.5 s later at the hub's exit and rolls toward the field center, so fuel never runs out.
- Scoring (
Game/Scoreboard.cs): free practice counts fuel in the player's own alliance hub (no timer). In a match a ball scores 1 point while that hub is active (the bridge's hub-shift schedule), otherwise the HUD flashes "HUB INACTIVE"; the other hub never counts. At the end of autonomous the player's autonomous points are compared with a virtual opponent's score (drawn per match, 4 to 12; ties go to the opponent) and the game sendsautoWinner, which sets the teleop hub shifts. - HUD (
Game/GameplayHud.cs), under the match clock:FUEL 12/20,OUR HUB 37(practice) orSCORE 37(match),AUTO 9 vs 7 (WON), a+1pop on each point, theHUB INACTIVEflash andFINAL 52after a match. The details panel (F1) has afuel: field 448 flying 3 hopper 12line. - Resets: F6 moves only the robot. Starting practice, starting or restarting a match respawn all fuel, preload the
hopper and clear the scores. F7 respawns the field fuel in practice. In a development build F8 drops a ball in front
of the robot;
./gradlew probeDriverSim -Pargs="20,spawnFuel 8 4"(orspawnFuel x y height, which releases the ball at rest from that height) does the same from outside.
The drivetrain is the robot code's own CTRE swerve simulation (DrivetrainSubsystem.startSimThread, 5 ms); its simulationPeriodic() adds up
its chassis speeds into the true pose every robot loop. Each
drive motor spins a simulated inertia under its current limit (the 115 A slip current), and the chassis moves with the
wheels. There is no separate chassis mass or traction model, so the wheel inertia stands in for the robot's mass:
DRIVE_INERTIA in CompbotTunerConstants is the robot mass (56.85 kg, from CompbotConstants) times the wheel radius
squared over 4. Phoenix uses it only in simulation. selfTestDriverSim measures the result from rest at full stick
(teleop default speed 3 m/s):
| Tuner default (0.01 kg m^2) | Robot mass (0.0367 kg m^2) | |
|---|---|---|
| Time to 90% of 2.87 m/s | 0.10 s | 0.28 s |
| Peak acceleration | 32.1 m/s^2 | 12.9 m/s^2 |
| Peak deceleration (stick released) | 41.3 m/s^2 | 18.6 m/s^2 |
| Stop time / distance | 0.12 s / 0.12 m | 0.38 s / 0.34 m |
Not modelled: wheel slip (peak braking is slightly above what a carpet of friction coefficient 1-1.5 allows), motor rotor inertia, and load when pushing into a wall (Unity stops the true robot, but the simulated wheels keep spinning).
- Each mechanism subsystem (robot code) moves its mechanism with a WPILib sim (
DCMotorSim,FlywheelSim,SingleJointedArmSim) in its ownsimulationPeriodic(), built from the robot code's own feedforward gains (kV,kA) where they exist, so it responds the way the code was tuned to expect; static friction (kS) is a dead band on the voltage. Values without robot-code gains (intake arm and climberkA, roller and climber gains, flywheel spin-up time constant, spindex inertia) are game-feel estimates written as literals where the subsystem's sim uses them. The hood servo has no sim: its feedback wire follows the commanded position. - Each sim uses its subsystem's own device handles (
TalonFX.getSimState(),DIOSim,PWMSim). The spindex'sSparkFlexSimis created only underisSimulation(). The rotor is written withsetRawRotorPosition, counted from where the mechanism started, so the robot code'ssetPositioncalls (zeroing) move only its belief. - Public methods prefixed
fr(frGetSimTruthPose,frGetSimRpm,frSimBallLaunched, ...) are for the Fieldrunner bridge; robot code never calls them. - There is no battery model: the battery stays at the roboRIO sim default.
- The robot code's
MatchStatecaches the autonomous winner once per process, so a second match in the same sim run keeps the first match's hub-shift order in the robot code (the bridge'smatch/statehub flags are correct).
