Prompter

Overview

Prompter is a pre-match configuration tool that displays a sequence of interactive prompts as telemetry. This allows you to easily set parameters such as alliance color, starting position, and strategy using the gamepad—right before a match.

This eliminates the need for multiple OpModes with hardcoded settings, reducing clutter.


Usage

Setup

To create a Prompter, simply instantiate it with the current OpMode instance:

Prompter prompter = new Prompter(this);

Enqueuing Prompts

Prompts are added to the Prompter using prompt(String, Prompt<T>).

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

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

Alliance alliance = prompter.get("alliance");
double delaySeconds = prompter.get("delay");
boolean shouldPark = prompter.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.

prompter.prompt("parkLocation", () -> {
    if (prompter.get("enablePark") == true) {
        return new OptionPrompt<>("Select Park Location", 1, 2);
    }
    return null; // Skip 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 = prompter.getOrDefault("parkLocation", 0);

Running the Prompter

To start the Prompter, simply call run(). This will block execution until all prompts are completed.

prompter.run();

Controls

Use the following gamepad controls to navigate the prompt interface:

  • D-PAD: Navigate the prompt

  • A: Confirm the current selection

  • B: Go back to the previous prompt

Example Usage

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

What the Driver Sees

On init, the Prompter will display the following on the Driver Hub:

Select Alliance:

1) RED <
2) BLUE

Prompts will appear one at a time in this format until all selections have been made.

Last updated