Troubleshooting Common FTC Programming Issues

intermediate55 min

Introduction

These issues appear on almost every team at some point: wrong device names, code before waitForStart(), and motors used before mapping.

Hardware mapping errors

hardwareMap.get() strings must match configuration exactly, including case.

Case-sensitive name example

LEFT_DRIVE does not match left_drive:

leftMotor = hardwareMap.get(DcMotor.class, "LEFT_DRIVE");

OpMode lifecycle

Map hardware before waitForStart(). Driver controls belong inside while (opModeIsActive()).

Correct structure

@TeleOp
public class LifecycleExample extends LinearOpMode {
    private DcMotor leftMotor;
    @Override
    public void runOpMode() {
        leftMotor = hardwareMap.get(DcMotor.class, "left_drive");
        waitForStart();
        while (opModeIsActive()) {
            leftMotor.setPower(0.5);
        }
    }
}

Use after init only

Calling setPower() before hardwareMap.get() fails or behaves unpredictably.

Init order example

// Correct
leftMotor = hardwareMap.get(DcMotor.class, "left_drive");
// Incorrect (will cause errors)
leftMotor.setPower(1.0); // leftMotor not initialized yet

Quick checklist

  • Check that all device names in your code match your configuration.
  • Initialize all hardware before waitForStart().
  • Put your main robot logic inside while (opModeIsActive()).
  • Use telemetry to display variable values and program state.
  • Read error messages carefully and look up unfamiliar terms.

Practice: Find and Fix Common Issues

Below is an OpMode with multiple errors. Your task is to identify all the problems and fix them. Here are the devices configured in your robot:

  • Identify all errors in the provided OpMode code.
  • Explain what each error is and why it occurs.
  • Provide a corrected version of the OpMode.
// Configured Devices:
// - left_drive (DcMotor)
// - right_drive (DcMotor)
// - claw_servo (Servo)
// - color_sensor (ColorSensor)
// - distance_sensor (DistanceSensor)

// Find all the errors in this OpMode:
@TeleOp
public class BuggyOpMode extends LinearOpMode {
    private DcMotor leftMotor, rightMotor;
    private Servo clawServo;
    private ColorSensor colorSensor;
    private DistanceSensor distanceSensor;
    
    @Override
    public void runOpMode() {
        // Initialize hardware
        leftMotor = hardwareMap.get(DcMotor.class, "LEFT_DRIVE");
        rightMotor = hardwareMap.get(DcMotor.class, "right_drive");
        clawServo = hardwareMap.get(Servo.class, "claw_servo");
        colorSensor = hardwareMap.get(ColorSensor.class, "color_sensor");
        distanceSensor = hardwareMap.get(DistanceSensor.class, "distance_sensor");
        
        // Set motor power before initialization
        leftMotor.setPower(0.5);
        
        telemetry.addData("Status", "Initialized");
        telemetry.update();
        
        waitForStart();
        
        // Main loop
        while (opModeIsActive()) {
            // Drive logic
            double leftPower = -gamepad1.left_stick_y;
            double rightPower = -gamepad1.right_stick_y;
            leftMotor.setPower(leftPower);
            rightMotor.setPower(rightPower);
            
            // Claw control
            if (gamepad1.a) {
                clawServo.setPosition(1.0);
            } else if (gamepad1.b) {
                clawServo.setPosition(0.0);
            }
            
            // Sensor reading
            if (colorSensor.red() > 100) {
                telemetry.addData("Color Detected", "Red");
            }
            
            if (distanceSensor.getDistance(DistanceUnit.CM) < 10) {
                telemetry.addData("Distance", "Object close");
            }
            
            telemetry.addData("Left Power", leftPower);
            telemetry.addData("Right Power", rightPower);
            telemetry.addData("Claw Position", clawServo.getPosition());
            telemetry.update();
        }
        
        // Code after the loop (will never execute)
        leftMotor.setPower(0);
        rightMotor.setPower(0);
    }
}

Further Reading Resources