[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 @@
#include "frc/IterativeRobotBase.h"
#include <hal/DriverStation.h>
#include <networktables/NetworkTableInstance.h>
#include <wpi/Format.h>
#include <wpi/SmallString.h>
#include <wpi/raw_ostream.h>
@@ -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();