Skip to content

Linear Slides Example

Linear slides are a commonly used mechanism in FTC, and most often controlled with a positional PID feedback controller and a constant feedforward term to account for gravity.

With NextControl, that would be implemented like this (using hypothetical constants):

kotlin
controlSystem {
    posPid(0.1, 0.0, 0.0)
    elevatorFF(0.04)
}

What can I do with this?

If you're using a command-based framework, like NextFTC, you can create commands using your control system. An example of a Linear Slides subsystem using NextControl can be found here.

If not, we can create OpModes that use our controllers directly. For example, let's say we wanted to change the target of our slides using a button press. We can easily do that by simply changing the goal of our ControlSystem:

kotlin
class SlideExample() : OpMode() {
    val slideMotor by lazy { hardwareMap.get(DcMotorEx.class, "slides") }
    val controller = controlSystem {
        posPid(0.1, 0.0, 0.0)
        elevatorFF(0.04)
    }

    override fun init() {
        controller.goal = KineticState(0.0)
    }

    override fun loop() {
        if (gamepad1.a) {
            controller.goal = KineticState(1000.0)
        } else if (gamepad1.b) {
            controller.goal = KineticState(0.0)
        } else if (gamepad1.x) {
            controller.goal = KineticState(500.0)
        }

        slideMotor.power = controller.calculate(
            slideMotor.currentPosition,
            slideMotor.velocity
        )
    }
}