mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
Makes Java Timer timing more accurate
Java was using integer division for calulating Timer values, which was causing Timer values to be concatinated, and only accurate to the nearest millisecond. This changes it to use double division, which matches C++ and makes timing much more accurate Change-Id: I61b893f4ad5791bf4dfdd767ee4346c1ed4ea418
This commit is contained in:
committed by
Gerrit Code Review
parent
fa8b68419f
commit
e852547344
@@ -58,7 +58,7 @@ public class HardwareTimer implements Timer.StaticInterface {
|
||||
}
|
||||
|
||||
class TimerImpl implements Timer.Interface {
|
||||
private long m_startTime;
|
||||
private double m_startTime;
|
||||
private double m_accumulatedTime;
|
||||
private boolean m_running;
|
||||
|
||||
@@ -70,8 +70,8 @@ public class HardwareTimer implements Timer.StaticInterface {
|
||||
reset();
|
||||
}
|
||||
|
||||
private long getMsClock() {
|
||||
return Utility.getFPGATime() / 1000;
|
||||
private double getMsClock() {
|
||||
return Utility.getFPGATime() / 1000.0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,7 @@ import gazebo.msgs.GzFloat64.Float64;
|
||||
*/
|
||||
public class SimTimer implements Timer.StaticInterface {
|
||||
|
||||
private long m_startTime;
|
||||
private double m_startTime;
|
||||
private double m_accumulatedTime;
|
||||
private boolean m_running;
|
||||
private static double simTime;
|
||||
@@ -100,8 +100,8 @@ public class SimTimer implements Timer.StaticInterface {
|
||||
* @deprecated Use getFPGATimestamp instead.
|
||||
* @return Robot running time in milliseconds.
|
||||
*/
|
||||
private long getMsClock() {
|
||||
return (long) (simTime * 1e3);
|
||||
private double getMsClock() {
|
||||
return (simTime * 1e3);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user