Class FtcOpMode

java.lang.Object
com.qualcomm.robotcore.eventloop.opmode.OpMode
com.qualcomm.robotcore.eventloop.opmode.LinearOpMode
ftclib.robotcore.FtcOpMode
All Implemented Interfaces:
TrcRobot.RobotMode

public abstract class FtcOpMode extends com.qualcomm.robotcore.eventloop.opmode.LinearOpMode implements TrcRobot.RobotMode
This class implements a cooperative multi-tasking scheduler extending LinearOpMode.
  • Field Details

    • moduleName

      private static final String moduleName
    • NUM_DASHBOARD_LINES

      protected static final int NUM_DASHBOARD_LINES
      See Also:
    • SLOW_LOOP_INTERVAL_NANO

      private static final long SLOW_LOOP_INTERVAL_NANO
      See Also:
    • globalTracer

      private static TrcDbgTrace globalTracer
    • instance

      private static FtcOpMode instance
    • startNotifier

      private final Object startNotifier
    • opModeName

      private static String opModeName
    • robotThread

      private Thread robotThread
    • robotThreadWatchdog

      private TrcWatchdogMgr.Watchdog robotThreadWatchdog
    • loopStartNanoTime

      private static long loopStartNanoTime
    • totalElapsedTime

      private final long[] totalElapsedTime
    • initLoopCount

      private long initLoopCount
    • loopCount

      private long loopCount
    • 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

    • FtcOpMode

      public FtcOpMode()
      Constructor: Creates an instance of the object. It calls the constructor of the LinearOpMode class and saves an instance of this class.
  • Method Details

    • getInstance

      public static FtcOpMode getInstance()
      This method returns the saved instance. This is a static method. So other class can get to this class instance by calling getInstance(). This is very useful for other classes that need to access the public fields and methods.
      Returns:
      save instance of this class.
    • getOpModeName

      public static String getOpModeName()
      This method returns the name of the active OpMode.
      Returns:
      active OpMode name.
    • getLoopStartTime

      public static double getLoopStartTime()
      This method returns the start time of the time slice loop. This is useful for the caller to determine if it is in the same time slice as a previous operation for optimization purposes.
      Returns:
      time slice loop start time.
    • getOpmodeAnnotation

      public Annotation getOpmodeAnnotation(Class opmodeType)
      This method returns the annotation object of the specifies opmode type if it is present.
      Parameters:
      opmodeType - specifies the opmode type.
      Returns:
      annotation object of the specified opmode type if present, null if not.
    • getOpmodeTypeName

      public String getOpmodeTypeName(Class<?> opmodeType)
      This method returns the opmode type name.
      Parameters:
      opmodeType - specifies Autonomous.class for autonomous opmode and TeleOp.class for TeleOp opmode.
      Returns:
      opmode type name.
    • getOpmodeTypeGroup

      public String getOpmodeTypeGroup(Class<?> opmodeType)
      This method returns the opmode type group.
      Parameters:
      opmodeType - specifies Autonomous.class for autonomous opmode and TeleOp.class for TeleOp opmode.
      Returns:
      opmode type group.
    • setBulkCachingModeEnabled

      private void setBulkCachingModeEnabled(boolean enabled)
      This method enables/disables Bulk Caching Mode. It is useful in situations such as resetting encoders and reading encoder values in a loop waiting for it to be cleared. With caching mode ON, the encoder value may never get cleared.
      Parameters:
      enabled - specifies true to enable caching mode, false to disable.
    • clearBulkCacheInManualMode

      public void clearBulkCacheInManualMode()
      This method clears the bulk cache if the module is in Manual mode.
    • ioTaskLoopBegin

      private void ioTaskLoopBegin(TrcRobot.RunMode runMode)
      This method is called by the IO task thread at the beginning of the IO loop so we can clear the bulk cache.
      Parameters:
      runMode - specifies the robot run mode (not used).
    • sendWatchdogHeartBeat

      public void sendWatchdogHeartBeat()
      This method sends a heart beat to the main robot thread watchdog. This is important if during robot init time that the user code decided to synchronously busy wait for something, it must periodically call this method to prevent the watchdog from complaining.
    • runOpMode

      public void runOpMode()
      This method is called when our OpMode is loaded and the "Init" button on the Driver Station is pressed.
      Specified by:
      runOpMode in class com.qualcomm.robotcore.eventloop.opmode.LinearOpMode
    • printPerformanceMetrics

      public void printPerformanceMetrics()
      This method prints the performance metrics of all loops and taska.
    • initPeriodic

      public void initPeriodic()
      This method is called periodically after robotInit() is called but before competition starts. Typically, you override this method and put code that will check and display robot status in this method. For example, one may monitor the gyro heading in this method to make sure there is no major gyro drift before competition starts. By default, this method is doing exactly what waitForStart() does.
    • robotInit

      public abstract void robotInit()
      This method is called to initialize the robot. In FTC, this is called when the "Init" button on the Driver Station phone is pressed.
    • startMode

      public void startMode(TrcRobot.RunMode prevMode, TrcRobot.RunMode nextMode)
      This method is called when the competition mode is about to start. In FTC, this is called when the "Play" button on the Driver Station phone is pressed. Typically, you put code that will prepare the robot for start of competition here such as resetting the encoders/sensors and enabling some sensors to start sampling.
      Specified by:
      startMode in interface TrcRobot.RobotMode
      Parameters:
      prevMode - specifies the previous RunMode it is coming from (always null for FTC).
      nextMode - specifies the next RunMode it is going into.
    • stopMode

      public void stopMode(TrcRobot.RunMode prevMode, TrcRobot.RunMode nextMode)
      This method is called when competition mode is about to end. Typically, you put code that will do clean up here such as disabling the sampling of some sensors.
      Specified by:
      stopMode in interface TrcRobot.RobotMode
      Parameters:
      prevMode - specifies the previous RunMode it is coming from.
      nextMode - specifies the next RunMode it is going into (always null for FTC).
    • periodic

      public void periodic(double elapsedTime, boolean slowPeriodicLoop)
      This method is called periodically at a fast rate. Typically, you put code that requires servicing at a high frequency here. To make the robot as responsive and as accurate as possible especially in autonomous mode, you will typically put that code here.
      Specified by:
      periodic in interface TrcRobot.RobotMode
      Parameters:
      elapsedTime - specifies the elapsed time since the mode started.
      slowPeriodicLoop - specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.
    • requestOpModeStop

      public final void requestOpModeStop()