Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ All commands use the Gradle wrapper from the repository root.
|---|---|---|
| Custom library classes | `X` prefix | `XGyro`, `XEncoder`, `XCANMotorController` |
| Base/abstract classes | `Base` prefix | `BaseCommand`, `BaseSubsystem`, `BaseRobot` |
| Mock/test implementations | `Mock` prefix | `MockGyro`, `MockTimer` |
| Mock/test implementations | `Mock` prefix | `MockGyro`, `MockLaserCAN` |
| WPILib adapter classes | `*WpiAdapter` suffix | `PowerDistributionPanelWPIAdapter` |
| Interfaces | `I` prefix (optional) | `ITableProxy` |
| Packages | all lowercase, dots allowed | `xbot.common.math` |
Expand Down Expand Up @@ -170,8 +170,9 @@ through the abstract base class and inject the concrete implementation via Dagge
- All tests extend `BaseWPITest` (located in `xbot.common.injection`) and implement
`createDaggerComponent()` to provide a Dagger component wired with mock modules.
- Tests are plain JUnit 4 (`@Test`, `@Before`, `@After`).
- The `MockTimer` (injected as `timer` in `BaseWPITest`) controls simulated time; advance it
manually where time-dependent logic is tested.
- `BaseWPITest` pauses WPILib's simulated clock; advance it with `SimHooks.stepTiming(seconds)` where
time-dependent logic is tested. The clock does not start at zero, so measure time relative to a
timestamp captured in the test.
- Test classes live in `src/test/java/` mirroring the package of the class under test.
- Aim for unit tests that do not require hardware, network, or file I/O.

Expand Down
8 changes: 2 additions & 6 deletions src/main/java/xbot/common/command/BaseRobot.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
import org.wpilib.hardware.bus.CANPort;
import org.wpilib.hardware.power.PowerDistribution;
import org.wpilib.system.RobotController;
import org.wpilib.system.Timer;
import org.wpilib.tunable.Tunables;

import xbot.common.advantage.TunableSkippingNT4Publisher;
import xbot.common.controls.sensors.XTimer;
import xbot.common.controls.sensors.XTimerImpl;
import xbot.common.injection.DevicePolice;
import xbot.common.injection.components.BaseComponent;
import xbot.common.logging.assertion.RobotAssertionManager;
Expand Down Expand Up @@ -172,9 +171,6 @@ protected void updateLoggingContext() {
protected void initializeSystems() {
updateLoggingContext();
// override with additional systems (but call this one too)
XTimerImpl timerimpl = injectorComponent.timerImplementation();
XTimer.setImplementation(timerimpl);

tunableManager = injectorComponent.tunableManager();
xScheduler = injectorComponent.scheduler();
xScheduler.reset();
Expand Down Expand Up @@ -280,6 +276,6 @@ public void refreshAllDataFrames() {
}

protected double getPerformanceTimestampInMs() {
return XTimer.getFPGATimestamp() * 1000.0;
return Timer.getMonotonicTimestamp() * 1000.0;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package xbot.common.command;

import org.wpilib.command2.Subsystem;

import xbot.common.controls.sensors.XTimer;
import org.wpilib.system.Timer;

/**
* Base class for subsystems that have a setpoint managed by a maintainer.
Expand Down Expand Up @@ -42,7 +41,7 @@ public boolean isMaintainerAtGoal() {
return false;
}

if (XTimer.getFPGATimestamp() - lastUpdateTimeFromMaintainer > 0.5) {
if (Timer.getMonotonicTimestamp() - lastUpdateTimeFromMaintainer > 0.5) {
// If we haven't heard from the maintainer within the last 0.5 seconds,
// then assume the system is not ready.
return false;
Expand All @@ -52,8 +51,9 @@ public boolean isMaintainerAtGoal() {
}

public void setMaintainerIsAtGoal(boolean atGoal) {
lastUpdateTimeFromMaintainer = XTimer.getFPGATimestamp();
lastUpdateTimeFromMaintainer = Timer.getMonotonicTimestamp();
this.atGoal = atGoal;

lastTargetValueUsedforAtGoal = getTargetValue();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package xbot.common.command;

import org.wpilib.system.Timer;
import org.wpilib.tunable.TunableDouble;

import xbot.common.controls.sensors.XTimer;
import xbot.common.properties.TunableFactory;

/**
Expand All @@ -24,7 +24,7 @@ public BaseWaitForMaintainerCommand(BaseSetpointSubsystem<?, ?> system, TunableF

@Override
public void initialize() {
this.startTime = XTimer.getFPGATimestamp();
this.startTime = Timer.getMonotonicTimestamp();
}

@Override
Expand All @@ -38,6 +38,6 @@ public boolean isFinished() {
}

private boolean isTimeoutExpired() {
return XTimer.getFPGATimestamp() > this.startTime + this.timeoutTunable.get();
return Timer.getMonotonicTimestamp() > this.startTime + this.timeoutTunable.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.function.DoubleSupplier;

import xbot.common.controls.sensors.XTimer;
import org.wpilib.system.Timer;

public class DelayViaSupplierCommand extends BaseCommand {

Expand All @@ -15,7 +15,7 @@ public DelayViaSupplierCommand(DoubleSupplier delaySupplier) {

@Override
public void initialize() {
this.startTime = XTimer.getFPGATimestamp();
this.startTime = Timer.getMonotonicTimestamp();
log.info("Initializing with intial time: " + startTime + " and waiting for " + delaySupplier.getAsDouble() + " seconds");
}

Expand All @@ -30,6 +30,6 @@ public boolean isFinished() {
}

private boolean isTimeoutExpired() {
return XTimer.getFPGATimestamp() > startTime + delaySupplier.getAsDouble();
return Timer.getMonotonicTimestamp() > startTime + delaySupplier.getAsDouble();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.function.DoubleSupplier;

import xbot.common.controls.sensors.XTimer;
import org.wpilib.system.Timer;

/**
* Command that waits for a maintainer to be at its goal or until a timeout.
Expand All @@ -28,7 +28,7 @@ public SimpleWaitForMaintainerCommand(BaseSetpointSubsystem<?, ?> subsystem, Dou

@Override
public void initialize() {
this.startTime = XTimer.getFPGATimestamp();
this.startTime = Timer.getMonotonicTimestamp();
}

@Override
Expand All @@ -42,6 +42,6 @@ public boolean isFinished() {
}

private boolean isTimeoutExpired() {
return XTimer.getFPGATimestamp() > startTime + delaySupplier.getAsDouble();
return Timer.getMonotonicTimestamp() > startTime + delaySupplier.getAsDouble();
}
}

This file was deleted.

40 changes: 0 additions & 40 deletions src/main/java/xbot/common/controls/sensors/XTimer.java

This file was deleted.

9 changes: 0 additions & 9 deletions src/main/java/xbot/common/controls/sensors/XTimerImpl.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package xbot.common.controls.sensors.mock_adapters;

import org.wpilib.system.Timer;

import dagger.assisted.Assisted;
import dagger.assisted.AssistedFactory;
import dagger.assisted.AssistedInject;

import xbot.common.command.DataFrameRegistry;
import xbot.common.controls.io_inputs.LaserCANInputs;
import xbot.common.controls.sensors.XLaserCAN;
import xbot.common.controls.sensors.XTimer;
import xbot.common.injection.DevicePolice;
import xbot.common.injection.electrical_contract.DeviceInfo;

Expand All @@ -31,13 +32,13 @@ public MockLaserCAN(@Assisted("info") DeviceInfo info, @Assisted("owningSystemPr

public void setDistance(double distanceMeters) {
this.distanceMeters = distanceMeters;
this.measurementTime = XTimer.getFPGATimestamp();
this.measurementTime = Timer.getMonotonicTimestamp();
}

@Override
public void updateInputs(LaserCANInputs inputs) {
inputs.isMeasurementValid = true;
inputs.distance = org.wpilib.units.Units.Meters.of(distanceMeters);
inputs.measurementLatency = Seconds.of(XTimer.getFPGATimestamp() - measurementTime);
inputs.measurementLatency = Seconds.of(Timer.getMonotonicTimestamp() - measurementTime);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
* import dagger.assisted.Assisted; import dagger.assisted.AssistedFactory; import dagger.assisted.AssistedInject;
*
* import xbot.common.command.DataFrameRegistry; import xbot.common.controls.io_inputs.LaserCANInputs; import
* xbot.common.controls.sensors.XLaserCAN; import xbot.common.controls.sensors.XTimer; import
* xbot.common.injection.DevicePolice; import xbot.common.injection.electrical_contract.DeviceInfo; import
* xbot.common.logging.AlertGroups;
* xbot.common.controls.sensors.XLaserCAN; import org.wpilib.system.Timer; import xbot.common.injection.DevicePolice;
* import xbot.common.injection.electrical_contract.DeviceInfo; import xbot.common.logging.AlertGroups;
*
* import static org.wpilib.units.Units.Meters; import static org.wpilib.units.Units.Seconds;
*
Expand Down Expand Up @@ -41,8 +40,8 @@
* @Override public void updateInputs(LaserCANInputs inputs) { LaserCanInterface.Measurement measurement =
* laserCan.getMeasurement(); if (measurement != null && measurement.status ==
* LaserCan.LASERCAN_STATUS_VALID_MEASUREMENT) { inputs.distance = Meters.of(measurement.distance_mm / 1000.0); if
* (!inputs.distance.isEquivalent(previousMeasurement)) { previousMeasurementTime = XTimer.getFPGATimestampTime();
* previousMeasurement = inputs.distance; } inputs.measurementLatency =
* XTimer.getFPGATimestampTime().minus(previousMeasurementTime); inputs.isMeasurementValid = true; } else {
* (!inputs.distance.isEquivalent(previousMeasurement)) { previousMeasurementTime =
* Seconds.of(Timer.getMonotonicTimestamp()); previousMeasurement = inputs.distance; } inputs.measurementLatency =
* Seconds.of(Timer.getMonotonicTimestamp()).minus(previousMeasurementTime); inputs.isMeasurementValid = true; } else {
* inputs.distance = Meters.zero(); inputs.measurementLatency = Seconds.zero(); inputs.isMeasurementValid = false; } } }
*/
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import org.wpilib.hardware.bus.I2C;
import org.wpilib.hardware.bus.I2C.Port;
import org.wpilib.system.Timer;

import dagger.assisted.Assisted;
import dagger.assisted.AssistedFactory;
import dagger.assisted.AssistedInject;

import xbot.common.controls.sensors.XLidarLite;
import xbot.common.controls.sensors.XTimer;
import xbot.common.injection.DevicePolice;
import xbot.common.properties.TunableFactory;

Expand All @@ -32,9 +32,9 @@ public LidarLiteWpiAdapter(@Assisted("port") Port port, TunableFactory tunableFa
// Update distance variable
public void update() {
i2c.write(lidar_config_register, 0x04); // Initiate measurement
XTimer.delay(0.04); // Delay for measurement to be taken
Timer.delay(0.04); // Delay for measurement to be taken
i2c.read(lidar_distance_register, 2, distance); // Read in measurement
XTimer.delay(0.01); // Delay to prevent over polling
Timer.delay(0.01); // Delay to prevent over polling
}

}
Loading
Loading