Multi-Variant Autonomous Modes
In FTC your autonomous flow often needs to adapt based on alliance or starting position, this is where multi-variant AutonomousModes come in.
Currently Volt comes with three types of multi-variant AutonomousModes:
DualAutonomousMode: Creates two variants, one for red and one for blue allianceMultiAutonomousMode: Creates one variant for every type defined in an enum classMultiDualAutonomousMode: Creates two variants for every type defined in an enum class, one for red and one for blue alliance
DualAutonomousMode
Section titled “DualAutonomousMode”Use DualAutonomousMode when your AutonomousMode needs to do different things when you are on blue alliance vs red alliance.
The color property references the selected AllianceColor.
DualAutonomousMode also provides helper methods:
<T> forAlliance(red: T, blue: T): T: Returnsredif the selected alliance isREDorblueif the selected alliance isBLUE.
Example
Section titled “Example”class Park : DualAutonomousMode<Robot>() { override val robot = Robot(hardwareMap)
init { blackboard["allianceColor"] = color // Save color to the blackboard }}public class Park extends DualAutonomousMode<Robot> { private final @NotNull Robot robot = new Robot(getHardwareMap());
@Override protected @NotNull Robot getRobot() { return robot; }
public Park() { blackboard.put("allianceColor", getColor()); // Save color to the blackboard }}MultiAutonomousMode
Section titled “MultiAutonomousMode”Use MultiAutonomousMode to create as many variants for your AutonomousMode as you want. Examples include multiple starting positions, launch positions, speeds, etc.
The variant property references the selected variant. The type of variant, E, is provided via a type parameter.
Example
Section titled “Example”enum class StartingPosition { LEFT, RIGHT,}
class Park : MultiAutonomousMode<DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain>>, StartingPosition>() { override val robot = DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain>( hardwareMap, MecanumDriveWithPP( hardwareMap, PinpointConfig { }, MecanumConfig { }, Foresight(ForesightConfig { }), PoseFactory.degrees() ), )
private val START_LEFT = robot.drivetrain.poseFactory.of(12.0, 60.0, 270.0) private val START_RIGHT = robot.drivetrain.poseFactory.of(12.0, 66.0, 270.0)
// Get initial pose private val initialPose = if (variant == StartingPosition.LEFT) START_LEFT else START_RIGHT
private val endPose = robot.drivetrain.poseFactory.of(12.0, 36.0, 270.0)
private val path = line(initialPose, endPose).linear(startPose, endPose)
init { Start then { +robot.drivetrain.followPath(path) } }}public class Park extends MultiAutonomousMode<DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain>, StartingPosition> { enum StartingPosition { LEFT, RIGHT }
private final @NotNull DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain> robot = new DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain>( getHardwareMap(), new PinpointMecanumPedroPathingDrivetrain( getHardwareMap(), new PinpointConfig(c -> { }), new MecanumConfig(c -> { }), new Foresight(new ForesightConfig(c -> { })), PoseFactory.degrees() ) );
@Override protected @NotNull DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain>> getRobot() { return robot; }
private PoseFactory poseFactory = getRobot().getDrivetrain().getPoseFactory();
private Pose START_LEFT = poseFactory.of(12.0, 60.0, 270.0); private Pose START_RIGHT = poseFactory.of(12.0, 66.0, 270.0);
// Get initial Pose private Pose getInitialPose() { if (getVariant().equals(StartingPosition.LEFT)) { return START_LEFT; } else { return START_RIGHT; } };
private Pose endPose = poseFactory.of(12.0, 36.0, 270.0);
private Path path = Paths.line(getInitialPose(), endPose).linear(getInitialPose(), endPose);
public Park() { then(Start.INSTANCE, (builder, param) -> { builder.unaryPlus(getRobot().getDrivetrain().followPath(path)); return Unit.INSTANCE; }); }}MultiDualAutonomousMode
Section titled “MultiDualAutonomousMode”MultiDualAutonomousMode combines DualAutonomousMode and MultiAutonomousMode, use it when you want alliance color variants for each of your MultiAutonomousMode variants.
MultiDualAutonomousMode extends DualAutonomousMode, adding the variant property from MultiAutonomousMode.
Example
Section titled “Example”enum class StartingPosition { LEFT, RIGHT,}
class Park : MultiDualAutonomousMode<DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain>>, StartingPosition>() { override val robot = DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain>( hardwareMap, MecanumDriveWithPP( hardwareMap, PinpointConfig { }, MecanumConfig { }, Foresight(ForesightConfig { }), PoseFactory.degrees() ), )
private val START_LEFT = robot.drivetrain.poseFactory.of(12.0, 60.0, 270.0) private val START_RIGHT = robot.drivetrain.poseFactory.of(12.0, 66.0, 270.0)
// Get initial pose private val initialPose = if (variant == StartingPosition.LEFT) START_LEFT else START_RIGHT
private val endPose = robot.drivetrain.poseFactory.of(12.0, 36.0, 270.0)
private val path = line(initialPose, endPose).linear(startPose, endPose)
init { blackboard["allianceColor"] = color // Save color to the blackboard
Start then { +robot.drivetrain.followPath(path) } }}public class Park extends MultiDualAutonomousMode<DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain>>, StartingPosition> { enum StartingPosition { LEFT, RIGHT }
private final @NotNull DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain> robot = new DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain>( getHardwareMap(), new PinpointMecanumPedroPathingDrivetrain( getHardwareMap(), new PinpointConfig(c -> { }), new MecanumConfig(c -> { }), new Foresight(new ForesightConfig(c -> { })), PoseFactory.degrees() ) );
@Override protected @NotNull DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain>> getRobot() { return robot; }
private PoseFactory poseFactory = getRobot().getDrivetrain().getPoseFactory();
private Pose START_LEFT = poseFactory.of(12.0, 60.0, 270.0); private Pose START_RIGHT = poseFactory.of(12.0, 66.0, 270.0);
// Get initial Pose private Pose getInitialPose() { if (getVariant().equals(StartingPosition.LEFT)) { return START_LEFT; } else { return START_RIGHT; } };
private Pose endPose = poseFactory.of(12.0, 36.0, 270.0);
private Path path = Paths.line(getInitialPose(), endPose).linear(getInitialPose(), endPose);
public Park() { blackboard.put("allianceColor", getColor()); // Save color to the blackboard
then(Start.INSTANCE, (builder, param) -> { builder.unaryPlus(getRobot().getDrivetrain().followPath(path)); return Unit.INSTANCE; }); }}Next Steps
Section titled “Next Steps”- Create a ManualMode to control you Robot with gamepads
- Learn more about Events
- Learn more about the VoltActionBuilder