Skip to content

Custom StateMachineBuilder

Johan Vandegriff edited this page Dec 16, 2016 · 4 revisions

Make a class that extends StateMachineBuilder and calls the superconstructor.

public class MyStateMachineBuilder extends StateMachineBuilder {
    public MyStateMachineBuilder(StateName firstStateName) {
        super(firstStateName);
    }
}

Then add a convenience method to it that uses your method you made in MyStates.

public class MyStateMachineBuilder extends StateMachineBuilder {
    public MyStateMachineBuilder(StateName firstStateName) {
        super(firstStateName);
    }
    
    public void addCalibrateGyro(StateName stateName, GyroSensor gyro, StateName nextStateName){
        add(stateName, MyStates.calibrateGyro(gyro, nextStateName));
    }
    
    public void addTelem(StateName stateName, String message, double value, Map<StateName, EndCondition> transitions) {
        add(stateName, EVStates.telemetry(transitions, message, value));
    }
}

You can even pass in objects in the constructor to be used multiple times, such as the gyro sensor or telemetry.

public class MyStateMachineBuilder extends StateMachineBuilder {
    private final Telemetry telemetry;
    
    public MyStateMachineBuilder(StateName firstStateName, Telemetry telemetry) {
        super(firstStateName);
        this.telemetry = telemetry;
    }
    
    public void addCalibrateGyro(StateName stateName, GyroSensor gyro, StateName nextStateName){
        add(stateName, MyStates.calibrateGyro(gyro, nextStateName));
    }
    
    public void addTelem(StateName stateName, String message, double value, Map<StateName, EndCondition> transitions) {
        add(stateName, EVStates.telemetry(transitions, message, value));
    }
}

The next step is to create Custom EndConditions.

Home | Features

This guide will walk you through the basics of creating state machines using the state-machine-framework.

  1. Importing Into Your Project
  2. The State Interface
  3. Simple State Machine
  4. Custom States
  5. Custom StateMachineBuilder
  6. Custom EndConditions

Clone this wiki locally