Class OpModeRobot
- All Implemented Interfaces:
AutoCloseable
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAnnotatedOpMode(Class<? extends OpMode> cls) voidScans for classes in the specified package and all nested packages that are annotated withAutonomous,Teleop, orTestOpModeand registers them.voidAdds an opmode for an opmode class.voidAdds an opmode for an opmode class.voidaddOpMode(Class<? extends OpMode> cls, RobotMode mode, String name, String group, String description) Adds an opmode for an opmode class.voidaddOpMode(Class<? extends OpMode> cls, RobotMode mode, String name, String group, String description, Color textColor, Color backgroundColor) Adds an opmode for an opmode class.voidaddOpModeFactory(Supplier<OpMode> factory, RobotMode mode, String name) Adds an opmode using a factory function that creates the opmode.voidAdds an opmode using a factory function that creates the opmode.voidaddOpModeFactory(Supplier<OpMode> factory, RobotMode mode, String name, String group, String description) Adds an opmode using a factory function that creates the opmode.voidaddOpModeFactory(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.voidClears all operating mode options and publishes an empty list to the driver station.voidFunction called exactly once after the DS is connected.final voidEnds the main loop in startCompetition().voidFunction called periodically anytime when no opmode is selected, including when the Driver Station is disconnected.voidPublishes the operating mode options to the driver station.voidremoveOpMode(RobotMode mode, String name) Removes an operating mode option.final voidProvide an alternate "main loop" via startCompetition().Methods inherited from class RobotBase
close, getMainThreadId, getOpMode, getOpModeId, getRuntimeType, isAutonomous, isAutonomousEnabled, isDisabled, isEnabled, isReal, isSimulation, isTeleop, isTeleopEnabled, isTest, isTestEnabled, startRobot, suppressExitWarning
-
Constructor Details
-
OpModeRobot
public OpModeRobot()Constructor.
-
-
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 opmodemode- robot modename- name of the operating modegroup- group of the operating modedescription- description of the operating modetextColor- text color, or null for defaultbackgroundColor- 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 opmodemode- robot modename- name of the operating modegroup- group of the operating modedescription- description of the operating mode- Throws:
IllegalArgumentException- if class does not meet criteria
-
addOpModeFactory
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 opmodemode- robot modename- name of the operating modegroup- group of the operating mode- Throws:
IllegalArgumentException- if class does not meet criteria
-
addOpModeFactory
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 opmodemode- robot modename- 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 addmode- robot modename- name of the operating modegroup- group of the operating modedescription- description of the operating modetextColor- text color, or null for defaultbackgroundColor- 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 addmode- robot modename- name of the operating modegroup- group of the operating modedescription- description of the operating mode- Throws:
IllegalArgumentException- if class does not meet criteria
-
addOpMode
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 addmode- robot modename- name of the operating modegroup- group of the operating mode- Throws:
IllegalArgumentException- if class does not meet criteria
-
addOpMode
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 addmode- robot modename- name of the operating mode- Throws:
IllegalArgumentException- if class does not meet criteria
-
addAnnotatedOpMode
Adds an opmode for an opmode class annotated withAutonomous,Teleop, orTestOpMode. 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 withAutonomous,Teleop, orTestOpModeand registers them. It's necessary to call publishOpModes() to make the added modes visible to the driver station.- Parameters:
pkg- package to scan
-
removeOpMode
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 modename- name of the operating mode
-
publishOpModes
Publishes the operating mode options to the driver station. -
clearOpModes
Clears all operating mode options and publishes an empty list to the driver station. -
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
Function called periodically anytime when no opmode is selected, including when the Driver Station is disconnected. -
startCompetition
Provide an alternate "main loop" via startCompetition().- Specified by:
startCompetitionin classRobotBase
-
endCompetition
Ends the main loop in startCompetition().- Specified by:
endCompetitionin classRobotBase
-