Skip to content

Creating your first Robot

Rapidly develop and test new robots with the Volt library.

What is a Robot?

A Robot is a class that contains all Attachments, sensors, and shared Actions that make up a robot.

You should create a new Robot class for each physical robot you’ve built.

Creating a Robot

Create a new kotlin class in TeamCode/src/main/kotlin/org/firstinspires/ftc/teamcode/robot that inherits the Robot class.

The Robot class contains:

  1. A list of attachments
  2. A function called update(telemetry: Telemetry) that is called every tick
class Example : Robot() {
init {
// Initialize
}
}

Add Sensors

Define the sensors that your robot will use and a way to access them. For example, add a HuskyLens sensor to your robot.

class Example : Robot() {
// Sensors
private val huskyLens: HuskyLens = hardwareMap.get(HuskyLens::class.java, "lens")
init {
// Set huskylens mode
huskyLens.selectAlgorithm(HuskyLens.Algorithm.OBJECT_RECOGNITION)
}
fun getDetectedObjects(telemetry: Telemetry): Array<out HuskyLens.Block>? {
// Get objects
val blocks = huskyLens.blocks()
telemetry.addData("Block count", blocks.size)
for (block in blocks) {
telemetry.addData("Block", block.toString())
}
return blocks
}
}

Add Attachments

Define the Attachments that your robot will use. For example, add a SimpleAttachmentWithDcMotor to your Robot.

class Example : Robot() {
// Sensors
private val huskyLens: HuskyLens = hardwareMap.get(HuskyLens::class.java, "lens")
// Attachments
val exampleAttachment: SimpleAttachmentWithDcMotor = SimpleAttachmentWithDcMotor(hardwareMap, "motor", 0.5, 1000)
init {
attachments = listOf(exampleAttachment)
// Set huskylens mode
huskyLens.selectAlgorithm(HuskyLens.Algorithm.OBJECT_RECOGNITION)
}
fun getDetectedObjects(telemetry: Telemetry): Array<out HuskyLens.Block>? {
// Get objects
val blocks = huskyLens.blocks()
telemetry.addData("Block count", blocks.size)
for (block in blocks) {
telemetry.addData("Block", block.toString())
}
return blocks
}
}

Add Actions

Define Actions for your Attachments and sensors. For example, add a function to move a motor to a specific position.

class Example : Robot() {
// Sensors
private val huskyLens: HuskyLens = hardwareMap.get(HuskyLens::class.java, "lens")
// Attachments
val exampleAttachment: SimpleAttachmentWithDcMotor = SimpleAttachmentWithDcMotor(hardwareMap, "motor", 0.5, 1000)
init {
attachments = listOf(exampleAttachment)
// Set huskylens mode
huskyLens.selectAlgorithm(HuskyLens.Algorithm.OBJECT_RECOGNITION)
}
fun moveMotorToSpecificPosition(): Action {
// Move motor to 1000 at 50% power
return exampleAttachment.goTo(0.5, 1000)
}
fun getDetectedObjects(telemetry: Telemetry): Array<out HuskyLens.Block>? {
// Get objects
val blocks = huskyLens.blocks()
telemetry.addData("Block count", blocks.size)
for (block in blocks) {
telemetry.addData("Block", block.toString())
}
return blocks
}
}

Result

package org.firstinspires.ftc.teamcode.robot
import com.acmerobotics.roadrunner.Action
import com.acmerobotics.roadrunner.Pose2d
import dev.kingssack.volt.attachment.SimpleAttachmentWithDcMotor
import dev.kingssack.volt.robot.Robot
import com.qualcomm.hardware.dfrobot.HuskyLens
import com.qualcomm.robotcore.hardware.HardwareMap
import org.firstinspires.ftc.robotcore.external.Telemetry
class Example : Robot() {
private val huskyLens: HuskyLens = hardwareMap.get(HuskyLens::class.java, "lens")
val exampleAttachment: SimpleAttachmentWithDcMotor = SimpleAttachmentWithDcMotor(hardwareMap, "motor", 0.5, 1000)
init {
attachments = listOf(exampleAttachment)
huskyLens.selectAlgorithm(HuskyLens.Algorithm.OBJECT_RECOGNITION)
}
fun moveMotorToSpecificPosition(): Action {
return exampleAttachment.goTo(0.5, 1000)
}
fun getDetectedObjects(telemetry: Telemetry): Array<out HuskyLens.Block>? {
val blocks = huskyLens.blocks()
telemetry.addData("Block count", blocks.size)
for (block in blocks) {
telemetry.addData("Block", block.toString())
}
return blocks
}
}