com.qualcomm.robotcore.eventloop.opmode

## Class OpMode

- java.lang.Object
- - com.qualcomm.robotcore.eventloop.opmode.OpMode

- Direct Known Subclasses:
    LinearOpMode

      public abstract class OpMode
      extends java.lang.Object

  Base class for user defined operation modes (op modes).

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `Gamepad` | `gamepad1` Gamepad 1
    `Gamepad` | `gamepad2` Gamepad 2
    `HardwareMap` | `hardwareMap` Hardware Mappings
    `OpModeServices` | `internalOpModeServices` this is logically an internal field.
    `int` | `msStuckDetectInit`
    `int` | `msStuckDetectInitLoop`
    `int` | `msStuckDetectLoop`
    `int` | `msStuckDetectStart`
    `int` | `msStuckDetectStop`
    `Telemetry` | `telemetry` The `telemetry` field contains an object in which a user may accumulate data which is to be transmitted to the driver station.
    `double` | `time` number of seconds this op mode has been running, this is updated before every call to loop.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `OpMode()` OpMode constructor

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `double` | `getRuntime()` Get the number of seconds this op mode has been running
    `void` | `init_loop()` User defined init_loop method
    `abstract void` | `init()` User defined init method
    `void` | `internalPostInitLoop()` automatically update telemetry in a non-linear opmode
    `void` | `internalPostLoop()` automatically update telemetry in a non-linear opmode
    `void` | `internalPreInit()`
    `void` | `internalUpdateTelemetryNow(TelemetryMessage telemetry)` This is an internal SDK method, not intended for use by user opmodes.
    `abstract void` | `loop()` User defined loop method
    `void` | `requestOpModeStop()` Requests that this OpMode be shut down if it the currently active opMode, much as if the stop button had been pressed on the driver station; if this is not the currently active OpMode, then this function has no effect.
    `void` | `resetStartTime()` Reset the start time to zero.
    `void` | `start()` User defined start method.
    `void` | `stop()` User defined stop method
    `void` | `updateTelemetry(Telemetry telemetry)` Refreshes the user's telemetry on the driver station with the contents of the provided telemetry object if a nominal amount of time has passed since the last telemetry transmission.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### gamepad1

          public Gamepad gamepad1

      Gamepad 1

    - #### gamepad2

          public Gamepad gamepad2

      Gamepad 2

    - #### telemetry

          public Telemetry telemetry

      The `telemetry` field contains an object in which a user may accumulate data which is to be transmitted to the driver station. This data is automatically transmitted to the driver station on a regular, periodic basis.

    - #### hardwareMap

          public HardwareMap hardwareMap

      Hardware Mappings

    - #### time

          public double time

      number of seconds this op mode has been running, this is updated before every call to loop.

    - #### msStuckDetectInit

          public int msStuckDetectInit

    - #### msStuckDetectInitLoop

          public int msStuckDetectInitLoop

    - #### msStuckDetectStart

          public int msStuckDetectStart

    - #### msStuckDetectLoop

          public int msStuckDetectLoop

    - #### msStuckDetectStop

          public int msStuckDetectStop

    - #### internalOpModeServices

          public OpModeServices internalOpModeServices

      this is logically an internal field. DO NOT USE

  - ### Constructor Detail

    - #### OpMode

          public OpMode()

      OpMode constructor

      The op mode name should be unique. It will be the name displayed on the driver station. If multiple op modes have the same name, only one will be available.

  - ### Method Detail

    - #### init

          public abstract void init()

      User defined init method

      This method will be called once when the INIT button is pressed.

    - #### init_loop

          public void init_loop()

      User defined init_loop method

      This method will be called repeatedly when the INIT button is pressed. This method is optional. By default this method takes no action.

    - #### start

          public void start()

      User defined start method.

      This method will be called once when the PLAY button is first pressed. This method is optional. By default this method takes not action. Example usage: Starting another thread.

    - #### loop

          public abstract void loop()

      User defined loop method

      This method will be called repeatedly in a loop while this op mode is running

    - #### stop

          public void stop()

      User defined stop method

      This method will be called when this op mode is first disabled The stop method is optional. By default this method takes no action.

    - #### requestOpModeStop

          public final void requestOpModeStop()

      Requests that this OpMode be shut down if it the currently active opMode, much as if the stop button had been pressed on the driver station; if this is not the currently active OpMode, then this function has no effect. Note as part of this processing, the OpMode's `stop()` method will be called, as that is part of the usual shutdown logic. Note that `requestOpModeStop()` may be called from any thread.
      See Also:
        `stop()`

    - #### getRuntime

          public double getRuntime()

      Get the number of seconds this op mode has been running

      This method has sub millisecond accuracy.

      Returns:
        number of seconds this op mode has been running

    - #### resetStartTime

          public void resetStartTime()

      Reset the start time to zero.

    - #### updateTelemetry

          public void updateTelemetry(Telemetry telemetry)

      Refreshes the user's telemetry on the driver station with the contents of the provided telemetry object if a nominal amount of time has passed since the last telemetry transmission. Once transmitted, the contents of the telemetry object are (by default) cleared.
      Parameters:
        `telemetry` - the telemetry data to transmit
      See Also:
        `telemetry`, `Telemetry.update()`

    - #### internalPreInit

          public void internalPreInit()

    - #### internalPostInitLoop

          public void internalPostInitLoop()

      automatically update telemetry in a non-linear opmode

    - #### internalPostLoop

          public void internalPostLoop()

      automatically update telemetry in a non-linear opmode

    - #### internalUpdateTelemetryNow

          public final void internalUpdateTelemetryNow(TelemetryMessage telemetry)

      This is an internal SDK method, not intended for use by user opmodes.
      Parameters:
        `telemetry` - the telemetry data to transmit
      See Also:
        `telemetry`, `Telemetry.update()`