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(); virtual void TestPeriodic();
protected: protected:
virtual void Prestart();
virtual ~IterativeRobot() = default; virtual ~IterativeRobot() = default;
IterativeRobot() = default; IterativeRobot() = default;

View File

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

View File

@@ -16,11 +16,6 @@
constexpr double IterativeRobot::kDefaultPeriod; 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(). * Provide an alternate "main loop" via StartCompetition().
* *
@@ -39,10 +34,7 @@ void IterativeRobot::StartCompetition() {
->PutBoolean("LW Enabled", false); ->PutBoolean("LW Enabled", false);
RobotInit(); RobotInit();
// We call this now (not in Prestart like default) so that the robot // Tell the DS that the robot is ready to be enabled
// 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.
HALNetworkCommunicationObserveUserProgramStarting(); HALNetworkCommunicationObserveUserProgramStarting();
// loop forever, calling the appropriate mode-dependent function // loop forever, calling the appropriate mode-dependent function
@@ -116,9 +108,13 @@ void IterativeRobot::StartCompetition() {
* Robot-wide initialization code should go here. * Robot-wide initialization code should go here.
* *
* Users should override this method for default Robot-wide initialization which * Users should override this method for default Robot-wide initialization which
* will * will be called when the robot is first powered on. It will be called exactly
* be called when the robot is first powered on. It will be called exactly 1 * one time.
* 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() { void IterativeRobot::RobotInit() {
printf("Default %s() method... Overload me!\n", __FUNCTION__); 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; } RobotBase &RobotBase::getInstance() { return *m_instance; }
void RobotBase::robotSetup(RobotBase *robot) { void RobotBase::robotSetup(RobotBase *robot) {
robot->Prestart();
robot->StartCompetition(); robot->StartCompetition();
} }
@@ -107,19 +106,6 @@ bool RobotBase::IsOperatorControl() const { return m_ds.IsOperatorControl(); }
*/ */
bool RobotBase::IsTest() const { return m_ds.IsTest(); } 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. * Indicates if new data is available from the driver station.
* @return Has new data arrived over the network since the last time this * @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. * Robot-wide initialization code should go here.
* *
* Programmers should override this method for default Robot-wide initialization * Users should override this method for default Robot-wide initialization which
* which will * will be called when the robot is first powered on. It will be called exactly
* be called each time the robot enters the disabled state. * 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() { void SampleRobot::RobotInit() {
printf("Default %s() method... Override me!\n", __FUNCTION__); printf("Default %s() method... Override me!\n", __FUNCTION__);
@@ -111,12 +116,16 @@ void SampleRobot::StartCompetition() {
->GetSubTable("~STATUS~") ->GetSubTable("~STATUS~")
->PutBoolean("LW Enabled", false); ->PutBoolean("LW Enabled", false);
RobotInit();
// Tell the DS that the robot is ready to be enabled
HALNetworkCommunicationObserveUserProgramStarting();
RobotMain(); RobotMain();
if (!m_robotMainOverridden) { if (!m_robotMainOverridden) {
// first and one-time initialization // first and one-time initialization
lw->SetEnabled(false); lw->SetEnabled(false);
RobotInit();
while (true) { while (true) {
if (IsDisabled()) { if (IsDisabled()) {

View File

@@ -61,12 +61,6 @@ public class IterativeRobot extends RobotBase {
m_testInitialized = false; 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(). * Provide an alternate "main loop" via startCompetition().
* *
@@ -76,10 +70,7 @@ public class IterativeRobot extends RobotBase {
robotInit(); robotInit();
// We call this now (not in prestart like default) so that the robot // Tell the DS that the robot is ready to be enabled
// 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.
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramStarting(); FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramStarting();
// loop forever, calling the appropriate mode-dependent function // 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 * 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 * 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() { public void robotInit() {
System.out.println("Default IterativeRobot.robotInit() method... Overload me!"); System.out.println("Default IterativeRobot.robotInit() method... Overload me!");

View File

@@ -148,18 +148,6 @@ public abstract class RobotBase {
*/ */
public abstract void startCompetition(); 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) { public static boolean getBooleanProperty(String name, boolean defaultValue) {
String propVal = System.getProperty(name); String propVal = System.getProperty(name);
if (propVal == null) { if (propVal == null) {
@@ -213,7 +201,6 @@ public abstract class RobotBase {
RobotBase robot; RobotBase robot;
try { try {
robot = (RobotBase) Class.forName(robotName).newInstance(); robot = (RobotBase) Class.forName(robotName).newInstance();
robot.prestart();
} catch (Throwable t) { } catch (Throwable t) {
DriverStation.reportError("ERROR Unhandled exception instantiating robot " + robotName + " " DriverStation.reportError("ERROR Unhandled exception instantiating robot " + robotName + " "
+ t.toString() + " at " + Arrays.toString(t.getStackTrace()), false); + t.toString() + " at " + Arrays.toString(t.getStackTrace()), false);

View File

@@ -8,6 +8,7 @@
package edu.wpi.first.wpilibj; package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.communication.UsageReporting; 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.tInstances;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.Timer;
@@ -41,9 +42,13 @@ public class SampleRobot extends RobotBase {
* Robot-wide initialization code should go here. * Robot-wide initialization code should go here.
* *
* Users should override this method for default Robot-wide initialization * 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() { protected void robotInit() {
System.out.println("Default robotInit() method running, consider providing your own"); System.out.println("Default robotInit() method running, consider providing your own");
@@ -116,11 +121,15 @@ public class SampleRobot extends RobotBase {
public void startCompetition() { public void startCompetition() {
UsageReporting.report(tResourceType.kResourceType_Framework, tInstances.kFramework_Sample); UsageReporting.report(tResourceType.kResourceType_Framework, tInstances.kFramework_Sample);
robotInit();
// Tell the DS that the robot is ready to be enabled
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramStarting();
robotMain(); robotMain();
if (!m_robotMainOverridden) { if (!m_robotMainOverridden) {
// first and one-time initialization // first and one-time initialization
LiveWindow.setEnabled(false); LiveWindow.setEnabled(false);
robotInit();
while (true) { while (true) {
if (isDisabled()) { if (isDisabled()) {