TeleOp Programming Concepts
Overview of TeleOp Programming
TeleOp programming is the process of writing code that allows drivers to control the robot in real time using gamepads. In this lesson, you'll learn how to read gamepad input, map controls to robot actions, and use telemetry for feedback.
Gamepad Input Handling
The
gamepad1 and gamepad2 objects provide access to all the buttons, sticks, and triggers on the controllers. Reading these values lets you control motors, servos, and other mechanisms.Example: 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 Gamepad Inputs to Robot Actions
You can use gamepad input to control motors, servos, and other mechanisms. For example, you might use the left stick for driving and a button to control a claw.
Example: Mapping Controls to Drive and Servo
// 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 Debugging and Feedback
Telemetry lets you send data from your robot to the Driver Station for real-time feedback. Use
For more on telemetry, see FTC Docs: Telemetry or Telemetry Logging.
telemetry.addData() to add information and telemetry.update() to send it. This is essential for debugging and for providing drivers with useful information during a match. For more on telemetry, see FTC Docs: Telemetry or Telemetry Logging.
Example: Using Telemetry
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.