Skip to content

OpModes

OpModes in CoreControl are designed to reduce boilerplate and integrate seamlessly with the library’s module and command systems. They handle the lifecycle of your robot’s components automatically, allowing you to focus on the logic.

CoreControl provides specialized OpMode classes that extend the standard SDK OpMode. These classes automatically manage:

  • Module Lifecycle: Initialization, updates, and cleanup for all registered modules.
  • Command Scheduling: Execution of commands with time-budgeting.
  • Telemetry: Automatic reporting of module states and command execution.
  • Hardware Access: Global access to hardwareMap and telemetry.

To use a CoreControl OpMode, simply extend one of the provided base classes (CoreTeleOp, CoreAuto, etc.) and override the lifecycle methods (onInit, onMainLoop, etc.) instead of the standard init and loop.

@TeleOp(name = "My TeleOp", group = "Main")
class MyTeleOp : CoreTeleOp(MyModule.INSTANCE) {
override fun onInit() {
// Initialization code
}
override fun onMainLoop() {
// Main loop logic
}
}

CoreTeleOp is the standard base class for TeleOp modes. It disables command logging telemetry by default to ensure performance during matches.

class MyTeleOp : CoreTeleOp(
// Register modules here
DriveTrain,
Intake
) {
override fun onMainLoop() {
// Gamepad logic here
}
}

CoreAuto is designed for Autonomous modes. Unlike TeleOp, it is structured around two main commands: an initCommand (runs during initialization) and a startCommand (runs when the match starts). You generally do not need to override loop methods in CoreAuto.

@Autonomous
class MyAuto : CoreAuto(
modules = arrayOf(DriveTrain, Intake),
initCommand = CloseClawCommand(),
startCommand = SequentialCommandGroup(
DriveToPosition(),
ScorePixel()
)
)

TestTeleOp is a variant of CoreTeleOp with all telemetry features enabled by default, including command logging. This is useful for debugging but should be avoided in competition due to potential performance overhead.

@TeleOp(group = "Test")
class DebugOpMode : TestTeleOp(DriveTrain) {
// Telemetry for commands and modules is enabled automatically
}

CoreOpMode is an alias for CoreTeleOp. It provides the same functionality and can be used interchangeably if you prefer the name.

CoreInternalOpMode is the base class for all CoreControl OpModes. It extends the SDK’s OpMode and implements the custom lifecycle hooks (onInit, onStart, onMainLoop, onStop). It also handles the global hardwareMap and telemetry injection.

Lifecycle Methods:

  • onInit(): Called once when INIT is pressed.
  • onInitLoop(): Called repeatedly during the initialization phase.
  • onStart(): Called once when PLAY is pressed.
  • onMainLoop(): Called repeatedly during the active phase.
  • onStop(): Called once when STOP is pressed.