File tree 4 files changed +14
-2
lines changed
src/main/java/org/team1540/robot2024
4 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 9
9
import org .littletonrobotics .junction .networktables .NT4Publisher ;
10
10
import org .littletonrobotics .junction .wpilog .WPILOGReader ;
11
11
import org .littletonrobotics .junction .wpilog .WPILOGWriter ;
12
- import org .team1540 .robot2024 .util .PhoenixTimeSyncSignalRefresher ;
13
12
14
13
/**
15
14
* The VM is configured to automatically run this class, and to call the functions corresponding to
@@ -84,7 +83,6 @@ public void robotInit() {
84
83
*/
85
84
@ Override
86
85
public void robotPeriodic () {
87
- if (Constants .currentMode == Constants .Mode .REAL ) PhoenixTimeSyncSignalRefresher .refreshSignals ();
88
86
// Runs the Scheduler. This is responsible for polling buttons, adding
89
87
// newly-scheduled commands, running already-scheduled commands, removing
90
88
// finished or interrupted commands, and running subsystem periodic() methods.
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ public GyroIOPigeon2() {
30
30
31
31
@ Override
32
32
public void updateInputs (GyroIOInputs inputs ) {
33
+ PhoenixTimeSyncSignalRefresher .refreshSignals ();
33
34
inputs .connected = BaseStatusSignal .isAllGood (yaw , yawVelocity );
34
35
inputs .yawPosition = Rotation2d .fromDegrees (yaw .getValueAsDouble ());
35
36
inputs .yawVelocityRadPerSec = Units .degreesToRadians (yawVelocity .getValueAsDouble ());
Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ public ModuleIOTalonFX(SwerveFactory.SwerveModuleHW hw) {
80
80
81
81
@ Override
82
82
public void updateInputs (ModuleIOInputs inputs ) {
83
+ PhoenixTimeSyncSignalRefresher .refreshSignals ();
83
84
BaseStatusSignal .refreshAll (
84
85
driveVelocity ,
85
86
driveAppliedVolts ,
Original file line number Diff line number Diff line change 2
2
3
3
import com .ctre .phoenix6 .BaseStatusSignal ;
4
4
import com .ctre .phoenix6 .CANBus ;
5
+ import edu .wpi .first .wpilibj .Timer ;
6
+ import org .team1540 .robot2024 .Constants ;
5
7
6
8
import java .util .Arrays ;
7
9
@@ -14,12 +16,22 @@ public class PhoenixTimeSyncSignalRefresher {
14
16
private static BaseStatusSignal [] signals = new BaseStatusSignal [0 ];
15
17
private static final boolean isCANFD = CANBus .isNetworkFD (CAN_BUS );
16
18
19
+ private static double lastRefreshTimestamp = 0 ;
20
+
21
+ /**
22
+ * Registers status signals to be refreshed when {@link PhoenixTimeSyncSignalRefresher#refreshSignals()}is called
23
+ */
17
24
public static void registerSignals (BaseStatusSignal ... newSignals ) {
18
25
signals = Arrays .copyOf (signals , signals .length + newSignals .length );
19
26
for (int i = 0 ; i < newSignals .length ; i ++) signals [signals .length - 1 - i ] = newSignals [i ];
20
27
}
21
28
29
+ /**
30
+ * Refreshes all registered signals if not already done so in the current loop period
31
+ */
22
32
public static void refreshSignals () {
33
+ if (Timer .getFPGATimestamp () - lastRefreshTimestamp < Constants .LOOP_PERIOD_SECS ) return ;
34
+ lastRefreshTimestamp = Timer .getFPGATimestamp ();
23
35
if (isCANFD ) BaseStatusSignal .waitForAll (0.01 , signals );
24
36
else BaseStatusSignal .refreshAll (signals );
25
37
}
You can’t perform that action at this time.
0 commit comments