Skip to content

Custom EndConditions

Johan Vandegriff edited this page Oct 27, 2016 · 1 revision

To create your own EndConditions, all you have to do is make a class that extends EndConditions.

public class EVEndConditions extends EndConditions {

}

And add some methods to it, for example a gyro end condition.

public class EVEndConditions extends EndConditions {

    public static EndCondition gyroCloseTo(final GyroSensor gyro, double targetDegrees, final double toleranceDegrees){
        final Vector3D targetVector = Vector3D.fromPolar2D(1, Angle.fromDegrees(targetDegrees));
        return new EndCondition() {
            @Override
            public void init() {}

            @Override
            public boolean isDone() {
                Vector3D gyroVector = Vector3D.fromPolar2D(1, Angle.fromDegrees(gyro.getHeading()));
                Angle separation = Vector3D.signedAngularSeparation(targetVector, gyroVector);
                return Math.abs(separation.getValueDegrees()) <= toleranceDegrees;
            }
        };
    }

}

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