mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Resolved artf3579: robot can no longer be enabled until robotInit() finishes in IterativeRobot; similar options available by overriding prestart() for other base classes.
Change-Id: I07fde4b1bd2fae0c2e2a04336639b44ec715628a
This commit is contained in:
@@ -59,6 +59,12 @@ public class IterativeRobot extends RobotBase {
|
||||
m_teleopInitialized = 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().
|
||||
@@ -68,15 +74,12 @@ public class IterativeRobot extends RobotBase {
|
||||
UsageReporting.report(tResourceType.kResourceType_Framework, tInstances.kFramework_Iterative);
|
||||
|
||||
robotInit();
|
||||
|
||||
// tracing support:
|
||||
final int TRACE_LOOP_MAX = 100;
|
||||
int loopCount = TRACE_LOOP_MAX;
|
||||
Object marker = null;
|
||||
boolean didDisabledPeriodic = false;
|
||||
boolean didAutonomousPeriodic = false;
|
||||
boolean didTeleopPeriodic = false;
|
||||
boolean didTestPeriodic = false;
|
||||
|
||||
// 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.
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramStarting();
|
||||
|
||||
// loop forever, calling the appropriate mode-dependent function
|
||||
LiveWindow.setEnabled(false);
|
||||
@@ -97,7 +100,6 @@ public class IterativeRobot extends RobotBase {
|
||||
if (nextPeriodReady()) {
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramDisabled();
|
||||
disabledPeriodic();
|
||||
didDisabledPeriodic = true;
|
||||
}
|
||||
} else if (isTest()) {
|
||||
// call TestInit() if we are now just entering test mode from either
|
||||
@@ -113,7 +115,6 @@ public class IterativeRobot extends RobotBase {
|
||||
if (nextPeriodReady()) {
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramTest();
|
||||
testPeriodic();
|
||||
didTestPeriodic = true;
|
||||
}
|
||||
} else if (isAutonomous()) {
|
||||
// call Autonomous_Init() if this is the first time
|
||||
@@ -132,7 +133,6 @@ public class IterativeRobot extends RobotBase {
|
||||
if (nextPeriodReady()) {
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramAutonomous();
|
||||
autonomousPeriodic();
|
||||
didAutonomousPeriodic = true;
|
||||
}
|
||||
} else {
|
||||
// call Teleop_Init() if this is the first time
|
||||
@@ -148,7 +148,6 @@ public class IterativeRobot extends RobotBase {
|
||||
if (nextPeriodReady()) {
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramTeleop();
|
||||
teleopPeriodic();
|
||||
didTeleopPeriodic = true;
|
||||
}
|
||||
}
|
||||
m_ds.waitForData();
|
||||
|
||||
@@ -130,6 +130,15 @@ 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.
|
||||
*/
|
||||
protected void prestart() {
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramStarting();
|
||||
}
|
||||
|
||||
public static boolean getBooleanProperty(String name, boolean defaultValue) {
|
||||
String propVal = System.getProperty(name);
|
||||
if (propVal == null) {
|
||||
@@ -149,7 +158,6 @@ public abstract class RobotBase {
|
||||
*/
|
||||
public static void initializeHardwareConfiguration(){
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationReserve();
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramStarting();
|
||||
|
||||
// Set some implementations so that the static methods work properly
|
||||
Timer.SetImplementation(new HardwareTimer());
|
||||
@@ -161,8 +169,6 @@ public abstract class RobotBase {
|
||||
* Starting point for the applications.
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
boolean errorOnExit = false;
|
||||
|
||||
initializeHardwareConfiguration();
|
||||
|
||||
UsageReporting.report(tResourceType.kResourceType_Language, tInstances.kLanguage_Java);
|
||||
@@ -182,14 +188,16 @@ 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);
|
||||
System.err.println("WARNING: Robots don't quit!");
|
||||
System.err.println("ERROR: Could not instantiate robot "+robotName+"!");
|
||||
System.err.println("ERROR: Could not instantiate robot " + robotName + "!");
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean errorOnExit = false;
|
||||
try {
|
||||
robot.startCompetition();
|
||||
} catch (Throwable t) {
|
||||
|
||||
Reference in New Issue
Block a user