Skip to content

Creating your first Autonomous Mode

An AutonomousMode is a VoltOpMode that allows you to perform Actions autonomously.

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)
}

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.AutonomousMode
import 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()
}
}
}
}
}

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.VoltOpModeMeta
import dev.kingssack.volt.opmode.autonomous.AutonomousMode
import 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
@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()
}
}
}
}
}