Creating your first Autonomous Mode
An AutonomousMode is a VoltOpMode that allows you to perform Actions autonomously.
1. Create Your AutonomousMode Class
Section titled “1. Create Your AutonomousMode Class”First, create a new class that inherits AutonomousMode.
AutonomousMode takes a type parameter for your Robot class. It uses that type for the abstract robot property.
Override the robot property with an instance of your Robot class. You can use properties defined in VoltOpMode like hardwareMap to create your Robot instance.
import dev.kingssack.volt.opmode.autonomous.AutonomousMode
class ExampleAuto : AutonomousMode<MyRobot>() { override val robot = MyRobot(hardwareMap)}import dev.kingssack.volt.opmode.autonomous.AutonomousMode;
public class ExampleAuto extends AutonomousMode<MyRobot> { @NotNull MyRobot robot = new MyRobot(getHardwareMap());
@Override protected @NotNull MyRobot getRobot() { return robot; }
public ExampleAuto() { super(); }}2. Define an Event
Section titled “2. Define an Event”By default AutonomousModes only have one event: Start, which is triggered when the play button is pressed on the Driver Station.
Events are defined with the then function, which takes an event and a lambda with a VoltActionBuilder as the receiver.
On Start, we’ll open the claw, then close the claw and score at the same time. We’ll repeat this sequence three times:
import dev.kingssack.volt.opmode.autonomous.AutonomousModeimport dev.kingssack.volt.util.Event.AutonomousEvent.Start
class ExampleAuto : AutonomousMode<MyRobot>() { override val robot = MyRobot(hardwareMap)
init { Start then { repeat(3) { +robot.claw.open() // Add an action to the sequence
parallel { // Run these actions at the same time +robot.claw.close() +robot.score() } } } }}import dev.kingssack.volt.opmode.autonomous.AutonomousMode;import dev.kingssack.volt.util.Event.AutonomousEvent.Start;import kotlin.Unit;
public class ExampleAuto extends AutonomousMode<MyRobot> { @NotNull MyRobot robot = new MyRobot(getHardwareMap());
@Override protected @NotNull MyRobot getRobot() { return robot; }
public ExampleAuto() { super();
then(Start.INSTANCE, builder -> { for (int i = 0; i < 3; i++) { builder.unaryPlus(robot.getClaw().open()); // Add an action to the sequence
builder.parallel(() -> { // Run these actions at the same time builder.unaryPlus(robot.getClaw().close()); builder.unaryPlus(robot.score()); }); } return Unit.INSTANCE; }); }}3. Add Metadata
Section titled “3. Add Metadata”Add the @VoltOpModeMeta annotation to the class definition. Without this annotation, the OpMode will not be registered and will not appear on the Driver Station.
import dev.kingssack.volt.opmode.VoltOpModeMetaimport dev.kingssack.volt.opmode.autonomous.AutonomousModeimport dev.kingssack.volt.util.Event.AutonomousEvent.Start
@VoltOpModeMeta("Example Auto", "Examples")class ExampleAuto : AutonomousMode<MyRobot>() { override val robot = MyRobot(hardwareMap)
init { Start then { repeat(3) { +robot.claw.open()
parallel { +robot.claw.close() +robot.score() } } } }}import dev.kingssack.volt.opmode.VoltOpModeMeta;import dev.kingssack.volt.opmode.autonomous.AutonomousMode;import dev.kingssack.volt.util.Event.AutonomousEvent.Start;import kotlin.Unit;
@VoltOpModeMeta("Example Auto", "Examples")public class ExampleAuto extends AutonomousMode<MyRobot> { @NotNull MyRobot robot = new MyRobot(getHardwareMap());
@Override protected @NotNull MyRobot getRobot() { return robot; }
public ExampleAuto() { super();
then(Start.INSTANCE, builder -> { for (int i = 0; i < 3; i++) { builder.unaryPlus(robot.getClaw().open());
builder.parallel(() -> { builder.unaryPlus(robot.getClaw().close()); builder.unaryPlus(robot.score()); }); } return Unit.INSTANCE; }); }}Result
Section titled “Result”package org.firstinspires.ftc.teamcode.opmodes.autonomous
import dev.kingssack.volt.opmode.VoltOpModeMetaimport dev.kingssack.volt.opmode.autonomous.AutonomousModeimport dev.kingssack.volt.util.Event.AutonomousEvent.Start
@VoltOpModeMeta("Example Auto", "Examples")class ExampleAuto : AutonomousMode<MyRobot>() { override val robot = MyRobot(hardwareMap)
init { Start then { repeat(3) { +robot.claw.open()
parallel { +robot.claw.close() +robot.score() } } } }}package org.firstinspires.ftc.teamcode.opmodes.autonomous;
import dev.kingssack.volt.opmode.VoltOpModeMeta;import dev.kingssack.volt.opmode.autonomous.AutonomousMode;import dev.kingssack.volt.util.Event.AutonomousEvent.Start;import kotlin.Unit;
@VoltOpModeMeta("Example Auto", "Examples")public class ExampleAuto extends AutonomousMode<MyRobot> { @NotNull MyRobot robot = new MyRobot(getHardwareMap());
@Override protected @NotNull MyRobot getRobot() { return robot; }
public ExampleAuto() { super();
then(Start.INSTANCE, builder -> { for (int i = 0; i < 3; i++) { builder.unaryPlus(robot.getClaw().open());
builder.parallel(() -> { builder.unaryPlus(robot.getClaw().close()); builder.unaryPlus(robot.score()); }); } return Unit.INSTANCE; }); }}Next Steps
Section titled “Next Steps”- Learn about multi-variant Autonomous Modes
- Create a ManualMode to control you Robot with gamepads
- Learn more about Events
- Learn more about the VoltActionBuilder