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

Commit dc7eb5d

Browse files
committed
[odometry] Switch to signal timestamp
Signed-off-by: Jade Turner <[email protected]>
1 parent 82f58ac commit dc7eb5d

File tree

1 file changed

+5
-29
lines changed

1 file changed

+5
-29
lines changed

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
}

0 commit comments

Comments
 (0)