Skip to content
Work in progress. This library and its docs are new and still changing, and some parts are not yet tested on a real robot. If something is wrong or unclear,tell us with a short GitHub form.

Controls.java: the buttons, and the TeleOp

Controls.java is your TeleOp: the program the drivers pick on the Driver Hub. It says what each button does. The library always sets up its own buttons (driving, pause, the button map). Each part’s buttons are lines in this file, so you can read and change every one.

This is a whole Controls.java. The robot has no parts yet, so it has no buttons of its own. It drives on the library’s buttons. The file writes them out so you can see each one, and it has a line for every free button. Click a (+) to read what a line does.

Controls.java
import com.crossbotics.ftchelper.robot.ControlMap;
import com.crossbotics.ftchelper.robot.Pad;
import com.crossbotics.ftchelper.teleop.LibraryButtons;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
/** The five files, file 3 of 5: the buttons, and the TeleOp. */
@TeleOp(name = "First Robot TeleOp")
public class Controls extends ControlMap<Robot> {
public static boolean oneDriver = true;
// Always there: the library's buttons, on gamepad 1. These lines are the defaults (one driver):
// without this method the buttons are the same. Change a line to move a button; null = no button.
@Override
protected void libraryButtons(LibraryButtons lib, Pad g1, Pad g2) {
lib.swapSticks(false); // left stick: drive and slide; right stick X: turn
lib.slow(null); // slow while a trigger is pulled: none (the triggers are free)
lib.slowToggle(g1.leftStickButton); // left stick click: slow on / off
lib.fieldCentric(g1.rightStickButton); // right stick click, a double tap: field-centric on / off
lib.pause(g1.back); // BACK: pause at the press; a tap goes on
lib.resetForward(g1.back); // BACK held 1 s: "forward" is where the robot faces now
lib.debug(g1.start, g1.back); // hold START, then press BACK: the debug lines
lib.setPose(g1.start); // START held 1 s: set pose here (robots with odometry)
lib.buttonMap(g1.guide); // GUIDE: the button map on the Driver Hub
lib.tuningMenu(g1.guide); // GUIDE held 1 s: the tuning menu (PRACTICE profile)
lib.allianceInInit(g1.x, g1.b); // in INIT: X = BLUE, B = RED
}
@Override
protected void buttons(Robot robot, Pad g1, Pad g2) {
// Every other button is a line here: each part's buttons, then your own. This robot has no parts yet.
// The free buttons: replace free() with a job, e.g. .press(...), .hold(...), .toggle(...), .tap(...).
g1.a.free();
g1.b.free(); // B and X choose the alliance in INIT only: free in the match
g1.x.free();
g1.y.free();
g1.lb.free();
g1.rb.free();
g1.lt.free(); // a trigger counts as pressed past half way
g1.rt.free();
g1.dpadUp.free();
g1.dpadDown.free();
g1.dpadLeft.free();
g1.dpadRight.free();
g1.rightStickY.free(); // a stick: .use(...) gets its value every loop
}
}
  1. The TeleOp’s name in the Driver Hub’s list. Change it to your robot’s name.
  2. ControlMap<Robot>: a TeleOp for the robot in your Robot.java. The library runs the loop, drives, and keeps every part updated.
  3. true: one gamepad. The driver drives and runs the parts, and g2 lines are on gamepad 1 too. Most teams start here. false: add gamepad 2 when you want to split the work, or for jobs that are hard to do while you drive (like arm control). Then the g2 lines move to gamepad 2 (One gamepad, and a second one).
  4. Always there: the library’s own buttons, one line each. These lines are the defaults, so without this method the buttons are the same. Change a line to move a button. null = no button.
  5. BACK pauses the robot at once: every motor stops. Keep it on a button: it is the drivers’ safety stop.
  6. Every other button is a line here. A part has no buttons until you add its lines. The reference has each part’s usual lines (Intake: buttons to add, and the same for every part).
  7. Every free button has a line, so you see what you can use. Replace free() with a job. When you add a part’s lines, delete the free() lines of the buttons they use: one line per button.

The first line of the file (above the imports) must be:

package org.firstinspires.ftc.teamcode;

With Robot.java, Tunables.java and this file, the robot drives.

  1. Build and install: Run in Android Studio (the buttons).
  2. Put the robot on a block, with its wheels off the floor.
  3. On the Driver Hub, pick First Robot TeleOp and press INIT. The screen shows the button map.
  4. Press ▶. Push the left stick forward: all four wheels turn forward.
  5. Take it off the block and drive. Tunables.Drive.maxPower = 0.5 keeps it slow.
  6. Check each one:
    • Stick up = forward, stick down = back, right stick right = turn clockwise.
    • Mecanum: left stick right = slide right, in a straight line.
    • Slow: pull LT (two gamepads; the further you pull, the slower), or click the left stick (one gamepad).
    • Mecanum: double-tap Y, or the right stick click with one gamepad (two buzzes: field-centric on). Turn the robot 90 degrees, and push the stick up. The robot still goes away from you.
    • Tap BACK: every part stops and the Driver Hub says PAUSED. Tap BACK again: it drives.

Robot-centric and field-centric. Robot-centric (the start): stick up = the way the robot faces. Field-centric: stick up = away from the driver, whichever way the robot faces. “Away” is the way the robot faced at INIT, or what the autonomous left. When it is wrong: turn field-centric on, point the robot away from you, and hold BACK 1 s (one buzz).

In the simulator: pick Simulator in the run list and click Run. Then pick the TeleOp on the simulator’s Driver Hub.

Done when: the robot drives forward, back, sideways (mecanum) and turns, the way the sticks say.

When a wheel turns the wrong way, fix it in Robot.java: a wheel turns the wrong way.

The library’s own buttons are always there, on gamepad 1. You write nothing for them, and every TeleOp has them. Why: BACK must always pause the robot, even in a file with a mistake.

Job One gamepad (oneDriver = true) Two gamepads
Drive and slide left stick left stick
Turn right stick, left and right right stick, left and right
Slow left stick click: slow on/off LT (the further, the slower)
Field-centric on/off (mecanum) right stick click (a double tap) Y (a double tap)
Pause / go on BACK (a tap) BACK (a tap)
Button map on the screen GUIDE (a tap) GUIDE (a tap)
Tuning menu GUIDE (held 1 s) GUIDE (held 1 s)
Choose the alliance (in INIT) X = BLUE, B = RED X = BLUE, B = RED

To move one: Moving the library’s buttons.

Every other button is a line in buttons(...). A part has no buttons until you add its lines, so every button the robot has is a line you can read in this file. Each part’s usual lines, ready to copy:

Part Usual buttons The lines
Intake RT: in (hold). LT: out (hold) Intake: buttons to add
Launcher LB: spin up / down. RB: fire one (tap), keep firing (hold). D-pad up and down: speed Launcher: buttons to add
Lift A, X, Y: heights. D-pad up and down: next height. Left stick: by hand Lift: buttons to add
Arm right stick: by hand Arm: buttons to add
Claw B: open / close Claw: buttons to add
Wrist D-pad left and right: positions Wrist: buttons to add
Turret right stick, left and right: by hand. right stick click: follow the goal on / off Turret: buttons to add

INIT tells you what is missing. When a part’s usual buttons are not in Controls.java, INIT shows a line for it, for example Intake: usual buttons not in Controls.java: G2 RT (in (hold)), G2 LT (out (hold)). INIT counts a button you used for something else as your choice.

The example allbuttons/Controls.java is a robot with a mecanum drive, an intake, a launcher and two drivers. It has every library button in libraryButtons(...), the intake’s and the launcher’s usual lines, and a free() line for every free button on both gamepads. A test checks that its lines are the parts’ usual ones.

Each button line has up to four pieces:

// 1. which button 2. how it starts 3. what it does 4. what the drivers see
g2.y .press( robot.claw::open) .says("open the claw");

For example, two buttons for a claw and a lift:

Controls.java
// Once per press. "::" hands over the method; the button runs it later.
g2.y.press(robot.claw::open).says("open the claw");
// Several commands: "() ->" starts a small piece of code (a lambda).
g2.x.press(() -> robot.lift.goTo("low")).says("lift to low");

Always add .says(...). The words go on the button map, so the drivers know what the button does.

Buttons Name in the code
Face buttons a, b, x, y
Bumpers lb, rb
Triggers (pressed past half way) lt, rt
D-pad dpadUp, dpadDown, dpadLeft, dpadRight
Stick clicks leftStickButton, rightStickButton
Small buttons back, start, guide
Sticks (a number from -1 to 1) leftStickX, leftStickY, rightStickX, rightStickY
Press type Write The job runs
Press .press(job) once, the moment the driver presses it
Let go .release(job) once, the moment the driver lets it go
Hold .hold(job) every loop while the driver holds it
Hold, then stop .hold(job, stopJob) every loop while the driver holds it, then stopJob once when the driver lets go
On / off .toggle(part) each press switches the part on or off
On / off, two jobs .toggle(onJob, offJob) presses take turns
Tap .tap(job) once per quick press
Double tap .doubleTap(job) once, on the second quick tap
Several taps .taps(3, job) once, on the last of 2 to 5 quick taps
Tap, then hold .tapThenHold(job) a tap, then press again and hold: every loop while held
Held for a time .heldFor(1.0, job) once, after the driver holds it 1 s: a safe “are you sure?”
Two buttons g2.lb.with(g2.y, job) once, when the driver presses Y while holding LB
A stick g2.leftStickY.use(robot.lift::manual) every loop, with the stick’s value

Gestures can share a button. tap, doubleTap, taps, tapThenHold, heldFor and hold chain on one button, each with its own job:

g2.rb.tap(robot.launcher::fire).says("fire one")
.hold(robot.launcher::fireWhileHeld, robot.launcher::ceaseFire).says("keep firing");

press, toggle and release each need a button of their own. Press types says when each gesture’s job runs, and how to change the double-tap time and the hold time.

The job Example
A part’s command robot.claw::open
A few commands () -> { robot.claw.open(); robot.intake.stop(); }
An action: several steps, like “score” Actions.scoreHigh(robot) (the next page: Actions.java)
A part to switch on and off robot.intake (with .toggle(...))

A job must never wait. No sleep(...) and no while loop: it freezes the whole robot. To do steps one after another, use an action.

You want Write
Words on the button map .says("open the claw")
A buzz when the job runs .rumble(), or .rumble(2) for two buzzes
A buzz when something becomes true g2.rumbleWhen(robot.launcher::isReady); (a line of its own)
A value on the Driver Hub show("Lift", robot.lift::position); (a line of its own)

A part’s buttons are your lines: change the button in its line. For example, the intake on the bumpers in place of the triggers:

Controls.java
// The intake's usual lines are on RT and LT: here the same jobs are on the bumpers.
g2.lb.hold(robot.intake::holdIn, robot.intake::stop).says("intake in (hold)");
g2.rb.hold(robot.intake::out, robot.intake::stop).says("intake out (hold)");

Build and install, then INIT the TeleOp.

Done when: INIT shows your button map with your words, and each button does its job.

INIT stops with a message when a button has two jobs, or when your job is on one of the library’s buttons. The message names the button.

If the drive goes wrong:

Problem Fix
INIT stops with a list of names A motor name in Robot.java does not match the configuration (capitals too)
It spins or drifts when it should go straight A motor direction is wrong: a wheel turns the wrong way
Stick up drives backward Every direction is flipped: reverse the other side
It slides on a slant when it should slide sideways Two motor names are on the wrong wheels (for example front_left and back_left swapped)
Field-centric goes the wrong way or circles The IMU’s logo and USB directions (check it), or “away” is wrong: hold BACK 1 s
Everything stopped and does not move It is paused: tap BACK
Slow even without LT maxPower is low, or practiceMaxPower is low in the PRACTICE profile

Next: Actions.java. Look it up: every press type and option. Go deeper: the cookbook’s button recipes.

Something wrong on this page? Tell us with a short GitHub form.