Gamepad Controls in FTC
Gamepad API
TeleOp reads gamepad1 and gamepad2 each loop. Field names match the FTC gamepad layout.
Full list: FTC Docs: Gamepad Input.
Input reference
- Analog: left_stick_x, left_stick_y, right_stick_x, right_stick_y, left_trigger, right_trigger
- Digital: a, b, x, y, dpad_up, dpad_down, dpad_left, dpad_right, left_bumper, right_bumper, start, back
Analog and digital inputs
// Analog inputs
double drive = -gamepad1.left_stick_y;
double turn = gamepad1.right_stick_x;
double lift = gamepad1.right_trigger - gamepad1.left_trigger;
// Digital inputs
boolean openClaw = gamepad1.a;
boolean closeClaw = gamepad1.b;
boolean slowMode = gamepad1.left_bumper;
Button toggles and edge detection
A toggle flips state once per press. Compare the current button to lastA so the action does not repeat every loop while held.
Toggle example
private boolean lastA = false;
private boolean clawOpen = false;
private void controlClaw() {
if (gamepad1.a && !lastA) {
clawOpen = !clawOpen;
clawServo.setPosition(clawOpen ? 1.0 : 0.0);
}
lastA = gamepad1.a;
}
Combined inputs
Require two buttons for safety-sensitive actions.
Safety interlock example
if (gamepad1.left_bumper && gamepad1.a) {
// Only run this if both are pressed
armMotor.setPower(1.0);
}
Two drivers
Assign drive to gamepad1 and a mechanism to gamepad2.
Two-gamepad example
// gamepad1 drives, gamepad2 operates arm
double leftPower = -gamepad1.left_stick_y;
double rightPower = -gamepad1.right_stick_y;
leftDrive.setPower(leftPower);
rightDrive.setPower(rightPower);
if (gamepad2.a) {
armMotor.setPower(1.0);
}
Slow mode
Scale stick input when a bumper is held for fine alignment.
Slow mode example
double speed = gamepad1.left_bumper ? 0.3 : 1.0;
double leftPower = -gamepad1.left_stick_y * speed;
double rightPower = -gamepad1.right_stick_y * speed;
leftDrive.setPower(leftPower);
rightDrive.setPower(rightPower);
Macros
Run a short sequence on a button press (use edge detection so it fires once).
Simple macro example
if (gamepad1.x && !lastX) {
// Run a macro: open claw, move arm
clawServo.setPosition(1.0);
armMotor.setPower(1.0);
sleep(500);
armMotor.setPower(0.0);
}
lastX = gamepad1.x;
Control layout tips
Name methods by subsystem. Test toggles, slow mode, and macros alone before merging them.
Practice Exercise: Gamepad Mapping and Advanced Controls
Write code to control a drive train with the left stick, a lift with the bumpers, and a claw with buttons A/B. Implement a toggle for the claw using edge detection. Add a slow mode, a macro, and assign subsystems to different gamepads.
- Map drive motors, a lift motor, and a claw servo.
- Read analog and digital inputs from gamepad1.
- Implement edge detection for the claw toggle.
- Add a slow mode for precision driving.
- Create a macro that runs a sequence of actions.
- Assign subsystems to different gamepads.