diff --git a/wpilibc/src/main/native/cpp/IterativeRobotBase.cpp b/wpilibc/src/main/native/cpp/IterativeRobotBase.cpp index c99af93aca..2e50600295 100644 --- a/wpilibc/src/main/native/cpp/IterativeRobotBase.cpp +++ b/wpilibc/src/main/native/cpp/IterativeRobotBase.cpp @@ -8,6 +8,7 @@ #include "frc/IterativeRobotBase.h" #include +#include #include #include #include @@ -98,6 +99,10 @@ void IterativeRobotBase::TestPeriodic() { } } +void IterativeRobotBase::SetNetworkTablesFlushEnabled(bool enabled) { + m_ntFlushEnabled = enabled; +} + void IterativeRobotBase::LoopFunc() { m_watchdog.Reset(); @@ -179,6 +184,9 @@ void IterativeRobotBase::LoopFunc() { m_watchdog.Disable(); + // Flush NetworkTables + if (m_ntFlushEnabled) nt::NetworkTableInstance::GetDefault().Flush(); + // Warn on loop time overruns if (m_watchdog.IsExpired()) { m_watchdog.PrintEpochs(); diff --git a/wpilibc/src/main/native/include/frc/IterativeRobotBase.h b/wpilibc/src/main/native/include/frc/IterativeRobotBase.h index 66897aaaac..8a20885915 100644 --- a/wpilibc/src/main/native/include/frc/IterativeRobotBase.h +++ b/wpilibc/src/main/native/include/frc/IterativeRobotBase.h @@ -155,6 +155,14 @@ class IterativeRobotBase : public RobotBase { */ virtual void TestPeriodic(); + /** + * Enables or disables flushing NetworkTables every loop iteration. + * By default, this is disabled. + * + * @param enabled True to enable, false to disable + */ + void SetNetworkTablesFlushEnabled(bool enabled); + /** * Constructor for IterativeRobotBase. * @@ -188,6 +196,7 @@ class IterativeRobotBase : public RobotBase { Mode m_lastMode = Mode::kNone; Watchdog m_watchdog; + bool m_ntFlushEnabled = false; void PrintLoopOverrunMessage(); }; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java index 87d23936b0..c9678671b0 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java @@ -8,6 +8,7 @@ package edu.wpi.first.wpilibj; import edu.wpi.first.hal.HAL; +import edu.wpi.first.networktables.NetworkTableInstance; import edu.wpi.first.wpilibj.livewindow.LiveWindow; import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; @@ -55,6 +56,7 @@ public abstract class IterativeRobotBase extends RobotBase { private Mode m_lastMode = Mode.kNone; private final Watchdog m_watchdog; + private boolean m_ntFlushEnabled; /** * Constructor for IterativeRobotBase. @@ -218,6 +220,16 @@ public abstract class IterativeRobotBase extends RobotBase { } } + /** + * Enables or disables flushing NetworkTables every loop iteration. + * By default, this is disabled. + * + * @param enabled True to enable, false to disable + */ + public void setNetworkTablesFlushEnabled(boolean enabled) { + m_ntFlushEnabled = enabled; + } + @SuppressWarnings("PMD.CyclomaticComplexity") protected void loopFunc() { m_watchdog.reset(); @@ -300,6 +312,11 @@ public abstract class IterativeRobotBase extends RobotBase { m_watchdog.disable(); + // Flush NetworkTables + if (m_ntFlushEnabled) { + NetworkTableInstance.getDefault().flush(); + } + // Warn on loop time overruns if (m_watchdog.isExpired()) { m_watchdog.printEpochs();