File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed 
src/main/java/org/trigon/hardware/phoenix6 Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 1515
1616import  com .ctre .phoenix6 .BaseStatusSignal ;
1717import  com .ctre .phoenix6 .StatusCode ;
18+ import  edu .wpi .first .wpilibj .RobotController ;
1819import  edu .wpi .first .wpilibj .Timer ;
19- import  org .littletonrobotics .junction .Logger ;
2020import  org .trigon .hardware .RobotHardwareStats ;
2121import  org .trigon .hardware .SignalThreadBase ;
2222
@@ -80,16 +80,25 @@ public void run() {
8080    private  void  updateValues () {
8181        if  (BaseStatusSignal .waitForAll (RobotHardwareStats .getPeriodicTimeSeconds (), signals ) != StatusCode .OK )
8282            return ;
83-         final  double  updateTimestamp  = (Logger .getRealTimestamp () / 1e6 ) - signals [0 ].getTimestamp ().getLatency ();
83+         final  double  currentTimestamp  = RobotController .getFPGATime () / 1e6 ;
84+         final  double  resultTimestamp  = currentTimestamp  - calculateLatency ();
8485
8586        SIGNALS_LOCK .lock ();
8687        try  {
87-             updateQueues (updateTimestamp );
88+             updateQueues (resultTimestamp );
8889        } finally  {
8990            SIGNALS_LOCK .unlock ();
9091        }
9192    }
9293
94+     private  double  calculateLatency () {
95+         double  totalLatency  = 0.0 ;
96+         for  (BaseStatusSignal  signal  : signals )
97+             totalLatency  += signal .getTimestamp ().getLatency ();
98+ 
99+         return  totalLatency  / signals .length ;
100+     }
101+ 
93102    private  void  updateQueues (double  updateTimestamp ) {
94103        for  (int  i  = 0 ; i  < signals .length ; i  += 1 ) {
95104            final  BaseStatusSignal  signal  = signals [i ];
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments