FTCLib Commands

FTCLib Commands #

FTCLib has a commands system that is similar to Road Runner actions.

Here’s a generic FTCLib command for wrapping actions.

public class ActionCommand implements Command {
    private final Action action;
    private final Set<Subsystem> requirements;
    private boolean finished = false;

    public ActionCommand(Action action, Set<Subsystem> requirements) {
        this.action = action;
        this.requirements = requirements;
    }

    @Override
    public Set<Subsystem> getRequirements() {
        return requirements;
    }

    @Override
    public void execute() {
        TelemetryPacket packet = new TelemetryPacket();
        action.preview(packet.fieldOverlay());
        finished = !action.run(packet);
        FtcDashboard.getInstance().sendTelemetryPacket(packet);
    }

    @Override
    public boolean isFinished() {
        return finished;
    }
}

This pretty much works with some caveats.

  • Actions have no concept of requirements, so they need to be given for each command.
  • Actions do not know when they’re interrupted, while commands have a chance to do some final cleanup. Of course, a custom command wrapping one particular action (e.g., following a trajectory) may specifically override end() to perform some work (e.g., stopping drive motors).
  • Commands don’t have a mechanism analogous to preview(). This means the quickstart trajectory preview will only work for the currently executing command (of course you can bundle several actions together into one composite action and wrap that).