Skip to content

Using Built-In Attachments

Volt has several built-in Attachments that can be used to quickly add functionality to your Robots.

These Attachments include:

  1. DcMotorAttachment: Controls a single DcMotor
  2. ServoAttachment: Controls a single Servo
  3. CRServoAttachment: Controls a single CRServo
  4. CRServoWithPotentiometerAttachment: Controls a CRServo with an AnalogInput measuring its angular displacement

There are two main ways to use a built-in attachment:

  1. As-is: Relies on existing Actions
  2. 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) }
}

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
}

The simplest built-in attachments control a single hardware actuator. These types of Attachments are very common.

  1. name: String: The name of the DcMotorAttachment
  2. motor: DcMotor: The motor to control
  3. maxPosition: Int: The maximum position of the motor in encoder ticks
  4. minPosition: Int: The minimum position of the motor in encoder ticks
  5. direction: DcMotorSimple.Direction: The direction the motor should spin
  • currentGoal: Int: The position of the current goal in encoder ticks
  • reset(): Resets the motor’s encoder
  • goTo(power: Double, position: Int): Moves the motor to the specified position in encoder ticks at the specified power

Logs the current goal, current position, and whether the motor is running. Example output:

Goal 0
Position 0
Busy false
  1. name: String: The name of the ServoAttachment
  2. servo: Servo: The servo to control
  3. direction: Servo.Direction: The direction the servo should spin
  • position: ServoPosition: The position of the servo
  • goTo(target: ServoPosition): Moves the servo to the specified target servo position

Logs the current position of the servo. Example output:

Position 0.0
  1. name: String: The name of the CRServoAttachment
  2. crServo: CRServo: The cr servo to control
  3. direction: DcMotorSimple.Direction: The direction the cr servo should spin

None

  • moveFor(power: Power, seconds: Seconds): Moves the cr servo for the specified number of seconds at the specified power
  • start(power: Power): Starts the cr servo at the specified power

Logs the current power being applied to the cr servo. Example output:

Power 0.0