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

Commit 5f50e51

Browse files
committed
[utils] Add methods to convert from Phoenix time
Signed-off-by: Jade Turner <[email protected]>
1 parent 0821adb commit 5f50e51

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
package org.curtinfrc.frc2025.util;
1515

1616
import com.ctre.phoenix6.StatusCode;
17+
import com.ctre.phoenix6.Utils;
18+
import edu.wpi.first.wpilibj.RobotController;
1719
import java.util.function.Supplier;
1820

1921
public class PhoenixUtil {
@@ -24,4 +26,20 @@ public static void tryUntilOk(int maxAttempts, Supplier<StatusCode> command) {
2426
if (error.isOK()) break;
2527
}
2628
}
29+
30+
/**
31+
* Converts a time from Phoenix6's timebase to FPGA time. Should only be used inside of an IO
32+
* layer as it relies on raw FPGA time.
33+
*/
34+
public static double phoenixToFPGATime(double timeSeconds) {
35+
return (RobotController.getFPGATime() - Utils.getCurrentTimeSeconds()) + timeSeconds;
36+
}
37+
38+
/**
39+
* Converts a time from Phoenix6's timebase to the robots timebase. Can be used outside of IO
40+
* layers.
41+
*/
42+
public static double phoenixToRobotTime(double timeSeconds) {
43+
return (RobotController.getTime() - Utils.getCurrentTimeSeconds()) + timeSeconds;
44+
}
2745
}

0 commit comments

Comments
 (0)