TeleOp Programming Concepts

beginner45 min

TeleOp overview

TeleOp code runs while drivers hold the gamepads. You read sticks and buttons, set motor and servo outputs, and show telemetry on the Driver Station.

Gamepad input

gamepad1 and gamepad2 expose sticks, triggers, and buttons.

Reading gamepad input

double drive = -gamepad1.left_stick_y; // Forward/backward
double turn = gamepad1.right_stick_x;   // Turning
boolean aPressed = gamepad1.a;          // Button A
if (aPressed) {
    // Do something when A is pressed
}

Mapping input to mechanisms

Typical pattern: left stick for drive, buttons for a claw or arm.

Drive and claw example

// Drive control
double leftPower = -gamepad1.left_stick_y;
double rightPower = -gamepad1.right_stick_y;
leftDrive.setPower(leftPower);
rightDrive.setPower(rightPower);
// Claw control
if (gamepad1.a) {
    clawServo.setPosition(1.0); // Open
} else if (gamepad1.b) {
    clawServo.setPosition(0.0); // Close
}

Telemetry for drivers

Call telemetry.addData() then telemetry.update() once per loop.

See Telemetry Logging for basics.

Telemetry example

telemetry.addData("Left Power", leftPower);
telemetry.addData("Right Power", rightPower);
telemetry.addData("Claw Position", clawServo.getPosition());
telemetry.update();

Practice Exercise: Custom TeleOp Controls

Write a TeleOp OpMode that uses the left stick to drive, the right stick to turn, and buttons A/B to open/close a claw. Add telemetry to display all relevant values. Refactor your code to use helper methods for each subsystem.

  • Map drive motors and a claw servo.
  • Read joystick and button values from gamepad1.
  • Set motor and servo power based on input.
  • Add telemetry for all controls.
  • Refactor code into helper methods.

Related Topics and Documentation