ChoiceMenu

Overview

ChoiceMenu is a pre-match configuration system for OpModes. It manages a sequence of interactive prompts displayed on the Driver Hub, enabling teams to quickly and easily configure parameters such as alliance, and strategy, etc. using gamepad inputs.

This is especially useful for autonomous programs. A fully integrated ChoiceMenu is included in AutoOpMode .


Usage

Setup

To use ChoiceMenu, simply instantiate it with an OpMode instance and gamepads:

ChoiceMenu menu = new ChoiceMenu(this, gamepad1, gamepad2);

Enqueuing Prompts

Prompts are added to the menu using enqueuePrompt(String, Prompt<T>).

menu.enqueuePrompt("alliance", new OptionPrompt<>("Select Alliance", Alliance.RED, Alliance.BLUE));
menu.enqueuePrompt("delay", new ValuePrompt("Start Delay", 0.0, 10.0, 0.0, 1.0));
menu.enqueuePrompt("enablePark", new BooleanPrompt("Enable Park?", true));

Each prompt is tied to a key so you can retrieve the result later:

Alliance alliance = menu.get("alliance");
double delaySeconds = menu.get("delay");
boolean shouldPark = menu.get("enablePark");

Conditional Prompts

You can conditionally add prompts using a Supplier<Prompt<T>>. This lets you decide whether to show a prompt based on earlier choices.

menu.enqueuePrompt("parkLocation", () -> {
    if (menu.get("enableParking") == true) {
        return new OptionPrompt<>("Select Park Location", 1, 2);
    }
    return null; // Skips if the driver chose not to park
});

You can retrieve the result using getOrDefault(string, T). If there is no selection for the prompt, it will return the provided default value.

int parkLocation = menu.getOrDefault("enablePark", 0);

Running the Menu

To begin the menu, call run(). This will block execution until all prompts are completed.

menu.run();

Example Usage:

public void init() {
    // Initialize subsystems...
    
    menu.enqueuePrompt("alliance", new OptionPrompt<>("Select Alliance", Alliance.RED, Alliance.BLUE));
    menu.enqueuePrompt("delay", new ValuePrompt("Start Delay", 0.0, 10.0, 0.0, 1.0));
    menu.enqueuePrompt("enablePark", new BooleanPrompt("Enable Park?", true));
    menu.enqueuePrompt("parkLocation", () -> {
        if (menu.get("enableParking") == true) {
            return new OptionPrompt<>("Select Park Location", 1, 2);
        }
        return null; // Skips if the driver chose not to park
    });
    
    choiceMenu.run(); // Blocks until done
    
    Alliance alliance = menu.get("alliance");
    double delay = menu.get("delay");
    boolean enablePark = menu.get("enablePark");
    int parkLocation = menu.getOrDefault("parkLocation", 0);
    
    telemetry.addData("Selected Alliance", alliance);
    telemetry.addData("Selected Delay", delay);
    telemetry.addData("Is Parking?", enablePark);
    telemetry.addData("Selected Park Location", parkLocation);
}

Controls

  • D-PAD: Navigate the prompt

  • A: Confirm the current selection

  • B: Go back to the previous prompt

Last updated