Class RobotBase

java.lang.Object
edu.wpi.first.wpilibj.RobotBase
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
IterativeRobotBase

public abstract class RobotBase
extends Object
implements AutoCloseable
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 
    Modifier Constructor Description
    protected RobotBase()
    Constructor for a generic robot program.
  • Method Summary

    Modifier and Type Method Description
    void close()  
    abstract void endCompetition()
    Ends the main loop in startCompetition().
    static long getMainThreadId()  
    static RuntimeType getRuntimeType()
    Get the current runtime type.
    boolean isAutonomous()
    Determine if the robot is currently in Autonomous mode as determined by the Driver Station.
    boolean isAutonomousEnabled()
    Determine if the robot is currently in Autonomous mode and enabled as determined by the Driver Station.
    boolean isDisabled()
    Determine if the Robot is currently disabled.
    boolean isEnabled()
    Determine if the Robot is currently enabled.
    static boolean isReal()
    Get if the robot is real.
    static boolean isSimulation()
    Get if the robot is a simulation.
    boolean isTeleop()
    Determine if the robot is currently in Operator Control mode as determined by the Driver Station.
    boolean isTeleopEnabled()
    Determine if the robot is currently in Operator Control mode and enabled as determined by the Driver Station.
    boolean isTest()
    Determine if the robot is currently in Test mode as determined by the Driver Station.
    boolean isTestEnabled()
    Determine if the robot is current in Test mode and enabled as determined by the Driver Station.
    abstract void startCompetition()
    Start the main robot code.
    static <T extends RobotBase>
    void
    startRobot​(Supplier<T> robotSupplier)
    Starting point for the applications.
    static void suppressExitWarning​(boolean value)
    Suppress the "The robot program quit unexpectedly." message.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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()
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • getRuntimeType

      public static RuntimeType 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 boolean isDisabled()
      Determine if the Robot is currently disabled.
      Returns:
      True if the Robot is currently disabled by the Driver Station.
    • isEnabled

      public boolean isEnabled()
      Determine if the Robot is currently enabled.
      Returns:
      True if the Robot is currently enabled by the Driver Station.
    • isAutonomous

      public 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 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.
    • isTest

      public boolean isTest()
      Determine if the robot is currently in Test mode as determined by the Driver Station.
      Returns:
      True if the robot is currently operating in Test mode.
    • isTestEnabled

      public boolean isTestEnabled()
      Determine if the robot is current in Test mode and enabled as determined by the Driver Station.
      Returns:
      True if the robot is currently operating in Test mode while enabled.
    • isTeleop

      public 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 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.
    • startCompetition

      public abstract void startCompetition()
      Start the main robot code. This function will be called once and should not exit until signalled by endCompetition()
    • endCompetition

      public abstract void endCompetition()
      Ends the main loop in startCompetition().
    • 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

      public static <T extends RobotBase> void startRobot​(Supplier<T> robotSupplier)
      Starting point for the applications.
      Type Parameters:
      T - Robot subclass.
      Parameters:
      robotSupplier - Function that returns an instance of the robot subclass.