Class OpModeRobot

java.lang.Object
org.wpilib.framework.RobotBase
org.wpilib.framework.OpModeRobot
All Implemented Interfaces:
AutoCloseable

public abstract class OpModeRobot extends RobotBase
OpModeRobot implements the opmode-based robot program framework.

The OpModeRobot class is intended to be subclassed by a user creating a robot program.

Classes annotated with Autonomous, Teleop, and TestOpMode in the same package or subpackages as the user's subclass will be automatically registered as autonomous, teleop, and test opmodes respectively.

Opmodes are constructed when selected on the driver station, and closed/no longer used when the robot is disabled after being enabled or a different opmode is selected. When no opmode is selected, nonePeriodic() is called. The driverStationConnected() function is called the first time the driver station connects to the robot.

  • Constructor Details

  • Method Details

    • addOpModeFactory

      public void addOpModeFactory(Supplier<OpMode> factory, RobotMode mode, String name, String group, String description, Color textColor, Color backgroundColor)
      Adds an opmode using a factory function that creates the opmode. It's necessary to call publishOpModes() to make the added mode visible to the driver station.
      Parameters:
      factory - factory function to create the opmode
      mode - robot mode
      name - name of the operating mode
      group - group of the operating mode
      description - description of the operating mode
      textColor - text color, or null for default
      backgroundColor - background color, or null for default
      Throws:
      IllegalArgumentException - if class does not meet criteria
    • addOpModeFactory

      public void addOpModeFactory(Supplier<OpMode> factory, RobotMode mode, String name, String group, String description)
      Adds an opmode using a factory function that creates the opmode. It's necessary to call publishOpModes() to make the added mode visible to the driver station.
      Parameters:
      factory - factory function to create the opmode
      mode - robot mode
      name - name of the operating mode
      group - group of the operating mode
      description - description of the operating mode
      Throws:
      IllegalArgumentException - if class does not meet criteria
    • addOpModeFactory

      public void addOpModeFactory(Supplier<OpMode> factory, RobotMode mode, String name, String group)
      Adds an opmode using a factory function that creates the opmode. It's necessary to call publishOpModes() to make the added mode visible to the driver station.
      Parameters:
      factory - factory function to create the opmode
      mode - robot mode
      name - name of the operating mode
      group - group of the operating mode
      Throws:
      IllegalArgumentException - if class does not meet criteria
    • addOpModeFactory

      public void addOpModeFactory(Supplier<OpMode> factory, RobotMode mode, String name)
      Adds an opmode using a factory function that creates the opmode. It's necessary to call publishOpModes() to make the added mode visible to the driver station.
      Parameters:
      factory - factory function to create the opmode
      mode - robot mode
      name - name of the operating mode
      Throws:
      IllegalArgumentException - if class does not meet criteria
    • addOpMode

      public void addOpMode(Class<? extends OpMode> cls, RobotMode mode, String name, String group, String description, Color textColor, Color backgroundColor)
      Adds an opmode for an opmode class. The class must be a public, non-abstract subclass of OpMode with a public constructor that either takes no arguments or accepts a single argument of this class's type (the latter is preferred). It's necessary to call publishOpModes() to make the added mode visible to the driver station.
      Parameters:
      cls - class to add
      mode - robot mode
      name - name of the operating mode
      group - group of the operating mode
      description - description of the operating mode
      textColor - text color, or null for default
      backgroundColor - background color, or null for default
      Throws:
      IllegalArgumentException - if class does not meet criteria
    • addOpMode

      public void addOpMode(Class<? extends OpMode> cls, RobotMode mode, String name, String group, String description)
      Adds an opmode for an opmode class. The class must be a public, non-abstract subclass of OpMode with a public constructor that either takes no arguments or accepts a single argument of this class's type (the latter is preferred). It's necessary to call publishOpModes() to make the added mode visible to the driver station.
      Parameters:
      cls - class to add
      mode - robot mode
      name - name of the operating mode
      group - group of the operating mode
      description - description of the operating mode
      Throws:
      IllegalArgumentException - if class does not meet criteria
    • addOpMode

      public void addOpMode(Class<? extends OpMode> cls, RobotMode mode, String name, String group)
      Adds an opmode for an opmode class. The class must be a public, non-abstract subclass of OpMode with a public constructor that either takes no arguments or accepts a single argument of this class's type (the latter is preferred). It's necessary to call publishOpModes() to make the added mode visible to the driver station.
      Parameters:
      cls - class to add
      mode - robot mode
      name - name of the operating mode
      group - group of the operating mode
      Throws:
      IllegalArgumentException - if class does not meet criteria
    • addOpMode

      public void addOpMode(Class<? extends OpMode> cls, RobotMode mode, String name)
      Adds an opmode for an opmode class. The class must be a public, non-abstract subclass of OpMode with a public constructor that either takes no arguments or accepts a single argument of this class's type (the latter is preferred). It's necessary to call publishOpModes() to make the added mode visible to the driver station.
      Parameters:
      cls - class to add
      mode - robot mode
      name - name of the operating mode
      Throws:
      IllegalArgumentException - if class does not meet criteria
    • addAnnotatedOpMode

      public void addAnnotatedOpMode(Class<? extends OpMode> cls)
      Adds an opmode for an opmode class annotated with Autonomous, Teleop, or TestOpMode. The class must be a public, non-abstract subclass of OpMode with a public constructor that either takes no arguments or accepts a single argument of this class's type. It's necessary to call publishOpModes() to make the added mode visible to the driver station.
      Parameters:
      cls - class to add
      Throws:
      IllegalArgumentException - if class does not meet criteria
    • addAnnotatedOpModeClasses

      Scans for classes in the specified package and all nested packages that are annotated with Autonomous, Teleop, or TestOpMode and registers them. It's necessary to call publishOpModes() to make the added modes visible to the driver station.
      Parameters:
      pkg - package to scan
    • removeOpMode

      public void removeOpMode(RobotMode mode, String name)
      Removes an operating mode option. It's necessary to call publishOpModes() to make the removed mode no longer visible to the driver station.
      Parameters:
      mode - robot mode
      name - name of the operating mode
    • publishOpModes

      public void publishOpModes()
      Publishes the operating mode options to the driver station.
    • clearOpModes

      public void clearOpModes()
      Clears all operating mode options and publishes an empty list to the driver station.
    • driverStationConnected

      public void driverStationConnected()
      Function called exactly once after the DS is connected.

      Code that needs to know the DS state should go here.

      Users should override this method for initialization that needs to occur after the DS is connected, such as needing the alliance information.

    • nonePeriodic

      public void nonePeriodic()
      Function called periodically anytime when no opmode is selected, including when the Driver Station is disconnected.
    • startCompetition

      public final void startCompetition()
      Provide an alternate "main loop" via startCompetition().
      Specified by:
      startCompetition in class RobotBase
    • endCompetition

      public final void endCompetition()
      Ends the main loop in startCompetition().
      Specified by:
      endCompetition in class RobotBase