[wpilib] Add option to flush NetworkTables every iterative loop

This functionality is disabled by default, but can be enabled by the user
program by calling setNetworkTablesFlushEnabled.
This commit is contained in:
Peter Johnson
2020-12-12 23:16:50 -08:00
parent acfbb1a44a
commit 581b7ec553
3 changed files with 34 additions and 0 deletions

View File

@@ -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();