Class RobotBase
java.lang.Object
org.wpilib.framework.RobotBase
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
IterativeRobotBase, OpModeRobot
Implement a Robot Program framework. The RobotBase class is intended to be subclassed to create a
robot program. The user must implement
startCompetition(), which will be called once and
is not expected to exit. The user must also implement endCompetition(), which signals to
the code in startCompetition() that it should exit.
It is not recommended to subclass this class directly - instead subclass IterativeRobotBase or TimedRobot.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()abstract voidEnds the main loop instartCompetition().static longReturns the main thread ID.static StringGets the currently selected operating mode of the driver station.static longGets the currently selected operating mode of the driver station.protected static StringgetRobotName(StackTraceElement[] elements) Gets the Robot subclass name from a stack trace.static RuntimeTypeGet the current runtime type.static booleanDetermine if the robot is currently in Autonomous mode as determined by the Driver Station.static booleanDetermine if the robot is currently in Autonomous mode and enabled as determined by the Driver Station.static booleanDetermine if the Robot is currently disabled.static booleanDetermine if the Robot is currently enabled.static booleanisReal()Get if the robot is real.static booleanGet if the robot is a simulation.static booleanisTeleop()Determine if the robot is currently in Operator Control mode as determined by the Driver Station.static booleanDetermine if the robot is currently in Operator Control mode and enabled as determined by the Driver Station.static booleanDetermine if the robot is currently in Utility mode as determined by the Driver Station.static booleanDetermine if the robot is current in Utility mode and enabled as determined by the Driver Station.abstract voidStart the main robot code.static <T extends RobotBase>
voidstartRobot(Supplier<T> robotConstructor) Starting point for the applications.static voidsuppressExitWarning(boolean value) Suppress the "The robot program quit unexpectedly." message.
-
Constructor Details
-
RobotBase
protected RobotBase()Constructor for a generic robot program. User code can be placed in the constructor that runs before the Autonomous or Operator Control period starts. The constructor will run to completion before Autonomous is entered.This must be used to ensure that the communications code starts. In the future it would be nice to put this code into its own task that loads on boot so ensure that it runs.
-
-
Method Details
-
getMainThreadId
public static long getMainThreadId()Returns the main thread ID.- Returns:
- The main thread ID.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
getRuntimeType
Get the current runtime type.- Returns:
- Current runtime type.
-
isSimulation
public static boolean isSimulation()Get if the robot is a simulation.- Returns:
- If the robot is running in simulation.
-
isReal
public static boolean isReal()Get if the robot is real.- Returns:
- If the robot is running in the real world.
-
isDisabled
public static boolean isDisabled()Determine if the Robot is currently disabled.- Returns:
- True if the Robot is currently disabled by the Driver Station.
-
isEnabled
public static boolean isEnabled()Determine if the Robot is currently enabled.- Returns:
- True if the Robot is currently enabled by the Driver Station.
-
isAutonomous
public static boolean isAutonomous()Determine if the robot is currently in Autonomous mode as determined by the Driver Station.- Returns:
- True if the robot is currently operating Autonomously.
-
isAutonomousEnabled
public static boolean isAutonomousEnabled()Determine if the robot is currently in Autonomous mode and enabled as determined by the Driver Station.- Returns:
- True if the robot is currently operating autonomously while enabled.
-
isUtility
public static boolean isUtility()Determine if the robot is currently in Utility mode as determined by the Driver Station.- Returns:
- True if the robot is currently operating in Utility mode.
-
isUtilityEnabled
public static boolean isUtilityEnabled()Determine if the robot is current in Utility mode and enabled as determined by the Driver Station.- Returns:
- True if the robot is currently operating in Utility mode while enabled.
-
isTeleop
public static boolean isTeleop()Determine if the robot is currently in Operator Control mode as determined by the Driver Station.- Returns:
- True if the robot is currently operating in Tele-Op mode.
-
isTeleopEnabled
public static boolean isTeleopEnabled()Determine if the robot is currently in Operator Control mode and enabled as determined by the Driver Station.- Returns:
- True if the robot is currently operating in Tele-Op mode while enabled.
-
getOpModeId
public static long getOpModeId()Gets the currently selected operating mode of the driver station. Note this does not mean the robot is enabled; use isEnabled() for that.- Returns:
- the unique ID provided by the DriverStation.addOpMode() function; may return 0 or a unique ID not added, so callers should be prepared to handle that case
-
getOpMode
Gets the currently selected operating mode of the driver station. Note this does not mean the robot is enabled; use isEnabled() for that.- Returns:
- Operating mode string; may return a string not in the list of options, so callers should be prepared to handle that case
-
startCompetition
public abstract void startCompetition()Start the main robot code. This function will be called once and should not exit until signalled byendCompetition() -
endCompetition
public abstract void endCompetition()Ends the main loop instartCompetition(). -
getRobotName
Gets the Robot subclass name from a stack trace.- Parameters:
elements- The stack trace elements to walk.- Returns:
- The Robot subclass name.
-
suppressExitWarning
public static void suppressExitWarning(boolean value) Suppress the "The robot program quit unexpectedly." message.- Parameters:
value- True if exit warning should be suppressed.
-
startRobot
-