Package ftclib.robotcore
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 Summary
FieldsModifier and TypeFieldDescriptioncom.qualcomm.robotcore.hardware.Gamepad
com.qualcomm.robotcore.hardware.Gamepad
private static TrcDbgTrace
com.qualcomm.robotcore.hardware.HardwareMap
private long
private static FtcOpMode
private long
private static long
private static final String
static final int
int
Deprecated.protected static final int
private static String
private Thread
private TrcWatchdogMgr.Watchdog
private static final long
private final Object
org.firstinspires.ftc.robotcore.external.Telemetry
private final long[]
Fields inherited from class com.qualcomm.robotcore.eventloop.opmode.OpMode
msStuckDetectInit, msStuckDetectInitLoop, msStuckDetectLoop, msStuckDetectStart, time
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
This method clears the bulk cache if the module is in Manual mode.static FtcOpMode
This method returns the saved instance.static double
This method returns the start time of the time slice loop.getOpmodeAnnotation
(Class opmodeType) This method returns the annotation object of the specifies opmode type if it is present.static String
This method returns the name of the active OpMode.getOpmodeTypeGroup
(Class<?> opmodeType) This method returns the opmode type group.getOpmodeTypeName
(Class<?> opmodeType) This method returns the opmode type name.void
This method is called periodically after robotInit() is called but before competition starts.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.void
periodic
(double elapsedTime, boolean slowPeriodicLoop) This method is called periodically at a fast rate.void
This method prints the performance metrics of all loops and taska.final void
abstract void
This method is called to initialize the robot.void
This method is called when our OpMode is loaded and the "Init" button on the Driver Station is pressed.void
This method sends a heart beat to the main robot thread watchdog.private void
setBulkCachingModeEnabled
(boolean enabled) This method enables/disables Bulk Caching Mode.void
startMode
(TrcRobot.RunMode prevMode, TrcRobot.RunMode nextMode) This method is called when the competition mode is about to start.void
stopMode
(TrcRobot.RunMode prevMode, TrcRobot.RunMode nextMode) This method is called when competition mode is about to end.Methods inherited from class com.qualcomm.robotcore.eventloop.opmode.LinearOpMode
idle, init, init_loop, isStarted, isStopRequested, loop, opModeInInit, opModeIsActive, sleep, start, stop, waitForStart
Methods inherited from class com.qualcomm.robotcore.eventloop.opmode.OpMode
getRuntime, internalPostInitLoop, internalPostLoop, internalPreInit, internalUpdateTelemetryNow, resetRuntime, terminateOpModeNow, updateTelemetry
-
Field Details
-
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
-
instance
-
startNotifier
-
opModeName
-
robotThread
-
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.
-
-
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
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
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
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
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
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
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 classcom.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
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 interfaceTrcRobot.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
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 interfaceTrcRobot.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 interfaceTrcRobot.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()
-