[wpilib] Add robot callback that is called when the DS is initially connected (#5231)

This commit is contained in:
Thad House
2023-06-21 14:53:34 -07:00
committed by GitHub
parent ebae341a91
commit 61aa60f0e3
3 changed files with 35 additions and 0 deletions

View File

@@ -24,6 +24,8 @@ import java.util.ConcurrentModificationException;
*
* <p>robotInit() -- provide for initialization at robot power-on
*
* <p>driverStationConnected() -- provide for initialization the first time the DS is connected
*
* <p>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.
*
* <p>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