Using Built-In Attachments
Volt has several built-in Attachments that can be used to quickly add functionality to your Robots.
These Attachments include:
DcMotorAttachment: Controls a singleDcMotorServoAttachment: Controls a singleServoCRServoAttachment: Controls a singleCRServoCRServoWithPotentiometerAttachment: Controls aCRServowith anAnalogInputmeasuring its angular displacement
Using Built-In Attachments
Section titled “Using Built-In Attachments”There are two main ways to use a built-in attachment:
- As-is: Relies on existing Actions
- Extended: Extends the existing implementation
To use a built-in Attachment as-is, simply create a new instance of the Attachment in your Robot class:
class MyRobot(hardwareMap: HardwareMap) : Robot(hardwareMap) { private val clawServo by servo("clawServo")
val claw = attachment { ServoAttachment("Claw", clawServo) }}public class MyRobot extends Robot { private final Servo clawServo; public final ServoAttachment claw;
public MyRobot(HardwareMap hardwareMap) { super(hardwareMap); clawServo = hardwareMap.get(Servo.class, "clawServo"); claw = attachment(() -> { return new ServoAttachment( "Claw", clawServo ); }); }}Extended
Section titled “Extended”To extend a built-in Attachment, create a new class that inherits the Attachment:
class Claw(servo: Servo) : ServoAttachment("Claw", servo) { // Custom functionality can be added here}public class Claw extends ServoAttachment { public Claw(Servo servo) { super("Claw", servo); }
// Custom functionality can be added here}Simple Built-in Attachments Reference
Section titled “Simple Built-in Attachments Reference”The simplest built-in attachments control a single hardware actuator. These types of Attachments are very common.
DcMotorAttachment
Section titled “DcMotorAttachment”Constructor Parameters
Section titled “Constructor Parameters”name: String: The name of theDcMotorAttachmentmotor: DcMotor: The motor to controlmaxPosition: Int: The maximum position of the motor in encoder ticksminPosition: Int: The minimum position of the motor in encoder ticksdirection: DcMotorSimple.Direction: The direction the motor should spin
Properties
Section titled “Properties”currentGoal: Int: The position of the current goal in encoder ticks
Actions
Section titled “Actions”reset(): Resets the motor’s encodergoTo(power: Double, position: Int): Moves the motor to the specifiedpositionin encoder ticks at the specifiedpower
Telemetry
Section titled “Telemetry”Logs the current goal, current position, and whether the motor is running. Example output:
Goal 0Position 0Busy falseServoAttachment
Section titled “ServoAttachment”Constructor Parameters
Section titled “Constructor Parameters”name: String: The name of theServoAttachmentservo: Servo: The servo to controldirection: Servo.Direction: The direction the servo should spin
Properties
Section titled “Properties”position: ServoPosition: The position of the servo
Actions
Section titled “Actions”goTo(target: ServoPosition): Moves the servo to the specifiedtargetservo position
Telemetry
Section titled “Telemetry”Logs the current position of the servo. Example output:
Position 0.0CRServoAttachment
Section titled “CRServoAttachment”Constructor Parameters
Section titled “Constructor Parameters”name: String: The name of theCRServoAttachmentcrServo: CRServo: The cr servo to controldirection: DcMotorSimple.Direction: The direction the cr servo should spin
Properties
Section titled “Properties”None
Actions
Section titled “Actions”moveFor(power: Power, seconds: Seconds): Moves the cr servo for the specified number ofsecondsat the specifiedpowerstart(power: Power): Starts the cr servo at the specifiedpower
Telemetry
Section titled “Telemetry”Logs the current power being applied to the cr servo. Example output:
Power 0.0