mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
Fixed function ordering in robot base classes (#553)
This commit is contained in:
committed by
Peter Johnson
parent
68b63632c4
commit
d34c844900
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
Reference in New Issue
Block a user