Repository navigation
Replace XTimer with WPILib Timer and SimHooks - #697
Open
NormalDuck wants to merge 1 commit into
Open
NormalDuck wants to merge 1 commit into
NormalDuck wants to merge 1 commit into
Conversation
Remove the XTimer facade, its implementations, and the Dagger timer bindings. Library code reads Timer.getMonotonicTimestamp() directly, and tests control time through WPILib's simulated clock: BaseWPITest pauses it and tests advance it with SimHooks.stepTiming(). Co-Authored-By: Claude <noreply@anthropic.com>
JUnit results 72 files - 1 72 suites - 1 3s ⏱️ -1s Results for commit 443401e. ± Comparison against base commit c0e2ecf. This pull request removes 9 and adds 6 tests. Note that renamed tests count towards both. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why are we doing this?
XTimerwas a static facade over a globally installedXTimerImpl, with aMockTimerfor tests and aTimerWpiAdapterfor the robot. WPILib already provides both halves:Timerfor reading time andSimHooksfor controlling simulated time in tests. Keeping our own copy meant extra Dagger bindings, extra setup in every test base class, and one more indirection on every timestamp read in the robot loop.Whats changing?
XTimer,XTimerImpl,XSettableTimerImpl,MockTimer,TimerWpiAdapter, andMockTimerTest.RobotModule,SimulationModule, andUnitTestModule, the accessor onBaseComponent, and the timer wiring inBaseRobot.XTimer.getFPGATimestamp()now callsTimer.getMonotonicTimestamp().BaseWPITestpauses WPILib's simulated clock in setup and resumes it in teardown. Tests advance time withSimHooks.stepTiming(seconds)instead oftimer.advanceTimeInSecondsBy(...)/setTimeInSeconds(...).AGENTS.mdand the FSM ReadMe to describe the new test-time pattern.This is a breaking change for robot projects: anything that uses
XTimerorMockTimerwill need the same migration.Questions/notes for reviewers
HistoryBufferTests,FiniteStateMachineReadMeExampleTest).FiniteStateMachineReadMeExampleTest.isFinishedOnlyOnceFinalAnalysisIsReachedhad its total-duration tolerance widened from one loop tick to three. The likely cause, not confirmed, is that the sim clock lands on exact threshold values whereMockTimer's accumulated doubles tipped over slightly early, so each of the three timed states can take one extra tick. The per-phase duration tests still pass at the original one-tick tolerance.BaseWPITest.setUp,createDaggerComponent()runs before the clock is paused. Nothing depends on this today, but it could be reordered.How this was tested
Existing tests were migrated rather than new ones added;
./gradlew buildpasses locally (tests, Checkstyle, Spotless). Not run on a robot.🤖 Generated with Claude Code