Skip to content

Using and Creating a Drivetrain

A Drivetrain is an Attachment that houses your Robot’s drive logic.

Volt currently provides one pre-built Drivetrain type: MecanumDrivetrain.

MecanumDrivetrain is an abstract Drivetrain class for four wheel mecanum drive robots. It has one method: setDrivePowers.

setDrivePowers takes a PoseVelocity2d that can be used to power each motor.

Implementations of MecanumDrivetrain are designed to work with RobotWithMecanumDrivetrain.

There are two pre-built implementations of MecanumDrivetrain:

  • MecanumDriveWithRR: A MecanumDrivetrain implementation using RoadRunner
  • MecanumDriveWithPP: A MecanumDrivetrain implementation using PedroPathing

MecanumDriveWithRR constructor parameters:

  • hardwareMap: HardwareMap: Used to get drive motors
  • pose: Pose2d: Used to set the Robot’s initial pose
  • params: MecanumDriveWithRR.DriveParams: Used to configure RoadRunner

MecanumDriveWithRR provides a trajectory builder that composes Actions using RoadRunner’s TrajectoryActionBuilder.

class ExampleRobot(
hardwareMap: HardwareMap
) : RobotWithMecanumDrivetrain<MecanumDriveWithRR>(
hardwareMap,
MecanumDriveWithRR(hardwareMap)
) {
fun driveForwardAction() = drivetrain.trajectory {
strafeTo(Vector2d(24.0, 0.0))
}
}

MecanumDriveWithPP constructor parameters:

  • hardwareMap: HardwareMap: Used to get drive motors
  • followerConstants: FollowerConstants: Used to configure PedroPathing’s path follower
  • localizerConstants: DriveEncoderConstants: Used to configure PedroPathing’s drive encoder localizer
  • pathConstraints: PathConstraints: Used to configure PedroPathing’s path following constraints
  • driveConstants: MecanumConstants: Used to configure PedroPathing’s mecanum drivetrain logic
  • initialPose: Pose: Used to set the Robot’s initial pose

MecanumDriveWithPP provides a path builder that composes Actions using a custom FollowerActionBuilder (built on PedroPathing’s path builder).

class ExampleRobot(
hardwareMap: HardwareMap
) : RobotWithMecanumDrivetrain<MecanumDriveWithPP>(
hardwareMap,
MecanumDriveWithPP(
hardwareMap,
FollowerConstants(),
DriveEncoderConstants(),
PathConstraints(),
MecanumConstants()
)
) {
fun driveAction() = drivetrain.path {
lineTo(Pose(24.0, 0.0, 0.0))
}
}

Building a custom Drivetrain class is just like building an Attachment:

  1. Extend Drivetrain (or MecanumDrivetrain)
  2. Configure hardware
  3. Write drive logic
class ExampleDrivetrain(hardwareMap: HardwareMap) : Drivetrain() {
val leftFront: DcMotorEx = hardwareMap.get(DcMotorEx::class.java, "lf")
val leftBack: DcMotorEx = hardwareMap.get(DcMotorEx::class.java, "lr")
val rightBack: DcMotorEx = hardwareMap.get(DcMotorEx::class.java, "rr")
val rightFront: DcMotorEx = hardwareMap.get(DcMotorEx::class.java, "rf")
// Define drive actions here
}