Enums, Lists, and Team Vocabulary
Use enums and collections to express robot states and groups of devices.
Use enums and collections to express robot states and groups of devices.
In this lesson, you will:
Enums give a fixed set of names to robot states. Lists let the team apply one rule to a group, like setting brake mode on every drive motor. Together they reduce magic values and duplicated setup code.
Students should see an enum as team vocabulary. DOWN, INTAKE, SCORE, and SAFE are easier to discuss than 0.17, 0.42, and some boolean called ready. A list is a way to say all these motors share a setup rule.
Start with a servo position enum, then use a method to move to that state. Next, create a list of motors and apply zero-power behavior in one loop. Keep raw numbers near the enum, not scattered through TeleOp.
EnumsListsandTeamVocabulary.javaJava
enum ClawState {
OPEN(0.35),
CLOSED(0.08);
final double position;
ClawState(double position) { this.position = position; }
}
void updateClaw(ClawState state) {
clawServo.setPosition(state.position);
telemetry.addData("claw state", state);
}Enums fail when the names are vague or when raw numbers are still used elsewhere. Lists fail when one device needs different behavior but is silently included. Review group setup carefully.
Define a two- or three-state enum for one mechanism and replace direct position writes in TeleOp with updateState calls.
Check your understanding before moving on.
0 of 2 answered