Package com.crossbotics.ftchelper.teleop
Class EasyTeleOp
java.lang.Object
com.qualcomm.robotcore.eventloop.opmode.OpMode
com.qualcomm.robotcore.eventloop.opmode.LinearOpMode
com.crossbotics.ftchelper.teleop.EasyTeleOp
- Direct Known Subclasses:
ControlMap
public abstract class EasyTeleOp
extends com.qualcomm.robotcore.eventloop.opmode.LinearOpMode
A whole TeleOp where you only write what is special about YOUR robot: its mechanisms, the
operator's buttons, and any extra screen lines. Everything every TeleOp needs is done for you:
- Driving on gamepad 1 (
DriverControls): left stick drive, right stick X turn, left trigger slow. Mecanum and tank. Robot-centric to start; Y double-tap = field-centric on/off (mecanum). - Field-centric "forward" continues from autonomous (
DriverHeading); BACK resets it. - The alliance from autonomous (
alliance(); chosen in INIT if no autonomous ran; a switch during TeleOp only if you turn it on), the 2:00 match timer with gamepad buzzes at 1:00 and 0:20, the tuning menu on GUIDE (PRACTICE profile only), debug telemetry on BACK + START, warnings for slow code, a tuned value or the PRACTICE profile. - Every one of these buttons can move or be freed:
libraryButtons(LibraryButtons). - Every mechanism updated every loop, and EVERYTHING stopped at the end, even after an error.
@TeleOp(name = "Main TeleOp")
public class MainTeleOp extends EasyTeleOp {
private Robot robot;
@Override protected RobotConfig robotConfig() { return new RobotSettings(); }
@Override protected Subsystems createSubsystems() { robot = new Robot(hardwareMap); return robot.all; }
@Override protected void bindButtons(ControllerBindings driver, ControllerBindings operator) {
operator.bindPress(Pad.G2, Btn.RB, robot.claw::toggle);
}
}
Order in each loop: buttons, driving, everyLoop(), mechanisms' update(), telemetry.
Nothing here waits. Your code must not wait either (docs/guides/non-blocking.md).
Docs: docs/modules/teleop.md. Tutorial: docs/tutorials/20-easy-teleop.md.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleHow long BACK is held to reset "forward" when a tap of BACK has another job, seconds.com.qualcomm.robotcore.hardware.Gamepadcom.qualcomm.robotcore.hardware.Gamepadstatic final doubleHow long GUIDE is held to open the tuning menu when there is a button map, seconds.com.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 TypeMethodDescriptionprotected voidExtra lines for the Driver Station during INIT (before START), every INIT loop.protected voidExtra lines for the Driver Station, every loop.protected Alliancealliance()The alliance autonomous chose (BLUE if no autonomous ran in the last few minutes).protected voidallianceChanged(Alliance now) Called when the alliance changes during TeleOp (switchAlliance()), afteralliance()has the new one: update what uses it.protected voidatEnd()Your own code at the very end (STOP, the end, or an error), after the wheels and every part are stopped: e.g.protected RunnablebackTap()What a tap of the pause button (BACK) does, or null (default): then BACK resets "forward".protected voidbindButtons(ControllerBindings driver, ControllerBindings operator) Your buttons.The button map's lines for the help page, or null (default) for none.protected double[]Seconds left when both gamepads buzz.protected voidconfigureDriving(DriverControls driving) Changes how driving feels, once, in INIT, right after the drive is made.protected DriverHeadingcreateHeading(com.qualcomm.robotcore.hardware.IMU imu) The driver's heading for field-centric driving: from the IMU (with autonomous's saved heading).protected com.qualcomm.robotcore.hardware.IMUThe IMU, for field-centric driving and "forward" from autonomous.protected SubsystemsYour mechanisms: kept updated every loop and stopped at the end.protected voiddrive(com.qualcomm.robotcore.hardware.Gamepad gamepad) Drives the robot from gamepad 1, every loop (not while the tuning menu is open).protected DriveConfigThe drivetrain settings.protected final doubleThe driving speed the library's slow buttons ask for now, 0 to 1 (1 = full speed): the slow trigger (the further, the slower), a slow button held, or slow on/off.protected DriverControlsdriving()The driving (field-centric on/off, slow mode).protected voidYour own code for every loop, e.g.protected ControllerBindings.BtnThe gamepad 1 button that switches field-centric driving on and off (mecanum with an IMU only).protected DriverHeadingheading()The heading compared with the driver, or null if there is no IMU.protected booleaninitMenu()The INIT menu on gamepad 1's D-pad (alliance, profile)? Default on.protected booleanTrue while the tuning menu is open.protected final String"G1 BACK" for a job's button ("BACK" alone on gamepad 1), or "(no button)".protected voidMoves or frees the library's own buttons (pause, slow, field-centric, menus...).protected final Set<LibraryButtons.Job> libraryJobs(boolean withButtonMap) The library's jobs this TeleOp has: "pause" only withbackTap(), "field-centric" only where possible, "set pose" only withsetPoseJob()...protected final LibraryButtonsWhere the library's buttons are (afterlibraryButtons(LibraryButtons)); null before INIT.protected MatchTimerThe 2:00 match timer (started at START).protected voidonStart()Runs once, right after START, before the first loop.protected BooleanSupplierHow to read "the robot is paused now", or null (default).final voidprotected RobotConfigYour robot's settings, shared with autonomous (seeRobotConfig).protected RobotTelemetryThe Driver Station screen helper (warnings, standard and debug lines).final voidThe whole TeleOp.The "set pose here" job, or null (default: none).protected StringWith nosetPoseJob(): a short note shown when the drivers hold the "set pose here" button anyway (alone, 1 s, then let go), so it does not silently do nothing; null (default) = no note.protected final voidShowstextas a warning at the top of the Driver Station for 3 seconds (e.g.protected doubleSpeed at a full squeeze of the slow trigger, 0 to 1.protected LibraryButtonsThe defaults beforelibraryButtons(LibraryButtons):LibraryButtons.twoDrivers(), with field-centric onfieldCentricButton().protected booleanTrue to start in field-centric mode.protected final voidSwitches the alliance now (BLUE to RED, or RED to BLUE), in case the wrong one was chosen: everything that readsalliance()orMatchMemorygets the new one, both gamepads buzz twice and the Driver Station says so.Methods inherited from class com.qualcomm.robotcore.eventloop.opmode.LinearOpMode
idle, init, init_loop, isStarted, isStopRequested, loop, opModeInInit, opModeIsActive, sleep, start, stop, waitForStartMethods inherited from class com.qualcomm.robotcore.eventloop.opmode.OpMode
getRuntime, internalPostInitLoop, internalPostLoop, internalPreInit, internalUpdateTelemetryNow, resetRuntime, terminateOpModeNow, updateTelemetry
-
Field Details
-
BACK_HOLD_SEC
public static final double BACK_HOLD_SECHow long BACK is held to reset "forward" when a tap of BACK has another job, seconds.- See Also:
-
GUIDE_HOLD_SEC
public static final double GUIDE_HOLD_SECHow long GUIDE is held to open the tuning menu when there is a button map, seconds.- See Also:
-
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
-
EasyTeleOp
public EasyTeleOp()
-
-
Method Details
-
robotConfig
Your robot's settings, shared with autonomous (seeRobotConfig). Returnnew RobotSettings(). If you do not have one, overridedriveConfig()andcreateImu()instead. -
driveConfig
The drivetrain settings. Default:robotConfig().drive(). -
createHeading
The driver's heading for field-centric driving: from the IMU (with autonomous's saved heading). The robot in five files uses its odometry instead when it has one.- Parameters:
imu- the IMU fromcreateImu(), or null
-
createImu
protected com.qualcomm.robotcore.hardware.IMU createImu()The IMU, for field-centric driving and "forward" from autonomous. Default:robotConfig().imu(...). Null = no IMU: robot-centric driving only. -
createSubsystems
Your mechanisms: kept updated every loop and stopped at the end. Default: none. -
bindButtons
Your buttons. Put gamepad 2 buttons onoperator. Extra gamepad 1 buttons go ondriver: those pause while the tuning menu is open (it uses gamepad 1). Already taken on gamepad 1 (unless moved withlibraryButtons(LibraryButtons)): LT, Y (field-centric), BACK, START (with BACK: debug lines), GUIDE. -
everyLoop
protected void everyLoop()Your own code for every loop, e.g. a stick that moves the lift by hand. Runs after the buttons and driving, before the mechanisms update. Must be quick: never wait here. -
atEnd
protected void atEnd()Your own code at the very end (STOP, the end, or an error), after the wheels and every part are stopped: e.g. save a number for the next OpMode. Runs even if stopping failed. -
addTelemetry
Extra lines for the Driver Station, every loop. The mechanisms' lines are already shown. -
buttonHelp
The button map's lines for the help page, or null (default) for none. With a map, a tap of GUIDE shows it during the match and holding GUIDE 1 s opens the tuning menu; without one, GUIDE opens the tuning menu. -
showNote
Showstextas a warning at the top of the Driver Station for 3 seconds (e.g. to confirm a button's job). A new note replaces the old one. Never waits. -
backTap
What a tap of the pause button (BACK) does, or null (default): then BACK resets "forward". With a job here (a Controls.java TeleOp: pause everything), holding BACKBACK_HOLD_SECresets "forward". The buttons can be moved:libraryButtons(LibraryButtons). -
pauseState
How to read "the robot is paused now", or null (default). With one, a press of the pause button pauses AT ONCE (even though BACK also has "hold: reset forward"), and going on is a tap. Without one,backTap()runs when BACK is let go. Controls.java gives one. -
setPoseJob
The "set pose here" job, or null (default: none). It sets the pose and returns the words for the Driver Station ("Pose set: ..."). Controls.java gives one on a robot with odometry. Its button works in INIT too (held 1 s before START), so the pose can be set before the match. -
setPoseMissingNote
With nosetPoseJob(): a short note shown when the drivers hold the "set pose here" button anyway (alone, 1 s, then let go), so it does not silently do nothing; null (default) = no note. Controls.java says the robot needs odometry for it. -
allianceChanged
Called when the alliance changes during TeleOp (switchAlliance()), afteralliance()has the new one: update what uses it. Default: nothing. Must not wait. -
libraryButtons
Moves or frees the library's own buttons (pause, slow, field-centric, menus...). Default: nothing changes. Example:lib.fieldCentric(Key.g1(Btn.X)).slow(Key.g1(Trigger.RT));. Two jobs on one button stop at INIT with the button's name. The table: docs/controls/04-move-library-buttons.md.- Parameters:
lib- the buttons, already at their defaults (LibraryButtons.twoDrivers())
-
standardLibraryButtons
The defaults beforelibraryButtons(LibraryButtons):LibraryButtons.twoDrivers(), with field-centric onfieldCentricButton(). Controls.java gives the one-driver ones. -
libraryKeys
Where the library's buttons are (afterlibraryButtons(LibraryButtons)); null before INIT. -
libraryJobs
The library's jobs this TeleOp has: "pause" only withbackTap(), "field-centric" only where possible, "set pose" only withsetPoseJob()...- Parameters:
withButtonMap- true if there is a button map (buttonHelp())
-
keyWords
"G1 BACK" for a job's button ("BACK" alone on gamepad 1), or "(no button)". -
switchAlliance
protected final void switchAlliance()Switches the alliance now (BLUE to RED, or RED to BLUE), in case the wrong one was chosen: everything that readsalliance()orMatchMemorygets the new one, both gamepads buzz twice and the Driver Station says so. The switch-alliance buttons call it (both heldLibraryButtons.SWITCH_ALLIANCE_SECs). -
driveSpeed
protected final double driveSpeed()The driving speed the library's slow buttons ask for now, 0 to 1 (1 = full speed): the slow trigger (the further, the slower), a slow button held, or slow on/off. -
addInitTelemetry
Extra lines for the Driver Station during INIT (before START), every INIT loop. -
onStart
protected void onStart()Runs once, right after START, before the first loop. Must be quick: start things here, never wait. Nothing may move before START, so this is the first moment a mechanism may move. -
startFieldCentric
protected boolean startFieldCentric()True to start in field-centric mode. Default false (robot-centric). -
fieldCentricButton
The gamepad 1 button that switches field-centric driving on and off (mecanum with an IMU only). Default Y. Return null for none (then field-centric stays asstartFieldCentric()says). A shortcut:libraryButtons(LibraryButtons)can put it on any button of either gamepad. -
slowSpeed
protected double slowSpeed()Speed at a full squeeze of the slow trigger, 0 to 1. Default 0.3. -
configureDriving
Changes how driving feels, once, in INIT, right after the drive is made. Example:driving.sticks(0.08, 3);for a bigger deadband and a stronger curve. -
buzzAtSecondsLeft
protected double[] buzzAtSecondsLeft()Seconds left when both gamepads buzz. Default 60 and 20 (1:00 and 0:20 left). Change it to the moments that matter in this season's game. -
drive
protected void drive(com.qualcomm.robotcore.hardware.Gamepad gamepad) Drives the robot from gamepad 1, every loop (not while the tuning menu is open). Default: the standard controls. Replace it to drive your own way, withdriving()'sdrive(...)ortank(...). Example, two-stick tank style:@Override protected void drive(Gamepad gamepad) { driving().tank(-gamepad.left_stick_y, -gamepad.right_stick_y, 1); } -
alliance
The alliance autonomous chose (BLUE if no autonomous ran in the last few minutes). -
robotTelemetry
The Driver Station screen helper (warnings, standard and debug lines). -
driving
The driving (field-centric on/off, slow mode). -
heading
The heading compared with the driver, or null if there is no IMU. -
matchTimer
The 2:00 match timer (started at START). -
isTuningMenuOpen
protected boolean isTuningMenuOpen()True while the tuning menu is open. Gamepad 1 belongs to the menu then: do not read its sticks. -
initMenu
protected boolean initMenu()The INIT menu on gamepad 1's D-pad (alliance, profile)? Default on. Override withreturn falsewhen your own INIT code uses gamepad 1's D-pad. -
runOpMode
public final void runOpMode()The whole TeleOp. The FTC SDK calls this when you press INIT.final: your class cannot replace it, so the safety steps here always run.- Specified by:
runOpModein classcom.qualcomm.robotcore.eventloop.opmode.LinearOpMode
-
requestOpModeStop
public final void requestOpModeStop()
-