From e852547344f89e7d254c4207c842595ae2fa3907 Mon Sep 17 00:00:00 2001 From: Thad House Date: Tue, 9 Feb 2016 19:29:57 -0800 Subject: [PATCH] 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 --- .../java/edu/wpi/first/wpilibj/internal/HardwareTimer.java | 6 +++--- .../sim/java/edu/wpi/first/wpilibj/internal/SimTimer.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java index d3f6179df4..92da9e4bf6 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java @@ -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; } /** diff --git a/wpilibj/src/sim/java/edu/wpi/first/wpilibj/internal/SimTimer.java b/wpilibj/src/sim/java/edu/wpi/first/wpilibj/internal/SimTimer.java index cf514f9bd9..a3d9352453 100644 --- a/wpilibj/src/sim/java/edu/wpi/first/wpilibj/internal/SimTimer.java +++ b/wpilibj/src/sim/java/edu/wpi/first/wpilibj/internal/SimTimer.java @@ -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); } /**