diff --git a/wpilibc/src/main/native/cpp/IterativeRobotBase.cpp b/wpilibc/src/main/native/cpp/IterativeRobotBase.cpp index 1232c65dbf..ee941b61cc 100644 --- a/wpilibc/src/main/native/cpp/IterativeRobotBase.cpp +++ b/wpilibc/src/main/native/cpp/IterativeRobotBase.cpp @@ -24,6 +24,8 @@ IterativeRobotBase::IterativeRobotBase(units::second_t period) void IterativeRobotBase::RobotInit() {} +void IterativeRobotBase::DriverStationConnected() {} + void IterativeRobotBase::SimulationInit() {} void IterativeRobotBase::DisabledInit() {} @@ -127,6 +129,11 @@ void IterativeRobotBase::LoopFunc() { mode = Mode::kTest; } + if (!m_calledDsConnected && word.IsDSAttached()) { + m_calledDsConnected = true; + DriverStationConnected(); + } + // If mode changed, call mode exit and entry functions if (m_lastMode != mode) { // Call last mode's exit function diff --git a/wpilibc/src/main/native/include/frc/IterativeRobotBase.h b/wpilibc/src/main/native/include/frc/IterativeRobotBase.h index 77ed197479..42b0c715df 100644 --- a/wpilibc/src/main/native/include/frc/IterativeRobotBase.h +++ b/wpilibc/src/main/native/include/frc/IterativeRobotBase.h @@ -23,6 +23,9 @@ namespace frc { * * RobotInit() -- provide for initialization at robot power-on * + * DriverStationConnected() -- provide for initialization the first time the DS + * is connected + * * Init() functions -- each of the following functions is called once when the * appropriate mode is entered: * @@ -67,6 +70,14 @@ class IterativeRobotBase : public RobotBase { */ virtual void RobotInit(); + /** + * Code that needs to know the DS state should go here. + * + * Users should override this method for initialization that needs to occur + * after the DS is connected, such as needing the alliance information. + */ + virtual void DriverStationConnected(); + /** * Robot-wide simulation initialization code should go here. * @@ -242,6 +253,7 @@ class IterativeRobotBase : public RobotBase { Watchdog m_watchdog; bool m_ntFlushEnabled = true; bool m_lwEnabledInTest = true; + bool m_calledDsConnected = 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 6c7b8bcbfb..4afece468d 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java @@ -24,6 +24,8 @@ import java.util.ConcurrentModificationException; * *

robotInit() -- provide for initialization at robot power-on * + *

driverStationConnected() -- provide for initialization the first time the DS is connected + * *

init() functions -- each of the following functions is called once when the appropriate mode * is entered: * @@ -69,6 +71,7 @@ public abstract class IterativeRobotBase extends RobotBase { private final Watchdog m_watchdog; private boolean m_ntFlushEnabled = true; private boolean m_lwEnabledInTest = true; + private boolean m_calledDsConnected; /** * Constructor for IterativeRobotBase. @@ -98,6 +101,14 @@ public abstract class IterativeRobotBase extends RobotBase { */ public void robotInit() {} + /** + * Code that needs to know the DS state should go here. + * + *

Users should override this method for initialization that needs to occur after the DS is + * connected, such as needing the alliance information. + */ + public void driverStationConnected() {} + /** * Robot-wide simulation initialization code should go here. * @@ -295,6 +306,11 @@ public abstract class IterativeRobotBase extends RobotBase { mode = Mode.kTest; } + if (!m_calledDsConnected && m_word.isDSAttached()) { + m_calledDsConnected = true; + driverStationConnected(); + } + // If mode changed, call mode exit and entry functions if (m_lastMode != mode) { // Call last mode's exit function