mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[wpilibj] Add units to parameter names (NFC) (#3497)
This commit is contained in:
@@ -1042,12 +1042,12 @@ public class DriverStation {
|
||||
* <p>Checks if new control data has arrived since the last waitForData call on the current
|
||||
* thread. If new data has not arrived, returns immediately.
|
||||
*
|
||||
* @param timeout The maximum time in seconds to wait.
|
||||
* @param timeoutSeconds The maximum time in seconds to wait.
|
||||
* @return true if there is new data, otherwise false
|
||||
*/
|
||||
public static boolean waitForData(double timeout) {
|
||||
long startTime = RobotController.getFPGATime();
|
||||
long timeoutMicros = (long) (timeout * 1000000);
|
||||
public static boolean waitForData(double timeoutSeconds) {
|
||||
long startTimeMicroS = RobotController.getFPGATime();
|
||||
long timeoutMicroS = (long) (timeoutSeconds * 1e6);
|
||||
m_waitForDataMutex.lock();
|
||||
try {
|
||||
int currentCount = m_waitForDataCount;
|
||||
@@ -1056,12 +1056,13 @@ public class DriverStation {
|
||||
return true;
|
||||
}
|
||||
while (m_waitForDataCount == currentCount) {
|
||||
if (timeout > 0) {
|
||||
long now = RobotController.getFPGATime();
|
||||
if (now < startTime + timeoutMicros) {
|
||||
if (timeoutMicroS > 0) {
|
||||
long nowMicroS = RobotController.getFPGATime();
|
||||
if (nowMicroS < startTimeMicroS + timeoutMicroS) {
|
||||
// We still have time to wait
|
||||
boolean signaled =
|
||||
m_waitForDataCond.await(startTime + timeoutMicros - now, TimeUnit.MICROSECONDS);
|
||||
m_waitForDataCond.await(
|
||||
startTimeMicroS + timeoutMicroS - nowMicroS, TimeUnit.MICROSECONDS);
|
||||
if (!signaled) {
|
||||
// Return false if a timeout happened
|
||||
return false;
|
||||
|
||||
@@ -18,9 +18,9 @@ public class Notifier implements AutoCloseable {
|
||||
// The C pointer to the notifier object. We don't use it directly, it is
|
||||
// just passed to the JNI bindings.
|
||||
private final AtomicInteger m_notifier = new AtomicInteger();
|
||||
// The time, in microseconds, at which the corresponding handler should be
|
||||
// called. Has the same zero as Utility.getFPGATime().
|
||||
private double m_expirationTime;
|
||||
// The time, in seconds, at which the corresponding handler should be
|
||||
// called. Has the same zero as RobotController.getFPGATime().
|
||||
private double m_expirationTimeSeconds;
|
||||
// The handler passed in by the user which should be called at the
|
||||
// appropriate interval.
|
||||
private Runnable m_handler;
|
||||
@@ -28,7 +28,7 @@ public class Notifier implements AutoCloseable {
|
||||
private boolean m_periodic;
|
||||
// If periodic, the period of the calling; if just once, stores how long it
|
||||
// is until we call the handler.
|
||||
private double m_period;
|
||||
private double m_periodSeconds;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NoFinalizer")
|
||||
@@ -59,19 +59,19 @@ public class Notifier implements AutoCloseable {
|
||||
/**
|
||||
* Update the alarm hardware to reflect the next alarm.
|
||||
*
|
||||
* @param triggerTime the time at which the next alarm will be triggered
|
||||
* @param triggerTimeMicroS the time in microseconds at which the next alarm will be triggered
|
||||
*/
|
||||
private void updateAlarm(long triggerTime) {
|
||||
private void updateAlarm(long triggerTimeMicroS) {
|
||||
int notifier = m_notifier.get();
|
||||
if (notifier == 0) {
|
||||
return;
|
||||
}
|
||||
NotifierJNI.updateNotifierAlarm(notifier, triggerTime);
|
||||
NotifierJNI.updateNotifierAlarm(notifier, triggerTimeMicroS);
|
||||
}
|
||||
|
||||
/** Update the alarm hardware to reflect the next alarm. */
|
||||
private void updateAlarm() {
|
||||
updateAlarm((long) (m_expirationTime * 1e6));
|
||||
updateAlarm((long) (m_expirationTimeSeconds * 1e6));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +104,7 @@ public class Notifier implements AutoCloseable {
|
||||
try {
|
||||
handler = m_handler;
|
||||
if (m_periodic) {
|
||||
m_expirationTime += m_period;
|
||||
m_expirationTimeSeconds += m_periodSeconds;
|
||||
updateAlarm();
|
||||
} else {
|
||||
// need to update the alarm to cause it to wait again
|
||||
@@ -165,14 +165,14 @@ public class Notifier implements AutoCloseable {
|
||||
* Register for single event notification. A timer event is queued for a single event after the
|
||||
* specified delay.
|
||||
*
|
||||
* @param delay Seconds to wait before the handler is called.
|
||||
* @param delaySeconds Seconds to wait before the handler is called.
|
||||
*/
|
||||
public void startSingle(double delay) {
|
||||
public void startSingle(double delaySeconds) {
|
||||
m_processLock.lock();
|
||||
try {
|
||||
m_periodic = false;
|
||||
m_period = delay;
|
||||
m_expirationTime = RobotController.getFPGATime() * 1e-6 + delay;
|
||||
m_periodSeconds = delaySeconds;
|
||||
m_expirationTimeSeconds = RobotController.getFPGATime() * 1e-6 + delaySeconds;
|
||||
updateAlarm();
|
||||
} finally {
|
||||
m_processLock.unlock();
|
||||
@@ -184,15 +184,15 @@ public class Notifier implements AutoCloseable {
|
||||
* notification. Each time the interrupt occurs, the event will be immediately requeued for the
|
||||
* same time interval.
|
||||
*
|
||||
* @param period Period in seconds to call the handler starting one period after the call to this
|
||||
* method.
|
||||
* @param periodSeconds Period in seconds to call the handler starting one period after the call
|
||||
* to this method.
|
||||
*/
|
||||
public void startPeriodic(double period) {
|
||||
public void startPeriodic(double periodSeconds) {
|
||||
m_processLock.lock();
|
||||
try {
|
||||
m_periodic = true;
|
||||
m_period = period;
|
||||
m_expirationTime = RobotController.getFPGATime() * 1e-6 + period;
|
||||
m_periodSeconds = periodSeconds;
|
||||
m_expirationTimeSeconds = RobotController.getFPGATime() * 1e-6 + periodSeconds;
|
||||
updateAlarm();
|
||||
} finally {
|
||||
m_processLock.unlock();
|
||||
|
||||
@@ -114,7 +114,7 @@ public final class RobotController {
|
||||
/**
|
||||
* Get the current output of the 3.3V rail.
|
||||
*
|
||||
* @return The controller 3.3V rail output current value in Volts
|
||||
* @return The controller 3.3V rail output current value in Amps
|
||||
*/
|
||||
public static double getCurrent3V3() {
|
||||
return PowerJNI.getUserCurrent3V3();
|
||||
|
||||
@@ -19,13 +19,13 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
*/
|
||||
public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
// Used for timeout print rate-limiting
|
||||
private static final long kMinPrintPeriod = 1000000; // microseconds
|
||||
private static final long kMinPrintPeriodMicroS = (long) 1e6;
|
||||
|
||||
private double m_startTime; // seconds
|
||||
private double m_timeout; // seconds
|
||||
private double m_expirationTime; // seconds
|
||||
private double m_startTimeSeconds;
|
||||
private double m_timeoutSeconds;
|
||||
private double m_expirationTimeSeconds;
|
||||
private final Runnable m_callback;
|
||||
private double m_lastTimeoutPrintTime; // seconds
|
||||
private double m_lastTimeoutPrintSeconds;
|
||||
|
||||
boolean m_isExpired;
|
||||
|
||||
@@ -46,11 +46,11 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
/**
|
||||
* Watchdog constructor.
|
||||
*
|
||||
* @param timeout The watchdog's timeout in seconds with microsecond resolution.
|
||||
* @param timeoutSeconds The watchdog's timeout in seconds with microsecond resolution.
|
||||
* @param callback This function is called when the timeout expires.
|
||||
*/
|
||||
public Watchdog(double timeout, Runnable callback) {
|
||||
m_timeout = timeout;
|
||||
public Watchdog(double timeoutSeconds, Runnable callback) {
|
||||
m_timeoutSeconds = timeoutSeconds;
|
||||
m_callback = callback;
|
||||
m_tracer = new Tracer();
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
public int compareTo(Watchdog rhs) {
|
||||
// Elements with sooner expiration times are sorted as lesser. The head of
|
||||
// Java's PriorityQueue is the least element.
|
||||
return Double.compare(m_expirationTime, rhs.m_expirationTime);
|
||||
return Double.compare(m_expirationTimeSeconds, rhs.m_expirationTimeSeconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,12 +73,12 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
return false;
|
||||
}
|
||||
Watchdog oth = (Watchdog) obj;
|
||||
return oth.m_expirationTime == m_expirationTime;
|
||||
return oth.m_expirationTimeSeconds == m_expirationTimeSeconds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Double.hashCode(m_expirationTime);
|
||||
return Double.hashCode(m_expirationTimeSeconds);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,25 +87,25 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
* @return The time in seconds since the watchdog was last fed.
|
||||
*/
|
||||
public double getTime() {
|
||||
return Timer.getFPGATimestamp() - m_startTime;
|
||||
return Timer.getFPGATimestamp() - m_startTimeSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the watchdog's timeout.
|
||||
*
|
||||
* @param timeout The watchdog's timeout in seconds with microsecond resolution.
|
||||
* @param timeoutSeconds The watchdog's timeout in seconds with microsecond resolution.
|
||||
*/
|
||||
public void setTimeout(double timeout) {
|
||||
m_startTime = Timer.getFPGATimestamp();
|
||||
public void setTimeout(double timeoutSeconds) {
|
||||
m_startTimeSeconds = Timer.getFPGATimestamp();
|
||||
m_tracer.clearEpochs();
|
||||
|
||||
m_queueMutex.lock();
|
||||
try {
|
||||
m_timeout = timeout;
|
||||
m_timeoutSeconds = timeoutSeconds;
|
||||
m_isExpired = false;
|
||||
|
||||
m_watchdogs.remove(this);
|
||||
m_expirationTime = m_startTime + m_timeout;
|
||||
m_expirationTimeSeconds = m_startTimeSeconds + m_timeoutSeconds;
|
||||
m_watchdogs.add(this);
|
||||
updateAlarm();
|
||||
} finally {
|
||||
@@ -121,7 +121,7 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
public double getTimeout() {
|
||||
m_queueMutex.lock();
|
||||
try {
|
||||
return m_timeout;
|
||||
return m_timeoutSeconds;
|
||||
} finally {
|
||||
m_queueMutex.unlock();
|
||||
}
|
||||
@@ -171,7 +171,7 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
|
||||
/** Enables the watchdog timer. */
|
||||
public void enable() {
|
||||
m_startTime = Timer.getFPGATimestamp();
|
||||
m_startTimeSeconds = Timer.getFPGATimestamp();
|
||||
m_tracer.clearEpochs();
|
||||
|
||||
m_queueMutex.lock();
|
||||
@@ -179,7 +179,7 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
m_isExpired = false;
|
||||
|
||||
m_watchdogs.remove(this);
|
||||
m_expirationTime = m_startTime + m_timeout;
|
||||
m_expirationTimeSeconds = m_startTimeSeconds + m_timeoutSeconds;
|
||||
m_watchdogs.add(this);
|
||||
updateAlarm();
|
||||
} finally {
|
||||
@@ -215,7 +215,7 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
NotifierJNI.cancelNotifierAlarm(m_notifier);
|
||||
} else {
|
||||
NotifierJNI.updateNotifierAlarm(
|
||||
m_notifier, (long) (m_watchdogs.peek().m_expirationTime * 1e6));
|
||||
m_notifier, (long) (m_watchdogs.peek().m_expirationTimeSeconds * 1e6));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,11 +245,11 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
Watchdog watchdog = m_watchdogs.poll();
|
||||
|
||||
double now = curTime * 1e-6;
|
||||
if (now - watchdog.m_lastTimeoutPrintTime > kMinPrintPeriod) {
|
||||
watchdog.m_lastTimeoutPrintTime = now;
|
||||
if (now - watchdog.m_lastTimeoutPrintSeconds > kMinPrintPeriodMicroS) {
|
||||
watchdog.m_lastTimeoutPrintSeconds = now;
|
||||
if (!watchdog.m_suppressTimeoutMessage) {
|
||||
DriverStation.reportWarning(
|
||||
String.format("Watchdog not fed within %.6fs\n", watchdog.m_timeout), false);
|
||||
String.format("Watchdog not fed within %.6fs\n", watchdog.m_timeoutSeconds), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user