diff --git a/wpilibc/wpilibC++Devices/include/IterativeRobot.h b/wpilibc/wpilibC++Devices/include/IterativeRobot.h index d26ab70b39..ccea4f86c2 100644 --- a/wpilibc/wpilibC++Devices/include/IterativeRobot.h +++ b/wpilibc/wpilibC++Devices/include/IterativeRobot.h @@ -70,8 +70,6 @@ class IterativeRobot : public RobotBase { virtual void TestPeriodic(); protected: - virtual void Prestart(); - virtual ~IterativeRobot() = default; IterativeRobot() = default; diff --git a/wpilibc/wpilibC++Devices/include/RobotBase.h b/wpilibc/wpilibC++Devices/include/RobotBase.h index a7c3fb0d3c..2fcd1467aa 100644 --- a/wpilibc/wpilibC++Devices/include/RobotBase.h +++ b/wpilibc/wpilibC++Devices/include/RobotBase.h @@ -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; diff --git a/wpilibc/wpilibC++Devices/src/IterativeRobot.cpp b/wpilibc/wpilibC++Devices/src/IterativeRobot.cpp index 9a2110d4d8..4027ae7000 100644 --- a/wpilibc/wpilibC++Devices/src/IterativeRobot.cpp +++ b/wpilibc/wpilibC++Devices/src/IterativeRobot.cpp @@ -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__); diff --git a/wpilibc/wpilibC++Devices/src/RobotBase.cpp b/wpilibc/wpilibC++Devices/src/RobotBase.cpp index c1dda66b91..f5b82dde73 100644 --- a/wpilibc/wpilibC++Devices/src/RobotBase.cpp +++ b/wpilibc/wpilibC++Devices/src/RobotBase.cpp @@ -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 diff --git a/wpilibc/wpilibC++Devices/src/SampleRobot.cpp b/wpilibc/wpilibC++Devices/src/SampleRobot.cpp index c8e2e846f7..c13d4312ae 100644 --- a/wpilibc/wpilibC++Devices/src/SampleRobot.cpp +++ b/wpilibc/wpilibC++Devices/src/SampleRobot.cpp @@ -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()) { diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java index 11440b01e3..56b6e2e0ad 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java @@ -61,12 +61,6 @@ public class IterativeRobot extends RobotBase { m_testInitialized = false; } - @Override - protected void prestart() { - // Don't immediately say that the robot's ready to be enabled. - // See below. - } - /** * Provide an alternate "main loop" via startCompetition(). * @@ -76,10 +70,7 @@ public class IterativeRobot extends RobotBase { 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 FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramStarting(); // loop forever, calling the appropriate mode-dependent function @@ -171,7 +162,12 @@ public class IterativeRobot extends RobotBase { * * 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. + * 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. */ public void robotInit() { System.out.println("Default IterativeRobot.robotInit() method... Overload me!"); diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/RobotBase.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/RobotBase.java index 51df54dd44..000f3919c3 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/RobotBase.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/RobotBase.java @@ -148,18 +148,6 @@ public abstract class RobotBase { */ public abstract void startCompetition(); - /** - * 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 FRCNetworkCommunicationsLibrary. - * FRCNetworkCommunicationOvserveUserProgramStarting() from your code when you - * are ready for the robot to be enabled. - */ - protected void prestart() { - FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramStarting(); - } - public static boolean getBooleanProperty(String name, boolean defaultValue) { String propVal = System.getProperty(name); if (propVal == null) { @@ -213,7 +201,6 @@ public abstract class RobotBase { RobotBase robot; try { robot = (RobotBase) Class.forName(robotName).newInstance(); - robot.prestart(); } catch (Throwable t) { DriverStation.reportError("ERROR Unhandled exception instantiating robot " + robotName + " " + t.toString() + " at " + Arrays.toString(t.getStackTrace()), false); diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SampleRobot.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SampleRobot.java index 99c8c54658..7da5471c5f 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SampleRobot.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SampleRobot.java @@ -8,6 +8,7 @@ package edu.wpi.first.wpilibj; import edu.wpi.first.wpilibj.communication.UsageReporting; +import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.Timer; @@ -41,9 +42,13 @@ public class SampleRobot extends RobotBase { * 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. + * which will be called when the robot is first powered on. It will be called + * exactly one time. * - * Called exactly 1 time when the competition starts. + * 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. */ protected void robotInit() { System.out.println("Default robotInit() method running, consider providing your own"); @@ -116,11 +121,15 @@ public class SampleRobot extends RobotBase { public void startCompetition() { UsageReporting.report(tResourceType.kResourceType_Framework, tInstances.kFramework_Sample); + robotInit(); + + // Tell the DS that the robot is ready to be enabled + FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramStarting(); + robotMain(); if (!m_robotMainOverridden) { // first and one-time initialization LiveWindow.setEnabled(false); - robotInit(); while (true) { if (isDisabled()) {