Package com.cdarobotics.cdalib.opmodes
Class ModularOpMode
java.lang.Object
com.qualcomm.robotcore.eventloop.opmode.OpMode
com.cdarobotics.cdalib.opmodes.ModularOpMode
public abstract class ModularOpMode
extends com.qualcomm.robotcore.eventloop.opmode.OpMode
Base class for OpModes assembled from reusable parts. Subsystems and modules are registered in
preload() and then driven automatically through their lifecycles: init on OpMode init,
start when play is pressed, and update/loop every cycle. Also manages Lynx hub bulk caching, so
each loop performs a single bulk read of all sensors — see setBulkCachingMode(com.qualcomm.hardware.lynx.LynxModule.BulkCachingMode).
PhotonFTC is available for teams that want even lower loop times: annotate your concrete
OpMode subclass with @Photon to have
PhotonCore swap in its optimized motor/servo controllers. Photon pairs with the default
MANUAL bulk-caching mode used here (one cache clear per loop()); leave the mode
on MANUAL when Photon is enabled.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final BindingManagerShared binding manager for this OpMode.com.qualcomm.robotcore.hardware.Gamepadcom.qualcomm.robotcore.hardware.Gamepadcom.qualcomm.robotcore.hardware.HardwareMapstatic final intintDeprecated.org.firstinspires.ftc.robotcore.external.TelemetryFields inherited from class com.qualcomm.robotcore.eventloop.opmode.OpMode
blackboard, msStuckDetectInit, msStuckDetectInitLoop, msStuckDetectLoop, msStuckDetectStart, time -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidinit()Runspreload(), applies the bulk-caching mode to every Lynx hub, then callsSubsystem.init()on each registered subsystem andModule.init()on each installed module, in registration order.voidCalled repeatedly while the driver is on the init screen.protected voidinstallModule(Module module) Install a module to be driven by this OpMode.voidloop()The main run loop.protected abstract voidpreload()Hook run once at the very start ofinit(), before any subsystem or module is initialized.protected voidregisterSubsystem(Subsystem subsystem) Register a subsystem to be driven by this OpMode.final voidprotected voidsetBulkCachingMode(com.qualcomm.hardware.lynx.LynxModule.BulkCachingMode mode) Sets the Lynx (Control/Expansion Hub) bulk-caching mode.voidstart()Called once when play is pressed.voidstop()Called once when the OpMode ends.Methods inherited from class com.qualcomm.robotcore.eventloop.opmode.OpMode
getRuntime, internalPostInitLoop, internalPostLoop, internalPreInit, internalUpdateTelemetryNow, resetRuntime, terminateOpModeNow, updateTelemetry
-
Field Details
-
bindingManager
Shared binding manager for this OpMode. Modules such asBindingModuleandTeleOpPedroModuleregister and query gamepad bindings against it. Exposed to subclasses so they can wire their own bindings. -
MS_BEFORE_FORCE_STOP_AFTER_STOP_REQUESTED
public static final int MS_BEFORE_FORCE_STOP_AFTER_STOP_REQUESTED- See Also:
-
gamepad1
public volatile com.qualcomm.robotcore.hardware.Gamepad gamepad1 -
gamepad2
public volatile com.qualcomm.robotcore.hardware.Gamepad gamepad2 -
telemetry
public org.firstinspires.ftc.robotcore.external.Telemetry telemetry -
hardwareMap
public volatile com.qualcomm.robotcore.hardware.HardwareMap hardwareMap -
msStuckDetectStop
Deprecated.
-
-
Constructor Details
-
ModularOpMode
public ModularOpMode()
-
-
Method Details
-
setBulkCachingMode
protected void setBulkCachingMode(com.qualcomm.hardware.lynx.LynxModule.BulkCachingMode mode) Sets the Lynx (Control/Expansion Hub) bulk-caching mode. The default,MANUAL, reads every sensor and encoder off the hub in a single bulk transaction per loop — the cache is cleared once at the top ofloop(), so each device'supdate()afterward is served from that snapshot instead of hitting the bus. Call frompreload()to change it. -
registerSubsystem
Register a subsystem to be driven by this OpMode. Call frompreload(). -
installModule
Install a module to be driven by this OpMode. Call frompreload(). -
preload
protected abstract void preload()Hook run once at the very start ofinit(), before any subsystem or module is initialized. Subclasses implement it to build the robot: register subsystems withregisterSubsystem(com.cdarobotics.cdalib.subsystems.Subsystem), install modules withinstallModule(com.cdarobotics.cdalib.opmodes.modules.Module), and optionally change the bulk-caching mode viasetBulkCachingMode(com.qualcomm.hardware.lynx.LynxModule.BulkCachingMode). -
init
public void init()Runspreload(), applies the bulk-caching mode to every Lynx hub, then callsSubsystem.init()on each registered subsystem andModule.init()on each installed module, in registration order.- Specified by:
initin classcom.qualcomm.robotcore.eventloop.opmode.OpMode
-
init_loop
public void init_loop()Called repeatedly while the driver is on the init screen. Forwards toSubsystem.init_loop()on each subsystem andModule.init_loop()on each module.- Overrides:
init_loopin classcom.qualcomm.robotcore.eventloop.opmode.OpMode
-
start
public void start()Called once when play is pressed. CallsSubsystem.start()on each subsystem andModule.start()on each module, then polls the task master once.- Overrides:
startin classcom.qualcomm.robotcore.eventloop.opmode.OpMode
-
loop
public void loop()The main run loop. InMANUALbulk-caching mode, clears every hub's bulk cache once so the loop's first hardware read pulls all sensors in a single transaction. Then callsSubsystem.update()on each subsystem andModule.loop()on each module, and polls the task master.- Specified by:
loopin classcom.qualcomm.robotcore.eventloop.opmode.OpMode
-
stop
public void stop()Called once when the OpMode ends. CallsSubsystem.stop()on each subsystem andModule.stop()on each module so they can safe or release hardware.- Overrides:
stopin classcom.qualcomm.robotcore.eventloop.opmode.OpMode
-
requestOpModeStop
public final void requestOpModeStop()
-