Lesson 25: Advanced Joystick Management

As robots get more complex, joystick code can become messy. Advanced joystick management means turning raw buttons and axes into clear driver commands.

Name Your Controls

Raw button numbers are hard to read. Give important controls names.

public class Controls {
    public static final int INTAKE_BUTTON = 1;
    public static final int EJECT_BUTTON = 2;
    public static final int SHIFT_BUTTON = 5;
}

Now the code says what the button means instead of only where it is.

if (driver.getRawButton(Controls.INTAKE_BUTTON)) {
    intakeState = IntakeState.INTAKING;
}

Deadbands

Joystick axes are rarely exactly zero. A deadband ignores tiny values so the robot does not drift.

public double deadband(double value) {
    if (Math.abs(value) < 0.08) {
        return 0.0;
    }
    return value;
}

Toggle Buttons

Sometimes one button press should toggle a state. To do that, detect the moment the button changes from not pressed to pressed.

boolean lastShiftButton = false;
boolean highGear = false;

public void teleopPeriodic() {
    boolean shiftButton = driver.getRawButton(Controls.SHIFT_BUTTON);

    if (shiftButton && !lastShiftButton) {
        highGear = !highGear;
    }

    lastShiftButton = shiftButton;
}

Driver Versus Operator

Many teams use two controllers: one for driving and one for mechanisms. Keep their responsibilities clear. The driver should not need to remember every mechanism button while lining up a robot.

Practice

Create a controls map for a robot with drive, intake, shooter, and climber. Then mark which controls belong to the driver and which belong to the operator.