|
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 | | - |
14 | 1 | package org.curtinfrc.frc2025.subsystems.drive; |
15 | 2 |
|
16 | 3 | import static org.curtinfrc.frc2025.subsystems.drive.DriveConstants.*; |
| 4 | +import static org.curtinfrc.frc2025.util.PhoenixUtil.phoenixToFPGATime; |
17 | 5 |
|
18 | 6 | import com.ctre.phoenix6.BaseStatusSignal; |
19 | 7 | import com.ctre.phoenix6.CANBus; |
20 | 8 | import com.ctre.phoenix6.StatusSignal; |
21 | 9 | import edu.wpi.first.units.measure.Angle; |
22 | | -import edu.wpi.first.wpilibj.RobotController; |
23 | 10 | import java.util.ArrayList; |
24 | 11 | import java.util.List; |
25 | 12 | import java.util.Queue; |
@@ -138,28 +125,17 @@ public void run() { |
138 | 125 | // Save new data to queues |
139 | 126 | Drive.odometryLock.lock(); |
140 | 127 | 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()); |
153 | 129 | // Add new samples to queues |
154 | 130 | for (int i = 0; i < phoenixSignals.length; i++) { |
155 | 131 | phoenixQueues.get(i).offer(phoenixSignals[i].getValueAsDouble()); |
| 132 | + timestampQueues |
| 133 | + .get(i) |
| 134 | + .offer(phoenixToFPGATime(phoenixSignals[i].getTimestamp().getTime())); |
156 | 135 | } |
157 | 136 | for (int i = 0; i < genericSignals.size(); i++) { |
158 | 137 | genericQueues.get(i).offer(genericSignals.get(i).getAsDouble()); |
159 | 138 | } |
160 | | - for (int i = 0; i < timestampQueues.size(); i++) { |
161 | | - timestampQueues.get(i).offer(timestamp); |
162 | | - } |
163 | 139 | } finally { |
164 | 140 | Drive.odometryLock.unlock(); |
165 | 141 | } |
|
0 commit comments