Interface OpMode
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
PeriodicOpMode
Top-level interface for opmode classes. Users should generally extend one of the abstract
implementations of this interface (e.g.
PeriodicOpMode) rather than directly implementing
this interface.
Lifecycle:
- constructed when opmode selected on driver station
- disabledPeriodic() called periodically as long as DS is disabled. Note this is not called on a set time interval (it does not use the same time interval as periodic())
- when DS transitions from disabled to enabled, start() is called once
- while DS is enabled, periodic() is called periodically at
OpModeRobot.getPeriod(), and additional periodic callbacks added via addPeriodic() are called periodically on their set time intervals - when DS transitions from enabled to disabled, or a different opmode is selected on the driver station when the DS is enabled, end() is called, followed by close(); the object is not reused
- if a different opmode is selected on the driver station when the DS is disabled, only close() is called; the object is not reused
All lifecycle callbacks and periodic callbacks run synchronously on the same thread that invokes them. Interactions between opmodes and the robot framework do not require additional synchronization.
Additional callbacks can be registered by implementing getCallbacks() to return a set
of PeriodicPriorityQueue.Callback objects with custom timing. PeriodicOpMode
provides a convenient implementation of this method and utility methods for adding periodic
callbacks.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidclose()This function is called when the opmode is no longer selected on the DS or after an enabled run ends.default voidThis function is called periodically while the opmode is selected and the robot is disabled.default voidend()This function is called asynchronously when the robot disables or switches opmodes while this opmode is enabled.default Set<PeriodicPriorityQueue.Callback> Returns a set of custom periodic callbacks to be executed while the opmode is enabled.default voidperiodic()This function is called periodically while the opmode is enabled at the rate returned byOpModeRobot.getPeriod().default voidstart()Called once when this opmode transitions to enabled.
-
Method Details
-
disabledPeriodic
This function is called periodically while the opmode is selected and the robot is disabled. Code that should only run once when the opmode is selected should go in the opmode constructor. -
start
Called once when this opmode transitions to enabled. -
periodic
This function is called periodically while the opmode is enabled at the rate returned byOpModeRobot.getPeriod(). -
end
This function is called asynchronously when the robot disables or switches opmodes while this opmode is enabled. Implementations should stop blocking work promptly. -
close
This function is called when the opmode is no longer selected on the DS or after an enabled run ends. The object will not be reused after this is called.- Specified by:
closein interfaceAutoCloseable
-
getCallbacks
Returns a set of custom periodic callbacks to be executed while the opmode is enabled.This method allows opmodes to register arbitrary periodic callbacks with custom execution intervals. The callbacks are executed by the robot framework at their scheduled times, in addition to the primary
periodic()callback.- Returns:
- A set of custom callbacks to execute, or an empty set if no custom callbacks are needed. The default implementation returns an empty set.
-