Class ControlMap<R extends RobotDefinition>

java.lang.Object
com.qualcomm.robotcore.eventloop.opmode.OpMode
com.qualcomm.robotcore.eventloop.opmode.LinearOpMode
com.crossbotics.ftchelper.teleop.EasyTeleOp
com.crossbotics.ftchelper.robot.ControlMap<R>

public abstract class ControlMap<R extends RobotDefinition> extends EasyTeleOp
The team's TeleOp and button map in one file, Controls.java. The library's own buttons (driving, pause, menus) are always there; every other button is a line in buttons(...), a part's too (each part's "buttons to add" in docs/reference/robot-java.md).

 @TeleOp(name = "TeleOp")
 public class Controls extends ControlMap<Robot> {
     public static boolean oneDriver = false;   // true: everything on gamepad 1

     @Override protected void buttons(Robot robot, Pad g1, Pad g2) {
         g2.y.press(Actions.scoreHigh(robot));   // an action on Y
         g2.rightStickButton.free();              // free: nothing yet
     }
 }
 

The library's own buttons (gamepad 1 by default): left stick drives (and strafes on mecanum), right stick X turns, LT slow (the further it is pulled, the slower), Y double-tap: field-centric on/off (mecanum), BACK pauses everything at the press (motors on brake; a tap again to go on), holding BACK 1 s also resets "forward" (field-centric), hold START then press BACK: debug lines (BACK first is just a pause), START held 1 s sets the pose to the reset spot (robots with odometry; sticks let go; also in INIT), GUIDE shows the button map (a tap) or opens the tuning menu (held 1 s, PRACTICE profile). Switching the alliance during TeleOp is off unless you turn it on: lib.switchAlliance(g1.start, g1.back). With oneDriver = true: left stick click slow on/off, right stick click field-centric, and the operator's buttons move to gamepad 1. Every one can be moved or freed in libraryButtons(LibraryButtons, Pad, Pad).

Checked at INIT: a button with two jobs in this file, or a job on a driving button, stops with the button's name. INIT shows the whole map, the Tunables notes and any tuned values that differ from Tunables.java (lines to copy back).

Everything else is EasyTeleOp: match timer, buzzes, everything stopped at the end. Docs: docs/reference/robot-java.md (section "Controls")

  • Field Details

    • 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

    • ControlMap

      public ControlMap()
  • Method Details

    • buttons

      protected abstract void buttons(R robot, Pad g1, Pad g2)
      Your buttons, after the modules' standard ones. A job here replaces a module's suggestion on the same button.

      It runs once, in INIT. Code of your own for this TeleOp only goes here too: robot.duringInit(...), robot.atStart(...), robot.everyLoop(...), robot.atStop(...) (docs/guides/your-own-code.md).

      Parameters:
      robot - your robot (its modules are set up)
      g1 - the driver's gamepad (the operator's too with oneDriver)
      g2 - the operator's gamepad (with oneDriver = true: gamepad 1, the same as g1)
    • libraryButtons

      protected void libraryButtons(LibraryButtons lib, Pad g1, Pad g2)
      Moves or frees the library's own buttons (driving, pause, slow, field-centric, menus, "set pose here", "switch alliance"). Default: nothing changes. Two jobs on one button stop at INIT with the button's name; a job of yours on a library button too.
      
       @Override protected void libraryButtons(LibraryButtons lib, Pad g1, Pad g2) {
           lib.fieldCentric(g1.x);              // Y is free for buttons(...) now
           lib.setPose(g1.dpadDown);            // hold D-pad down 1 s: set pose here
           lib.switchAlliance(g1.start, g1.back);   // turn on the alliance switch (hold START, then BACK, 1.5 s)
       }
       
      Parameters:
      lib - the library's buttons, at their defaults (one driver: the one-driver ones)
      g1 - gamepad 1's buttons, to name them
      g2 - gamepad 2's (with oneDriver = true: gamepad 1, the same as g1)
    • useStandardButtons

      protected boolean useStandardButtons()
      True: each part adds its usual buttons by itself (the way before v0.39.0), and a line of yours on one of those buttons replaces it. Default false: a part has no buttons until Controls.java writes its lines, so every button is a line you can read. INIT names each part's usual button that is still free ("Intake: usual buttons not in Controls.java: G2 RT (in (hold)), ..."). The usual lines: docs/reference/robot-java.md, each part's "Buttons to add".
    • robot

      protected final R robot()
      The robot, made from ControlMap<Robot>'s type.
    • oneDriver

      protected final boolean oneDriver()
      True if this class has public static boolean oneDriver = true.
    • robotConfig

      protected final RobotConfig robotConfig()
      Description copied from class: EasyTeleOp
      Your robot's settings, shared with autonomous (see RobotConfig). Return new RobotSettings(). If you do not have one, override EasyTeleOp.driveConfig() and EasyTeleOp.createImu() instead.
      Overrides:
      robotConfig in class EasyTeleOp
    • slowSpeed

      protected final double slowSpeed()
      Description copied from class: EasyTeleOp
      Speed at a full squeeze of the slow trigger, 0 to 1. Default 0.3.
      Overrides:
      slowSpeed in class EasyTeleOp
    • fieldCentricButton

      protected final ControllerBindings.Btn fieldCentricButton()
      Description copied from class: EasyTeleOp
      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 as EasyTeleOp.startFieldCentric() says). A shortcut: EasyTeleOp.libraryButtons(LibraryButtons) can put it on any button of either gamepad.
      Overrides:
      fieldCentricButton in class EasyTeleOp
    • createSubsystems

      protected final Subsystems createSubsystems()
      Description copied from class: EasyTeleOp
      Your mechanisms: kept updated every loop and stopped at the end. Default: none.
      Overrides:
      createSubsystems in class EasyTeleOp
    • createHeading

      protected final DriverHeading createHeading(com.qualcomm.robotcore.hardware.IMU imu)
      Description copied from class: EasyTeleOp
      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.
      Overrides:
      createHeading in class EasyTeleOp
      Parameters:
      imu - the IMU from EasyTeleOp.createImu(), or null
    • standardLibraryButtons

      protected final LibraryButtons standardLibraryButtons()
      Description copied from class: EasyTeleOp
      The defaults before EasyTeleOp.libraryButtons(LibraryButtons): LibraryButtons.twoDrivers(), with field-centric on EasyTeleOp.fieldCentricButton(). Controls.java gives the one-driver ones.
      Overrides:
      standardLibraryButtons in class EasyTeleOp
    • libraryButtons

      protected final void libraryButtons(LibraryButtons lib)
      Description copied from class: EasyTeleOp
      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.
      Overrides:
      libraryButtons in class EasyTeleOp
      Parameters:
      lib - the buttons, already at their defaults (LibraryButtons.twoDrivers())
    • setPoseJob

      protected final Supplier<String> setPoseJob()
      Description copied from class: EasyTeleOp
      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.
      Overrides:
      setPoseJob in class EasyTeleOp
    • setPoseMissingNote

      protected final String setPoseMissingNote()
      Description copied from class: EasyTeleOp
      With no EasyTeleOp.setPoseJob(): 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.
      Overrides:
      setPoseMissingNote in class EasyTeleOp
    • allianceChanged

      protected final void allianceChanged(Alliance now)
      Description copied from class: EasyTeleOp
      Called when the alliance changes during TeleOp (EasyTeleOp.switchAlliance()), after EasyTeleOp.alliance() has the new one: update what uses it. Default: nothing. Must not wait.
      Overrides:
      allianceChanged in class EasyTeleOp
    • bindButtons

      protected final void bindButtons(ControllerBindings driver, ControllerBindings operator)
      Description copied from class: EasyTeleOp
      Your buttons. Put gamepad 2 buttons on operator. Extra gamepad 1 buttons go on driver: those pause while the tuning menu is open (it uses gamepad 1). Already taken on gamepad 1 (unless moved with EasyTeleOp.libraryButtons(LibraryButtons)): LT, Y (field-centric), BACK, START (with BACK: debug lines), GUIDE.
      Overrides:
      bindButtons in class EasyTeleOp
    • buttonHelp

      protected final List<String> buttonHelp()
      Description copied from class: EasyTeleOp
      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.
      Overrides:
      buttonHelp in class EasyTeleOp
    • backTap

      protected final Runnable backTap()
      Description copied from class: EasyTeleOp
      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 BACK EasyTeleOp.BACK_HOLD_SEC resets "forward". The buttons can be moved: EasyTeleOp.libraryButtons(LibraryButtons).
      Overrides:
      backTap in class EasyTeleOp
    • pauseState

      protected final BooleanSupplier pauseState()
      Description copied from class: EasyTeleOp
      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, EasyTeleOp.backTap() runs when BACK is let go. Controls.java gives one.
      Overrides:
      pauseState in class EasyTeleOp
    • drive

      protected final void drive(com.qualcomm.robotcore.hardware.Gamepad gamepad)
      Description copied from class: EasyTeleOp
      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, with EasyTeleOp.driving()'s drive(...) or tank(...). Example, two-stick tank style:
      
       @Override protected void drive(Gamepad gamepad) {
           driving().tank(-gamepad.left_stick_y, -gamepad.right_stick_y, 1);
       }
       
      Overrides:
      drive in class EasyTeleOp
    • onStart

      protected final void onStart()
      Description copied from class: EasyTeleOp
      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.
      Overrides:
      onStart in class EasyTeleOp
    • addTelemetry

      protected final void addTelemetry(RobotTelemetry t)
      Description copied from class: EasyTeleOp
      Extra lines for the Driver Station, every loop. The mechanisms' lines are already shown.
      Overrides:
      addTelemetry in class EasyTeleOp
    • route

      protected final Runnable route(String label, double xIn, double yIn, double headingDeg, double maxPower)
      Makes a job that drives the robot to a field spot by itself, around the boxes of fieldMap(...) in Robot.java. Call it in buttons(...) and give the job to a button or a time. It works out the route when the job starts, from where the robot is then.
      
       Runnable park = route("Park", -56, -36, 0, 0.8);
       g1.dpadLeft.tap(park).says("drive to the park spot");
       atSecondsLeft(10, park);
       

      Any drive stick stops it at once, and the sticks drive from then on. Pause and the tuning menu stop it too, and it stays stopped. It also ends when it is stuck, when the odometry stops working, or after actionTimeoutSec on one line of the route; the Driver Station says why. It never waits: the rest of the robot keeps running. It cannot see another robot.

      Mistakes stop INIT: no fieldMap(...) or odometry(...) line, a tank drive, or a spot on a box. In the match it does not set off without a known pose, and on a real robot only after the Drive Tuner and the Odometry Tuner (Tunables.Drive.calibrated, Tunables.Odometry.checked; the INIT screen warns). Docs: docs/modules/odometry.md, "Keep-out boxes and routes".

      Parameters:
      label - a name for the Driver Station
      xIn - inches right of the center line, written for BLUE like driveTo
      yIn - inches from the center toward the far wall
      headingDeg - the heading to turn to (counterclockwise +; 0 = facing away)
      maxPower - 0.1 to 1
      Returns:
      the job: it starts the route, and returns at once
    • route

      protected final Runnable route(String label, double xIn, double yIn, double headingDeg, double maxPower, double toleranceIn)
      route(String, double, double, double, double) with your own "close enough" at the end, inches.
    • routeRunning

      protected final boolean routeRunning()
    • stopRoute

      protected final void stopRoute()
      Ends a running route(java.lang.String, double, double, double, double) job now (nothing happens if none runs).
    • atSecondsLeft

      protected final void atSecondsLeft(double seconds, Runnable job)
      Runs a job once, when this many seconds of TeleOp are left, e.g. atSecondsLeft(10, park). Call it in buttons(...). The job must be quick, like a button's.

      A route(java.lang.String, double, double, double, double) job does not take the robot from a driver who is driving. If a drive stick is pushed at that time (or the robot is paused, or the menu is open), the gamepad buzzes and the route waits up to 5 s. It starts on the first loop the sticks are let go. After 5 s it gives up.

      Parameters:
      seconds - seconds left on the clock
      job - what to do
    • show

      protected final void show(String label, Supplier<?> value)
      Shows a value of your own on the Driver Station during the match, read again every loop. Call it in buttons(...), e.g. show("Lift ticks", robot.lift::position); or show("Ready", () -> robot.launcher.isReady());.
      Parameters:
      label - the words before the value
      value - how to read it (a method reference or a small lambda; it must not wait)
    • everyLoop

      protected final void everyLoop()
      Description copied from class: EasyTeleOp
      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.
      Overrides:
      everyLoop in class EasyTeleOp
    • atEnd

      protected final void atEnd()
      Description copied from class: EasyTeleOp
      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.
      Overrides:
      atEnd in class EasyTeleOp
    • addInitTelemetry

      protected final void addInitTelemetry(RobotTelemetry t)
      Description copied from class: EasyTeleOp
      Extra lines for the Driver Station during INIT (before START), every INIT loop.
      Overrides:
      addInitTelemetry in class EasyTeleOp
    • requestOpModeStop

      public final void requestOpModeStop()