Skip to content

Adding a Drivetrain

A Drivetrain is a type of Attachment that defines Actions that can move Robots autonomously and tele-operated.

Volt provides many pre-built Drivetrain classes for many combinations of drivetrain types, localization methods, and backends. Using these pre-built classes is the simplest way to add a Drivetrain to your Robot.

Choosing a Drivetrain is a three-step process:

  1. Select a type of physical drivetrain (What drivetrain does your robot physically use?)
  2. Select a localization method (What localization hardware do you have?)
  3. Select a compatible backend (Which pathing backend/actions do you want to use?)

This table contains all of Volt’s pre-built Drivetrain classes:

Drivetrain Localization Backend Class
Mecanum Drive Encoder RoadRunner DriveEncoderMecanumRoadRunnerDrivetrain
Mecanum Two Wheel PedroPathing TwoWheelMecanumPedroPathingDrivetrain
Mecanum Two Wheel RoadRunner TwoWheelMecanumRoadRunnerDrivetrain
Mecanum Three Wheel PedroPathing ThreeWheelMecanumPedroPathingDrivetrain
Mecanum Three Wheel RoadRunner ThreeWheelMecanumRoadRunnerDrivetrain
Mecanum Three Wheel + IMU PedroPathing ThreeWheelIMUMecanumPedroPathingDrivetrain
Mecanum Pinpoint PedroPathing PinpointMecanumPedroPathingDrivetrain
Mecanum Pinpoint RoadRunner PinpointMecanumRoadRunnerDrivetrain
Mecanum OTOS PedroPathing OTOSMecanumPedroPathingDrivetrain
Mecanum OTOS RoadRunner OTOSMecanumRoadRunnerDrivetrain
Mecanum OctoQuad PedroPathing OctoQuadMecanumPedroPathingDrivetrain
Swerve Two Wheel PedroPathing TwoWheelSwervePedroPathingDrivetrain
Swerve Three Wheel PedroPathing ThreeWheelSwervePedroPathingDrivetrain
Swerve Three Wheel + IMU PedroPathing ThreeWheelIMUSwervePedroPathingDrivetrain
Swerve Pinpoint PedroPathing PinpointSwervePedroPathingDrivetrain
Swerve OTOS PedroPathing OTOSSwervePedroPathingDrivetrain
Swerve OctoQuad PedroPathing OctoQuadSwervePedroPathingDrivetrain
Tank Drive Encoder RoadRunner DriveEncoderTankRoadRunnerDrivetrain
Tank Two Wheel RoadRunner TwoWheelTankRoadRunnerDrivetrain
Tank Three Wheel RoadRunner ThreeWheelTankRoadRunnerDrivetrain
Tank Pinpoint RoadRunner PinpointTankRoadRunnerDrivetrain
Tank OTOS RoadRunner OTOSTankRoadRunnerDrivetrain

Let’s use a mecanum drivetrain, drive encoder localization, and PedroPathing.

Create a Robot class that extends DrivetrainRobot. This gives your Robot access to a drivetrain instance.

class MyRobot(hardwareMap: HardwareMap) :
DrivetrainRobot(hardwareMap)

Pass a generic type parameter that inherits Drivetrain. This lets Volt know what type of Drivetrain class your Robot uses.

In this case we’ll use PinpointMecanumPedroPathingDrivetrain:

class MyRobot(hardwareMap: HardwareMap) :
DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain>(
hardwareMap,
PinpointMecanumPedroPathingDrivetrain(
hardwareMap,
)
)

4. Create and Configure Drivetrain Instance

Section titled “4. Create and Configure Drivetrain Instance”

Create a new instance of your Drivetrain type. This is where you define hardware and tune your Drivetrain.

For our PinpointMecanumPedroPathingDrivetrain, we’ll supply PinpointConfig, MecanumConfig, and use the Foresight algorithm.

class MyRobot(hardwareMap: HardwareMap) :
DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain>(
hardwareMap,
PinpointMecanumPedroPathingDrivetrain(
hardwareMap,
PinpointConfig {
it.name.set("pinpoint")
it.xPodOffset.set(2.187)
it.yPodOffset.set(-4.572)
it.xPodDirection.set(GoBildaPinpointDriver.EncoderDirection.FORWARD)
it.yPodDirection.set(GoBildaPinpointDriver.EncoderDirection.FORWARD)
},
MecanumConfig {
it.frontLeftName.set("lf")
it.backLeftName.set("lr")
it.frontRightName.set("rf")
it.backRightName.set("rr")
it.frontLeftDirection.set(DcMotorSimple.Direction.FORWARD)
it.backLeftDirection.set(DcMotorSimple.Direction.FORWARD)
it.frontRightDirection.set(DcMotorSimple.Direction.REVERSE)
it.backRightDirection.set(DcMotorSimple.Direction.REVERSE)
it.manualBrakeMode.set(true)
},
Foresight(
ForesightConfig {
val primaryTranslationalForward = Controller.proportional(0.3)
val secondaryTranslationalForward = Controller.proportional(0.1)
val primaryTranslationalLateral = Controller.proportional(0.3)
val secondaryTranslationalLateral = Controller.proportional(0.1)
it.forwardTranslational.set(
Controller.piecewise(secondaryTranslationalForward)
.put(2.5, primaryTranslationalForward)
)
it.strafeTranslational.set(
Controller.piecewise(secondaryTranslationalLateral)
.put(2.5, primaryTranslationalLateral)
)
it.coast.set(Controller.proportionalFeedforward(0.010978350889324107))
it.brake.set(Controller.proportionalFeedforward(0.008731598255925491))
it.headingFeedback.set(Controller.proportional(5.258721785960744))
it.headingBrakeCoefficients.set(
Vector2D.cartesian(0.05642143125655298, 0.0063829525363003695)
)
it.linearBrakeCoefficients.set(
Matrix.diag(0.10605894992901523, 0.08719146175596092)
)
it.quadraticBrakeCoefficients.set(
Matrix.diag(0.0014663966976606565, 0.0013837064502458813)
)
it.maxAchievableForwardVelocity.set(72.72923108818539)
it.maxAchievableStrafeVelocity.set(52.34323936525474)
it.naturalForwardDeceleration.set(85.01144677379789)
it.naturalStrafeDeceleration.set(104.49787535782846)
}
),
),
)

In this case, we would have calculated the Robot’s mass, driving base width, and driving base length; tuned translational PIDF coefficients, forward ticks per inch, strafe ticks per inch, and turn ticks per inch; and experimented with various maximum powers.

import com.pedropathing.algorithm.Foresight
import com.pedropathing.algorithm.ForesightConfig
import com.pedropathing.controllers.Controller
import com.pedropathing.math.Matrix
import com.pedropathing.math.Vector2D
import com.pedropathing.revhub.drivetrains.MecanumConfig
import com.pedropathing.revhub.localizers.PinpointConfig
import com.qualcomm.hardware.gobilda.GoBildaPinpointDriver
import com.qualcomm.robotcore.hardware.DcMotorSimple
import com.qualcomm.robotcore.hardware.HardwareMap
import dev.kingssack.volt.attachment.drivetrain.pp.mecanum.PinpointMecanumPedroPathingDrivetrain
import dev.kingssack.volt.robot.DrivetrainRobot
class MyRobot(hardwareMap: HardwareMap) :
DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain>(
hardwareMap,
PinpointMecanumPedroPathingDrivetrain(
hardwareMap,
PinpointConfig {
it.name.set("pinpoint")
it.xPodOffset.set(2.187)
it.yPodOffset.set(-4.572)
it.xPodDirection.set(GoBildaPinpointDriver.EncoderDirection.FORWARD)
it.yPodDirection.set(GoBildaPinpointDriver.EncoderDirection.FORWARD)
},
MecanumConfig {
it.frontLeftName.set("lf")
it.backLeftName.set("lr")
it.frontRightName.set("rf")
it.backRightName.set("rr")
it.frontLeftDirection.set(DcMotorSimple.Direction.FORWARD)
it.backLeftDirection.set(DcMotorSimple.Direction.FORWARD)
it.frontRightDirection.set(DcMotorSimple.Direction.REVERSE)
it.backRightDirection.set(DcMotorSimple.Direction.REVERSE)
it.manualBrakeMode.set(true)
},
Foresight(
ForesightConfig {
val primaryTranslationalForward = Controller.proportional(0.3)
val secondaryTranslationalForward = Controller.proportional(0.1)
val primaryTranslationalLateral = Controller.proportional(0.3)
val secondaryTranslationalLateral = Controller.proportional(0.1)
it.forwardTranslational.set(
Controller.piecewise(secondaryTranslationalForward)
.put(2.5, primaryTranslationalForward)
)
it.strafeTranslational.set(
Controller.piecewise(secondaryTranslationalLateral)
.put(2.5, primaryTranslationalLateral)
)
it.coast.set(Controller.proportionalFeedforward(0.010978350889324107))
it.brake.set(Controller.proportionalFeedforward(0.008731598255925491))
it.headingFeedback.set(Controller.proportional(5.258721785960744))
it.headingBrakeCoefficients.set(
Vector2D.cartesian(0.05642143125655298, 0.0063829525363003695)
)
it.linearBrakeCoefficients.set(
Matrix.diag(0.10605894992901523, 0.08719146175596092)
)
it.quadraticBrakeCoefficients.set(
Matrix.diag(0.0014663966976606565, 0.0013837064502458813)
)
it.maxAchievableForwardVelocity.set(72.72923108818539)
it.maxAchievableStrafeVelocity.set(52.34323936525474)
it.naturalForwardDeceleration.set(85.01144677379789)
it.naturalStrafeDeceleration.set(104.49787535782846)
}
),
),
)