Skip to content

Claw Subsystem

Another common subsystem in FTC is a claw. Generally, a claw is powered by one servo, generally with an open and a closed position.

This guide assumes you have already read the Lift Subsystem guide. Let's get started!

Step 1: Create your class

Just like with the Lift Subsystem, we need to start by creating our class.

kotlin
object Claw: Subsystem() {

}

Step 2: Create your servo

Now, since we're using a servo, instead of a motor, let's create a servo variable. Currently, there is no wrapper class for Servos, so you will be using the Qualcomm servo class.

Just like our motor variable from the lift subystem, it needs to be a lateinit variable:

kotlin
lateinit var servo: Servo

Just like our motors, we also need a name for our servo. This is the name specified in the hardwareMap. I called mine claw_servo:

kotlin
val name = "claw_servo"

Finally, we need to initialize our servo in the initialize() function. Because there is no wrapper class, you will need to access the hardwareMap yourself. NextFTC will automatically set the hardwareMap in each of your OpModes (as long as you extend NextFTCOpMode or PedroOpMode).

The easiest way to access the hardwareMap is by using OpModeData.hardwareMap:

kotlin
override fun initialize() {
    servo = OpModeData.hardwareMap.get(Servo::class.java, name)
}

To recap how you create servo-based Subsystems in NextFTC:

  • Create a variable to store your Servo instance
  • Create a variable to store the name
  • In initialize(), get the Servo instance from the hardwareMap using your name variable.

Step 3: Create commands

Programming servo commands is very easy in NextFTC.

TIP

It's recommended to create a variable to store each servo position. However, that takes up more space, so I won't be doing that here.

For servos, the command you will be using is ServoToPosition. You will pass your servo, a target position, and your subsystem (just like the lift).

Just like your lift, you will be creating properties that return instances of Commands:

kotlin
val open: Command
    get() = ServoToPosition(servo, // SERVO TO MOVE
        0.1, // POSITION TO MOVE TO
        this)  // IMPLEMENTED SUBSYSTEM

Nice! Let's do the same with the close command:

kotlin
val close: Command
    get() = ServoToPosition(servo, // SERVO TO MOVE
        0.2, // POSITION TO MOVE TO
        this) // IMPLEMENTED SUBSYSTEM

Final result

You've successfully created your claw subsystem! Here's the final result:

kotlin
object Claw: Subsystem() {
    lateinit var servo: Servo

    val name = "claw_servo"

    val open: Command
        get() = ServoToPosition(servo, // SERVO TO MOVE
            0.9, // POSITION TO MOVE TO
            this)  // IMPLEMENTED SUBSYSTEM

    val close: Command
        get() = ServoToPosition(servo, // SERVO TO MOVE
            0.2, // POSITION TO MOVE TO
            this) // IMPLEMENTED SUBSYSTEM

    override fun initialize() {
        servo = OpModeData.hardwareMap.get(Servo::class.java, name)
    }
}