Skip to content

Motor Commands

NextFTC has a bunch of motor commands so that you don't have to write your own!

RunToPosition

RunToPosition is likely the most common motor command you will use. It takes a Controllable (like a MotorEx or a MotorGroup), a Controller, and a target. It finishes once the motor is in a tolerable distance of the target.

kotlin
RunToPosition(motor, target, controller, setOf(subsystems))

// or in a subsystem:
RunToPosition(motor, target, controller, this)

The tolerance of the controller can be set with controller.setPointTolerance as follows:

kotlin
controller.setPointTolerance(20.0) // default is 10

HoldPosition

HoldPosition holds a motor at the position it was at when the command was scheduled.

kotlin
HoldPosition(motor, controller, setOf(subsystems))

It is mostly commonly used as the default command in a subsystem, which means it will run when no other command is being run.

kotlin
override val defaultCommand: Command
        get() = HoldPosition(motor, controller, this)

SetPower

SetPower is very simple: it sets the power and ends instantly.

kotlin
SetPower(motor, power, setOf(subsystems))

// or in a subsystem:
SetPower(motor, power, this)

RunToVelocity

RunToVelocity uses a controller on a motor until it reaches a set velocity and then depowers the motor.

kotlin
RunToVelocity(motor, velocity, controller, setOf(subsystems))

// or in a subsystem:
RunToVelocity(motor, velocity, controller, this)

Optionally, you can pass the condition when it ends as well.

kotlin
RunToVelocity(
    motor,
    velocity,
    controller,
    setOf(subsystems),
    { abs(motor.velocity) - velocity < 10 } // this is the default
)

HoldVelocity

HoldVelocity is like a combination of RunToVelocity and HoldPosition: it keeps a motor at the velocity it was at when the command was scheduled.

kotlin
HoldVelocity(motor, controller, setOf(subsystems))

Like HoldPosition, HoldVelocity is most commonly used as the default command in a subsystem. This is useful for something like a flywheel. You can have RunToVelocity commands that bring it to a velocity (spinning or stopped), and the HoldVelocity command will run when those stop to keep it at that velocity.

kotlin
override val defaultCommand: Command
        get() = HoldVelocity(motor, controller, this)

ResetEncoder

ResetEncoder does exactly what it sounds like: it resets the encoder.

kotlin
ResetEncoder(motor, setOf(subsystems))

// or in a subsystem:
ResetEncoder(motor, this)

NOTE

See the controllables reference for more information.