Skip to content
This repository was archived by the owner on Jan 17, 2026. It is now read-only.

Commit 5686cad

Browse files
committed
[odometry] Switch to signal timestamp
Signed-off-by: Jade Turner <[email protected]>
1 parent 04b9d14 commit 5686cad

File tree

6 files changed

+18
-30
lines changed

6 files changed

+18
-30
lines changed

src/main/java/org/curtinfrc/frc2025/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* (log replay from a file).
1616
*/
1717
public final class Constants {
18-
public static final RobotType robotType = RobotType.COMPBOT;
18+
public static final RobotType robotType = RobotType.SIMBOT;
1919
public static final double ROBOT_X = 0.705;
2020
public static final double ROBOT_Y = 0.730;
2121
public static final double FIELD_LENGTH = aprilTagLayout.getFieldLength();

src/main/java/org/curtinfrc/frc2025/Robot.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import edu.wpi.first.wpilibj.DataLogManager;
1414
import edu.wpi.first.wpilibj.Filesystem;
1515
import edu.wpi.first.wpilibj.GenericHID.RumbleType;
16+
import edu.wpi.first.wpilibj.RobotController;
1617
import edu.wpi.first.wpilibj.Threads;
1718
import edu.wpi.first.wpilibj2.command.Command;
1819
import edu.wpi.first.wpilibj2.command.Command.InterruptionBehavior;
@@ -724,6 +725,10 @@ public void robotPeriodic() {
724725
Threads.setCurrentThreadPriority(true, 99);
725726

726727
PhoenixUtil.refreshAll();
728+
Logger.recordOutput("PhoenixTime", PhoenixUtil.getTime());
729+
Logger.recordOutput("FPGATime", RobotController.getFPGATime() / 1000000.0);
730+
Logger.recordOutput(
731+
"TimeDifference", PhoenixUtil.getTime() - RobotController.getFPGATime() / 1000000.0);
727732

728733
controllerDisconnected.set(!controller.isConnected());
729734

src/main/java/org/curtinfrc/frc2025/subsystems/drive/PhoenixOdometryThread.java

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
1-
// Copyright 2021-2024 FRC 6328
2-
// http://github.com/Mechanical-Advantage
3-
//
4-
// This program is free software; you can redistribute it and/or
5-
// modify it under the terms of the GNU General Public License
6-
// version 3 as published by the Free Software Foundation or
7-
// available in the root directory of this project.
8-
//
9-
// This program is distributed in the hope that it will be useful,
10-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
// GNU General Public License for more details.
13-
141
package org.curtinfrc.frc2025.subsystems.drive;
152

163
import static org.curtinfrc.frc2025.subsystems.drive.DriveConstants.*;
4+
import static org.curtinfrc.frc2025.util.PhoenixUtil.phoenixToFPGATime;
175

186
import com.ctre.phoenix6.BaseStatusSignal;
197
import com.ctre.phoenix6.CANBus;
208
import com.ctre.phoenix6.StatusSignal;
219
import edu.wpi.first.units.measure.Angle;
22-
import edu.wpi.first.wpilibj.RobotController;
2310
import java.util.ArrayList;
2411
import java.util.List;
2512
import java.util.Queue;
@@ -138,28 +125,17 @@ public void run() {
138125
// Save new data to queues
139126
Drive.odometryLock.lock();
140127
try {
141-
// Sample timestamp is current FPGA time minus average CAN latency
142-
// Default timestamps from Phoenix are NOT compatible with
143-
// FPGA timestamps, this solution is imperfect but close
144-
double timestamp = RobotController.getFPGATime() / 1e6;
145-
double totalLatency = 0.0;
146-
for (BaseStatusSignal signal : phoenixSignals) {
147-
totalLatency += signal.getTimestamp().getLatency();
148-
}
149-
if (phoenixSignals.length > 0) {
150-
timestamp -= totalLatency / phoenixSignals.length;
151-
}
152-
128+
assert (phoenixQueues.size() == timestampQueues.size());
153129
// Add new samples to queues
154130
for (int i = 0; i < phoenixSignals.length; i++) {
155131
phoenixQueues.get(i).offer(phoenixSignals[i].getValueAsDouble());
132+
timestampQueues
133+
.get(i)
134+
.offer(phoenixToFPGATime(phoenixSignals[i].getTimestamp().getTime()));
156135
}
157136
for (int i = 0; i < genericSignals.size(); i++) {
158137
genericQueues.get(i).offer(genericSignals.get(i).getAsDouble());
159138
}
160-
for (int i = 0; i < timestampQueues.size(); i++) {
161-
timestampQueues.get(i).offer(timestamp);
162-
}
163139
} finally {
164140
Drive.odometryLock.unlock();
165141
}

src/main/java/org/curtinfrc/frc2025/util/PhoenixUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,9 @@ public static double phoenixToFPGATime(double timeSeconds) {
6262
public static double phoenixToRobotTime(double timeSeconds) {
6363
return (RobotController.getTime() - Utils.getCurrentTimeSeconds()) + timeSeconds;
6464
}
65+
66+
/** Returns raw Phoenix time. Is *NOT* deterministic. */
67+
public static double getTime() {
68+
return Utils.getCurrentTimeSeconds();
69+
}
6570
}
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Manifest-Version: 1.0
2+

0 commit comments

Comments
 (0)