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

    Fields
    Modifier and Type
    Field
    Description
    protected final BindingManager
    Shared binding manager for this OpMode.
    com.qualcomm.robotcore.hardware.Gamepad
     
    com.qualcomm.robotcore.hardware.Gamepad
     
    com.qualcomm.robotcore.hardware.HardwareMap
     
    static final int
     
    int
    Deprecated.
    org.firstinspires.ftc.robotcore.external.Telemetry
     

    Fields inherited from class com.qualcomm.robotcore.eventloop.opmode.OpMode

    blackboard, msStuckDetectInit, msStuckDetectInitLoop, msStuckDetectLoop, msStuckDetectStart, time
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Runs preload(), applies the bulk-caching mode to every Lynx hub, then calls Subsystem.init() on each registered subsystem and Module.init() on each installed module, in registration order.
    void
    Called repeatedly while the driver is on the init screen.
    protected void
    Install a module to be driven by this OpMode.
    void
    The main run loop.
    protected abstract void
    Hook run once at the very start of init(), before any subsystem or module is initialized.
    protected void
    Register a subsystem to be driven by this OpMode.
    final void
     
    protected void
    setBulkCachingMode(com.qualcomm.hardware.lynx.LynxModule.BulkCachingMode mode)
    Sets the Lynx (Control/Expansion Hub) bulk-caching mode.
    void
    Called once when play is pressed.
    void
    Called once when the OpMode ends.

    Methods inherited from class com.qualcomm.robotcore.eventloop.opmode.OpMode

    getRuntime, internalPostInitLoop, internalPostLoop, internalPreInit, internalUpdateTelemetryNow, resetRuntime, terminateOpModeNow, updateTelemetry

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • bindingManager

      protected final BindingManager bindingManager
      Shared binding manager for this OpMode. Modules such as BindingModule and TeleOpPedroModule register 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 public int 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 of loop(), so each device's update() afterward is served from that snapshot instead of hitting the bus. Call from preload() to change it.
    • registerSubsystem

      protected void registerSubsystem(Subsystem subsystem)
      Register a subsystem to be driven by this OpMode. Call from preload().
    • installModule

      protected void installModule(Module module)
      Install a module to be driven by this OpMode. Call from preload().
    • preload

      protected abstract void preload()
      Hook run once at the very start of init(), before any subsystem or module is initialized. Subclasses implement it to build the robot: register subsystems with registerSubsystem(com.cdarobotics.cdalib.subsystems.Subsystem), install modules with installModule(com.cdarobotics.cdalib.opmodes.modules.Module), and optionally change the bulk-caching mode via setBulkCachingMode(com.qualcomm.hardware.lynx.LynxModule.BulkCachingMode).
    • init

      public void init()
      Runs preload(), applies the bulk-caching mode to every Lynx hub, then calls Subsystem.init() on each registered subsystem and Module.init() on each installed module, in registration order.
      Specified by:
      init in class com.qualcomm.robotcore.eventloop.opmode.OpMode
    • init_loop

      public void init_loop()
      Called repeatedly while the driver is on the init screen. Forwards to Subsystem.init_loop() on each subsystem and Module.init_loop() on each module.
      Overrides:
      init_loop in class com.qualcomm.robotcore.eventloop.opmode.OpMode
    • start

      public void start()
      Called once when play is pressed. Calls Subsystem.start() on each subsystem and Module.start() on each module, then polls the task master once.
      Overrides:
      start in class com.qualcomm.robotcore.eventloop.opmode.OpMode
    • loop

      public void loop()
      The main run loop. In MANUAL bulk-caching mode, clears every hub's bulk cache once so the loop's first hardware read pulls all sensors in a single transaction. Then calls Subsystem.update() on each subsystem and Module.loop() on each module, and polls the task master.
      Specified by:
      loop in class com.qualcomm.robotcore.eventloop.opmode.OpMode
    • stop

      public void stop()
      Called once when the OpMode ends. Calls Subsystem.stop() on each subsystem and Module.stop() on each module so they can safe or release hardware.
      Overrides:
      stop in class com.qualcomm.robotcore.eventloop.opmode.OpMode
    • requestOpModeStop

      public final void requestOpModeStop()