Notify the Driver Station that code is ready after robotInit is called

Change-Id: Id833a2a945c14bcbb4761d4fe463c6c9f7c4430c
This commit is contained in:
Tyler Veness
2015-10-20 11:12:02 -07:00
parent 91891081b9
commit 76756048c4
8 changed files with 40 additions and 61 deletions

View File

@@ -70,8 +70,6 @@ class IterativeRobot : public RobotBase {
virtual void TestPeriodic();
protected:
virtual void Prestart();
virtual ~IterativeRobot() = default;
IterativeRobot() = default;

View File

@@ -62,8 +62,6 @@ class RobotBase {
RobotBase(const RobotBase&) = delete;
RobotBase& operator=(const RobotBase&) = delete;
virtual void Prestart();
Task *m_task = nullptr;
DriverStation &m_ds;

View File

@@ -16,11 +16,6 @@
constexpr double IterativeRobot::kDefaultPeriod;
void IterativeRobot::Prestart() {
// Don't immediately say that the robot's ready to be enabled.
// See below.
}
/**
* Provide an alternate "main loop" via StartCompetition().
*
@@ -39,10 +34,7 @@ void IterativeRobot::StartCompetition() {
->PutBoolean("LW Enabled", false);
RobotInit();
// We call this now (not in Prestart like default) so that the robot
// won't enable until the initialization has finished. This is useful
// because otherwise it's sometimes possible to enable the robot
// before the code is ready.
// Tell the DS that the robot is ready to be enabled
HALNetworkCommunicationObserveUserProgramStarting();
// loop forever, calling the appropriate mode-dependent function
@@ -116,9 +108,13 @@ void IterativeRobot::StartCompetition() {
* Robot-wide initialization code should go here.
*
* Users should override this method for default Robot-wide initialization which
* will
* be called when the robot is first powered on. It will be called exactly 1
* time.
* will be called when the robot is first powered on. It will be called exactly
* one time.
*
* Warning: the Driver Station "Robot Code" light and FMS "Robot Ready"
* indicators will be off until RobotInit() exits. Code in RobotInit() that
* waits for enable will cause the robot to never indicate that the code is
* ready, causing the robot to be bypassed in a match.
*/
void IterativeRobot::RobotInit() {
printf("Default %s() method... Overload me!\n", __FUNCTION__);

View File

@@ -30,7 +30,6 @@ void RobotBase::setInstance(RobotBase *robot) {
RobotBase &RobotBase::getInstance() { return *m_instance; }
void RobotBase::robotSetup(RobotBase *robot) {
robot->Prestart();
robot->StartCompetition();
}
@@ -107,19 +106,6 @@ bool RobotBase::IsOperatorControl() const { return m_ds.IsOperatorControl(); }
*/
bool RobotBase::IsTest() const { return m_ds.IsTest(); }
/**
* This hook is called right before startCompetition(). By default, tell the DS
* that the robot is now ready to
* be enabled. If you don't want for the robot to be enabled yet, you can
* override this method to do nothing.
* If you do so, you will need to call
* HALNetworkCommunicationObserveUserProgramStarting() from your code when
* you are ready for the robot to be enabled.
*/
void RobotBase::Prestart() {
HALNetworkCommunicationObserveUserProgramStarting();
}
/**
* Indicates if new data is available from the driver station.
* @return Has new data arrived over the network since the last time this

View File

@@ -19,9 +19,14 @@ SampleRobot::SampleRobot() : m_robotMainOverridden(true) {}
/**
* Robot-wide initialization code should go here.
*
* Programmers should override this method for default Robot-wide initialization
* which will
* be called each time the robot enters the disabled state.
* Users should override this method for default Robot-wide initialization which
* will be called when the robot is first powered on. It will be called exactly
* one time.
*
* Warning: the Driver Station "Robot Code" light and FMS "Robot Ready"
* indicators will be off until RobotInit() exits. Code in RobotInit() that
* waits for enable will cause the robot to never indicate that the code is
* ready, causing the robot to be bypassed in a match.
*/
void SampleRobot::RobotInit() {
printf("Default %s() method... Override me!\n", __FUNCTION__);
@@ -111,12 +116,16 @@ void SampleRobot::StartCompetition() {
->GetSubTable("~STATUS~")
->PutBoolean("LW Enabled", false);
RobotInit();
// Tell the DS that the robot is ready to be enabled
HALNetworkCommunicationObserveUserProgramStarting();
RobotMain();
if (!m_robotMainOverridden) {
// first and one-time initialization
lw->SetEnabled(false);
RobotInit();
while (true) {
if (IsDisabled()) {