[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 @@ 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

View File

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

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