From d34c8449004f0c29e4562f4e5936db58eb7e87b5 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sat, 1 Jul 2017 01:12:28 -0400 Subject: [PATCH] Fixed function ordering in robot base classes (#553) --- wpilibc/athena/include/IterativeRobot.h | 5 +- wpilibc/athena/include/SampleRobot.h | 9 +- wpilibc/athena/src/SampleRobot.cpp | 118 ++++++++++++------------ 3 files changed, 67 insertions(+), 65 deletions(-) diff --git a/wpilibc/athena/include/IterativeRobot.h b/wpilibc/athena/include/IterativeRobot.h index 34847d6454..e10dd2bbea 100644 --- a/wpilibc/athena/include/IterativeRobot.h +++ b/wpilibc/athena/include/IterativeRobot.h @@ -43,10 +43,9 @@ namespace frc { * - TestPeriodic() * */ - class IterativeRobot : public RobotBase { public: - virtual void StartCompetition(); + void StartCompetition() override; virtual void RobotInit(); virtual void DisabledInit(); @@ -61,8 +60,8 @@ class IterativeRobot : public RobotBase { virtual void TestPeriodic(); protected: - virtual ~IterativeRobot() = default; IterativeRobot() = default; + virtual ~IterativeRobot() = default; private: bool m_disabledInitialized = false; diff --git a/wpilibc/athena/include/SampleRobot.h b/wpilibc/athena/include/SampleRobot.h index 09051e5c71..372221e72c 100644 --- a/wpilibc/athena/include/SampleRobot.h +++ b/wpilibc/athena/include/SampleRobot.h @@ -13,15 +13,18 @@ namespace frc { class SampleRobot : public RobotBase { public: - SampleRobot(); - virtual ~SampleRobot() = default; + void StartCompetition() override; + virtual void RobotInit(); virtual void Disabled(); virtual void Autonomous(); virtual void OperatorControl(); virtual void Test(); virtual void RobotMain(); - void StartCompetition(); + + protected: + SampleRobot(); + virtual ~SampleRobot() = default; private: bool m_robotMainOverridden; diff --git a/wpilibc/athena/src/SampleRobot.cpp b/wpilibc/athena/src/SampleRobot.cpp index 5ef7ef41a9..a7daacf783 100644 --- a/wpilibc/athena/src/SampleRobot.cpp +++ b/wpilibc/athena/src/SampleRobot.cpp @@ -15,7 +15,64 @@ using namespace frc; -SampleRobot::SampleRobot() : m_robotMainOverridden(true) {} +/** + * Start a competition. + * + * This code needs to track the order of the field starting to ensure that + * everything happens in the right order. Repeatedly run the correct method, + * either Autonomous or OperatorControl or Test when the robot is enabled. + * After running the correct method, wait for some state to change, either the + * other mode starts or the robot is disabled. Then go back and wait for the + * robot to be enabled again. + */ +void SampleRobot::StartCompetition() { + LiveWindow* lw = LiveWindow::GetInstance(); + + HAL_Report(HALUsageReporting::kResourceType_Framework, + HALUsageReporting::kFramework_Simple); + + NetworkTable::GetTable("LiveWindow") + ->GetSubTable("~STATUS~") + ->PutBoolean("LW Enabled", false); + + RobotInit(); + + // Tell the DS that the robot is ready to be enabled + HAL_ObserveUserProgramStarting(); + + RobotMain(); + + if (!m_robotMainOverridden) { + // first and one-time initialization + lw->SetEnabled(false); + + while (true) { + if (IsDisabled()) { + m_ds.InDisabled(true); + Disabled(); + m_ds.InDisabled(false); + while (IsDisabled()) m_ds.WaitForData(); + } else if (IsAutonomous()) { + m_ds.InAutonomous(true); + Autonomous(); + m_ds.InAutonomous(false); + while (IsAutonomous() && IsEnabled()) m_ds.WaitForData(); + } else if (IsTest()) { + lw->SetEnabled(true); + m_ds.InTest(true); + Test(); + m_ds.InTest(false); + while (IsTest() && IsEnabled()) m_ds.WaitForData(); + lw->SetEnabled(false); + } else { + m_ds.InOperatorControl(true); + OperatorControl(); + m_ds.InOperatorControl(false); + while (IsOperatorControl() && IsEnabled()) m_ds.WaitForData(); + } + } + } +} /** * Robot-wide initialization code should go here. @@ -90,61 +147,4 @@ void SampleRobot::Test() { */ void SampleRobot::RobotMain() { m_robotMainOverridden = false; } -/** - * Start a competition. - * - * This code needs to track the order of the field starting to ensure that - * everything happens in the right order. Repeatedly run the correct method, - * either Autonomous or OperatorControl or Test when the robot is enabled. - * After running the correct method, wait for some state to change, either the - * other mode starts or the robot is disabled. Then go back and wait for the - * robot to be enabled again. - */ -void SampleRobot::StartCompetition() { - LiveWindow* lw = LiveWindow::GetInstance(); - - HAL_Report(HALUsageReporting::kResourceType_Framework, - HALUsageReporting::kFramework_Simple); - - NetworkTable::GetTable("LiveWindow") - ->GetSubTable("~STATUS~") - ->PutBoolean("LW Enabled", false); - - RobotInit(); - - // Tell the DS that the robot is ready to be enabled - HAL_ObserveUserProgramStarting(); - - RobotMain(); - - if (!m_robotMainOverridden) { - // first and one-time initialization - lw->SetEnabled(false); - - while (true) { - if (IsDisabled()) { - m_ds.InDisabled(true); - Disabled(); - m_ds.InDisabled(false); - while (IsDisabled()) m_ds.WaitForData(); - } else if (IsAutonomous()) { - m_ds.InAutonomous(true); - Autonomous(); - m_ds.InAutonomous(false); - while (IsAutonomous() && IsEnabled()) m_ds.WaitForData(); - } else if (IsTest()) { - lw->SetEnabled(true); - m_ds.InTest(true); - Test(); - m_ds.InTest(false); - while (IsTest() && IsEnabled()) m_ds.WaitForData(); - lw->SetEnabled(false); - } else { - m_ds.InOperatorControl(true); - OperatorControl(); - m_ds.InOperatorControl(false); - while (IsOperatorControl() && IsEnabled()) m_ds.WaitForData(); - } - } - } -} +SampleRobot::SampleRobot() : m_robotMainOverridden(true) {}