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:
- A list of attachments
- A function called
update(telemetry: Telemetry)
that is called every tick
class Example : Robot() { init { // Initialize }}
(Coming Soon)
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 }}
(Coming Soon)
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 }}
(Coming Soon)
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 }}
(Coming Soon)
Result
package org.firstinspires.ftc.teamcode.robot
import com.acmerobotics.roadrunner.Actionimport com.acmerobotics.roadrunner.Pose2dimport dev.kingssack.volt.attachment.SimpleAttachmentWithDcMotorimport dev.kingssack.volt.robot.Robotimport com.qualcomm.hardware.dfrobot.HuskyLensimport com.qualcomm.robotcore.hardware.HardwareMapimport 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 }}
(Coming Soon)