Unit 6: Intermediate FRC Coding
As a programmer, you are a robot diagnostician. When a mechanism fails, the first question is always: "Is this a code problem or a hardware problem?" This lesson teaches a systematic approach to find the answer quickly.
The most effective debugging is a process of elimination. You start with the simplest, most fundamental test to rule out entire categories of problems, then work your way up in complexity.
You've deployed code, you press the button, and nothing happens. Here is the checklist to run through.
Before you look at a single line of your own code, perform the simplest test: does the motor work at all? The Driver Station's "Test Mode" lets you bypass your code entirely.
If the motor spins: The hardware is likely fine. The problem is in your code. Proceed to Step 2.
If the motor does NOT spin: This is an electrical or mechanical issue. Alert the appropriate subteam. They will check wiring, power, and the motor controller's status lights.
If the hardware works, the problem is in your code. The next step is to simplify the code to its most basic form. In `RobotContainer.java`, temporarily replace your complex command binding with the simplest possible command: a "run once" action.
// In configureButtonBindings() in RobotContainer.java
// Temporarily comment out your complex command
// .whileTrue(new ComplicatedIntakeCommand(m_intake));
// Replace it with the simplest possible command
new JoystickButton(m_operatorController, XboxController.Button.kA.value)
.onTrue(Commands.runOnce(() -> m_intake.setMotorSpeed(0.5), m_intake));
Deploy and test. If the motor spins now, the problem is in your original command's logic. If it still doesn't spin, the problem is more fundamental.
If the simplest command doesn't work, the issue is likely in the Subsystem itself. The two most common errors are:
public class IntakeSubsystem extends SubsystemBase {
// This is declared...
private final Spark m_intakeMotor;
public IntakeSubsystem() {
// ...but was it initialized here? This line is crucial!
m_intakeMotor = new Spark(5); // Is port 5 correct?
}
}
Question: A motor on your robot is not spinning when you press the assigned controller button. According to the systematic debugging process, what is the very first thing you should do?