Skip to content

Give an OpMode run a battery when the map has no voltage sensor - #32

Open
saltyeg wants to merge 1 commit into
Horizon-36596:mainfrom
saltyeg:fix/default-voltage-sensor
Open

saltyeg wants to merge 1 commit into
Horizon-36596:mainfrom
saltyeg:fix/default-voltage-sensor

Conversation

@saltyeg

@saltyeg saltyeg commented Oct 29, 2026

Copy link
Copy Markdown

What

When a run starts and the FakeHardwareMap has no voltage sensor, OpModeRunner registers a 12 V
FakeVoltageSensor under "Control Hub" (the name a Control Hub's own sensor has in a real configuration). A map
that already has a voltage sensor is left alone. Adds OpModeRunner.DEFAULT_VOLTAGE_SENSOR_NAME.

Why

Robot code that compensates for the battery (feedforward scaled by 12 / volts, which is common for flywheels and
drivetrains) reads hardwareMap.voltageSensor.iterator().next(). A real robot's map always answers that: every hub
has a voltage sensor. An empty fake map throws NoSuchElementException at INIT, so the team's unchanged OpMode
crashes before it starts, and the stack trace points into their subsystem constructor, not at the sim. We hit this
when a teammate added voltage compensation to our launcher: every OpMode test failed at once.

FakeVoltageSensor already existed; this just means a team doesn't have to know to register one. It's in the
runner rather than the FakeHardwareMap constructor so a new map stays empty (size(), getAll and the existing
fidelity tests are unchanged), and a test that wants another voltage registers its own sensor and gets no default.

How I tested it

  • New opmode/DefaultBatteryTest: an OpMode reading voltageSensor.iterator().next() in init() gets 12.0 V from a
    bare map, under "Control Hub"; with the test's own 11.2 V sensor registered, it gets that one and the runner adds
    none. With the runner's call commented out, the first test fails with the NoSuchElementException.

  • ./gradlew :SimLoop:testDebugUnitTest --rerun: 1253 tests, 0 failed. :examples:testDebugUnitTest and
    :SimLoop:desktop:test pass. bash tools/leak-gate/leak-gate.sh passes.

  • ./gradlew test passes on my machine

  • New or changed behaviour has a test

  • If I touched docs or public javadoc: ./gradlew :SimLoop:docsSite passes (touched docs/packages/opmode.md
    and added a public constant with javadoc; docsSite not run here, it needs the mkdocs toolchain)

Checklist

  • No robot-specific or season-specific code (SimLoop stays season-agnostic)
  • Every new number says its unit, and its frame if it is a pose
  • Any public API change is called out above (one new public constant)
  • If an AI agent wrote some of this, a human has read the change and run the tests

Robot code that compensates for the battery reads
hardwareMap.voltageSensor.iterator().next(). A real robot's map always
answers (its hubs' voltage sensors); an empty FakeHardwareMap threw
NoSuchElementException at INIT. The runner now registers a 12 V
FakeVoltageSensor named "Control Hub" when the map has none, and leaves
a map with its own sensor alone.

This branch has not been deployed

No deployments
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.

1 participant