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.
1. Choose a Drivetrain
Section titled “1. Choose a Drivetrain”Choosing a Drivetrain is a three-step process:
- Select a type of physical drivetrain (What drivetrain does your robot physically use?)
- Select a localization method (What localization hardware do you have?)
- 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.
2. Create a DrivetrainRobot
Section titled “2. Create a DrivetrainRobot”Create a Robot class that extends DrivetrainRobot. This gives your Robot access to a drivetrain instance.
class MyRobot(hardwareMap: HardwareMap) : DrivetrainRobot(hardwareMap)public class MyRobot extends DrivetrainRobot { public MyRobot(HardwareMap hardwareMap) { super(hardwareMap); }}3. Declare Drivetrain Type
Section titled “3. Declare Drivetrain Type”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, ) )public class MyRobot extends DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain> { public MyRobot(HardwareMap hardwareMap) { super(getHardwareMap(), new PinpointMecanumPedroPathingDrivetrain( getHardwareMap() )); }}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) } ), ), )public class MyRobot extends DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain> { public MyRobot(HardwareMap hardwareMap) { super( hardwareMap, new PinpointMecanumPedroPathingDrivetrain( getHardwareMap(), new PinpointConfig(c -> { c.name.set("pinpoint"); c.xPodOffset.set(2.187); c.yPodOffset.set(-4.572); c.xPodDirection.set(GoBildaPinpointDriver.EncoderDirection.FORWARD); c.yPodDirection.set(GoBildaPinpointDriver.EncoderDirection.FORWARD); }), new MecanumConfig(c -> { c.frontLeftName.set("lf"); c.backLeftName.set("lr"); c.frontRightName.set("rf"); c.backRightName.set("rr");
c.frontLeftDirection.set(DcMotorSimple.Direction.REVERSE); c.backLeftDirection.set(DcMotorSimple.Direction.REVERSE); c.frontRightDirection.set(DcMotorSimple.Direction.FORWARD); c.backRightDirection.set(DcMotorSimple.Direction.FORWARD);
c.manualBrakeMode.set(true); }), new Foresight(new ForesightConfig(c -> { Controller primaryTranslationalForward = Controller.proportional(0.3); Controller secondaryTranslationalForward = Controller.proportional(0.1); Controller primaryTranslationalLateral = Controller.proportional(0.3); Controller secondaryTranslationalLateral = Controller.proportional(0.1);
c.forwardTranslational.set(Controller.piecewise(secondaryTranslationalForward).put(2.5, primaryTranslationalForward)); c.strafeTranslational.set(Controller.piecewise(secondaryTranslationalLateral).put(2.5, primaryTranslationalLateral));
c.coast.set(Controller.proportionalFeedforward(0.010978350889324107)); c.brake.set(Controller.proportionalFeedforward(0.008731598255925491));
c.headingFeedback.set(Controller.proportional(5.258721785960744)); c.headingBrakeCoefficients.set(Vector2D.cartesian(0.05642143125655298, 0.0063829525363003695));
c.linearBrakeCoefficients.set(Matrix.diag(0.10605894992901523, 0.08719146175596092)); c.quadraticBrakeCoefficients.set(Matrix.diag(0.0014663966976606565, 0.0013837064502458813));
c.maxAchievableForwardVelocity.set(72.72923108818539); c.maxAchievableStrafeVelocity.set(52.34323936525474); c.naturalForwardDeceleration.set(85.01144677379789); c.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.
Result
Section titled “Result”import com.pedropathing.algorithm.Foresightimport com.pedropathing.algorithm.ForesightConfigimport com.pedropathing.controllers.Controllerimport com.pedropathing.math.Matriximport com.pedropathing.math.Vector2Dimport com.pedropathing.revhub.drivetrains.MecanumConfigimport com.pedropathing.revhub.localizers.PinpointConfigimport com.qualcomm.hardware.gobilda.GoBildaPinpointDriverimport com.qualcomm.robotcore.hardware.DcMotorSimpleimport com.qualcomm.robotcore.hardware.HardwareMapimport dev.kingssack.volt.attachment.drivetrain.pp.mecanum.PinpointMecanumPedroPathingDrivetrainimport 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) } ), ), )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;
public class MyRobot extends DrivetrainRobot<PinpointMecanumPedroPathingDrivetrain> { public MyRobot(HardwareMap hardwareMap) { super( hardwareMap, new PinpointMecanumPedroPathingDrivetrain( getHardwareMap(), new PinpointConfig(c -> { c.name.set("pinpoint"); c.xPodOffset.set(2.187); c.yPodOffset.set(-4.572); c.xPodDirection.set(GoBildaPinpointDriver.EncoderDirection.FORWARD); c.yPodDirection.set(GoBildaPinpointDriver.EncoderDirection.FORWARD); }), new MecanumConfig(c -> { c.frontLeftName.set("lf"); c.backLeftName.set("lr"); c.frontRightName.set("rf"); c.backRightName.set("rr");
c.frontLeftDirection.set(DcMotorSimple.Direction.REVERSE); c.backLeftDirection.set(DcMotorSimple.Direction.REVERSE); c.frontRightDirection.set(DcMotorSimple.Direction.FORWARD); c.backRightDirection.set(DcMotorSimple.Direction.FORWARD);
c.manualBrakeMode.set(true); }), new Foresight(new ForesightConfig(c -> { Controller primaryTranslationalForward = Controller.proportional(0.3); Controller secondaryTranslationalForward = Controller.proportional(0.1); Controller primaryTranslationalLateral = Controller.proportional(0.3); Controller secondaryTranslationalLateral = Controller.proportional(0.1);
c.forwardTranslational.set(Controller.piecewise(secondaryTranslationalForward).put(2.5, primaryTranslationalForward)); c.strafeTranslational.set(Controller.piecewise(secondaryTranslationalLateral).put(2.5, primaryTranslationalLateral));
c.coast.set(Controller.proportionalFeedforward(0.010978350889324107)); c.brake.set(Controller.proportionalFeedforward(0.008731598255925491));
c.headingFeedback.set(Controller.proportional(5.258721785960744)); c.headingBrakeCoefficients.set(Vector2D.cartesian(0.05642143125655298, 0.0063829525363003695));
c.linearBrakeCoefficients.set(Matrix.diag(0.10605894992901523, 0.08719146175596092)); c.quadraticBrakeCoefficients.set(Matrix.diag(0.0014663966976606565, 0.0013837064502458813));
c.maxAchievableForwardVelocity.set(72.72923108818539); c.maxAchievableStrafeVelocity.set(52.34323936525474); c.naturalForwardDeceleration.set(85.01144677379789); c.naturalStrafeDeceleration.set(104.49787535782846); })) ) ); }}Next Steps
Section titled “Next Steps”- Create an OpMode that controls your drivetrain
- Learn more about Actions