Skip to content

Drive Util

NextFTC v2 provides functions to drive mecanum and tank drivetrains from a gamepad, so you don’t have to write the math yourself.

Register your motors on a Drivetrain mechanism

Section titled “Register your motors on a Drivetrain mechanism”
class Drivetrain : Mechanism {
val frontLeft = NextMotor(//...)
val frontRight = NextMotor(//...)
val backLeft = NextMotor(//...)
val backRight = NextMotor(//...)
}

Register it on your NextRobot’s getMechanisms() set, just like any other mechanism.

In your Robot class, add a startDrive method like this:

Section titled “In your Robot class, add a startDrive method like this:”
fun startDrive(gamepad1: Gamepad) {
mecanumDrive(
drivetrain.frontLeft,
drivetrain.frontRight,
drivetrain.backLeft,
drivetrain.backRight,
gamepad1,
)()
}

For a tank drivetrain, swap in tankDrive

Call this once, in your TeleOp’s constructor and your set!

robot.startDrive(gamepad1)

mecanumDriveFieldCentric rotates stick input by the robot’s current heading, so “forward” on the stick always moves the robot away from the driver.

mecanumDriveFieldCentric(
drivetrain.frontLeft,
drivetrain.frontRight,
drivetrain.backLeft,
drivetrain.backRight,
gamepad1,
{ //insert heading},
)()

Multiplies your gamepad inputs by a scalar to support different speed modes or sensitivities.

scalar = 0.5 // makes it half speed

A common way to use Scalar is a slow mode:

gp1.leftBumper().whileTrue(Commands.infinite { scalar = 0.4 })