You do not need all of Java to write great robot code. You need classes, fields, methods, control flow, and a working mental model of references.
Classes and objectsLink to this section
A subsystem is a class. Its fields hold hardware references and state; its methods expose intent to the rest of the robot.
public class Intake {
private final DcMotor motor;
private static final double COLLECT_POWER = 0.85;
public Intake(HardwareMap hardwareMap) {
motor = hardwareMap.get(DcMotor.class, "intake");
motor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
}
public void collect() { motor.setPower(COLLECT_POWER); }
public void eject() { motor.setPower(-COLLECT_POWER); }
public void stop() { motor.setPower(0); }
}Types you will use constantlyLink to this section
| Type | Use | Note |
|---|---|---|
| double | Motor power, angles, distances | Default for all math |
| int | Encoder ticks, counters | Ticks are integers, never floats |
| boolean | Sensor states, toggles | Debounce gamepad reads |
| enum | Robot states | Far safer than magic ints |
Enums for state machinesLink to this section
private enum LiftState { IDLE, RAISING, HOLDING, LOWERING }
private LiftState state = LiftState.IDLE;