mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
Suppress Watchdog's generic timeout message in MotorSafety (#1486)
This commit is contained in:
committed by
Peter Johnson
parent
0c3b488e18
commit
41596608cc
@@ -19,12 +19,14 @@ using namespace frc;
|
||||
MotorSafety::MotorSafety(MotorSafety&& rhs)
|
||||
: ErrorBase(std::move(rhs)), m_enabled(std::move(rhs.m_enabled)) {
|
||||
m_watchdog = Watchdog(rhs.m_watchdog.GetTimeout(), [this] { TimeoutFunc(); });
|
||||
m_watchdog.SuppressTimeoutMessage(true);
|
||||
}
|
||||
|
||||
MotorSafety& MotorSafety::operator=(MotorSafety&& rhs) {
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
|
||||
m_watchdog = Watchdog(rhs.m_watchdog.GetTimeout(), [this] { TimeoutFunc(); });
|
||||
m_watchdog.SuppressTimeoutMessage(true);
|
||||
m_enabled = std::move(rhs.m_enabled);
|
||||
|
||||
return *this;
|
||||
|
||||
@@ -51,10 +51,12 @@ void Watchdog::Thread::Main() {
|
||||
auto now = hal::fpga_clock::now();
|
||||
if (now - watchdog->m_lastTimeoutPrintTime > kMinPrintPeriod) {
|
||||
watchdog->m_lastTimeoutPrintTime = now;
|
||||
wpi::outs() << "Watchdog not fed within "
|
||||
<< wpi::format("%.6f",
|
||||
watchdog->m_timeout.count() / 1.0e6)
|
||||
<< "s\n";
|
||||
if (!watchdog->m_suppressTimeoutMessage) {
|
||||
wpi::outs() << "Watchdog not fed within "
|
||||
<< wpi::format("%.6f",
|
||||
watchdog->m_timeout.count() / 1.0e6)
|
||||
<< "s\n";
|
||||
}
|
||||
}
|
||||
lock.unlock();
|
||||
watchdog->m_callback();
|
||||
@@ -159,6 +161,10 @@ void Watchdog::Disable() {
|
||||
thr->m_cond.notify_all();
|
||||
}
|
||||
|
||||
void Watchdog::SuppressTimeoutMessage(bool suppress) {
|
||||
m_suppressTimeoutMessage = suppress;
|
||||
}
|
||||
|
||||
bool Watchdog::operator>(const Watchdog& rhs) {
|
||||
return m_expirationTime > rhs.m_expirationTime;
|
||||
}
|
||||
|
||||
@@ -104,6 +104,16 @@ class Watchdog {
|
||||
*/
|
||||
void Disable();
|
||||
|
||||
/**
|
||||
* Enable or disable suppression of the generic timeout message.
|
||||
*
|
||||
* This may be desirable if the user-provided callback already prints a more
|
||||
* specific message.
|
||||
*
|
||||
* @param suppress Whether to suppress generic timeout message.
|
||||
*/
|
||||
void SuppressTimeoutMessage(bool suppress);
|
||||
|
||||
private:
|
||||
// Used for timeout print rate-limiting
|
||||
static constexpr std::chrono::milliseconds kMinPrintPeriod{1000};
|
||||
@@ -118,6 +128,8 @@ class Watchdog {
|
||||
wpi::StringMap<std::chrono::microseconds> m_epochs;
|
||||
bool m_isExpired = false;
|
||||
|
||||
bool m_suppressTimeoutMessage = false;
|
||||
|
||||
class Thread;
|
||||
wpi::SafeThreadOwner<Thread>* m_owner;
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@ public abstract class MotorSafety {
|
||||
private boolean m_enabled;
|
||||
private final Object m_thisMutex = new Object();
|
||||
|
||||
public MotorSafety() {
|
||||
m_watchdog.suppressTimeoutMessage(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Feed the motor safety object.
|
||||
*
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
*
|
||||
* <p>The watchdog is initialized disabled, so the user needs to call enable() before use.
|
||||
*/
|
||||
@SuppressWarnings("PMD.TooManyMethods")
|
||||
public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
// Used for timeout print rate-limiting
|
||||
private static final long kMinPrintPeriod = 1000000; // us
|
||||
@@ -38,6 +39,8 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
private final Map<String, Long> m_epochs = new HashMap<>();
|
||||
boolean m_isExpired;
|
||||
|
||||
boolean m_suppressTimeoutMessage;
|
||||
|
||||
static {
|
||||
startDaemonThread(() -> schedulerFunc());
|
||||
}
|
||||
@@ -201,6 +204,17 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable suppression of the generic timeout message.
|
||||
*
|
||||
* <p>This may be desirable if the user-provided callback already prints a more specific message.
|
||||
*
|
||||
* @param suppress Whether to suppress generic timeout message.
|
||||
*/
|
||||
public void suppressTimeoutMessage(boolean suppress) {
|
||||
m_suppressTimeoutMessage = suppress;
|
||||
}
|
||||
|
||||
private static Thread startDaemonThread(Runnable target) {
|
||||
Thread inst = new Thread(target);
|
||||
inst.setDaemon(true);
|
||||
@@ -229,7 +243,9 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
long now = RobotController.getFPGATime();
|
||||
if (now - watchdog.m_lastTimeoutPrintTime > kMinPrintPeriod) {
|
||||
watchdog.m_lastTimeoutPrintTime = now;
|
||||
System.out.format("Watchdog not fed within %.6fs\n", watchdog.m_timeout / 1.0e6);
|
||||
if (!watchdog.m_suppressTimeoutMessage) {
|
||||
System.out.format("Watchdog not fed within %.6fs\n", watchdog.m_timeout / 1.0e6);
|
||||
}
|
||||
}
|
||||
m_queueMutex.unlock();
|
||||
watchdog.m_callback.run();
|
||||
|
||||
Reference in New Issue
Block a user