Pedro Pathing 2.0.0 has released! If you haven't already, migrate now.
Pedro Pathing LogoPedro Pathing
Tuning/Swerve

Swerve Setup

Setting up pedro constants for a swerve drivetrain

Swerve Constants

Next, we will create our drivetrain constants and construct our pods.

Constants.java
public static SwerveConstants swerveConstants = new SwerveConstants()
        .maxPower(1) //determines the max power of the drivetrain
//      .zeroPowerBehavior(SwerveConstants.ZeroPowerBehavior.IGNORE_ANGLE_CHANGES)
        //the above disables x locking for swerve, which can be useful for tuning pod offsets

Constructing Pods

Now we will construct our SwervePod instances (SwervePod is an interface). Pedro has two built-in implementations of SwervePod, CoaxialPod and DiffyPod. To set up your drivetrain, you will need to create a method to construct each of your pods, which you will then pass into the swerve drivetrain.

An example of a method creating a CoaxialPod is shown below.

Constants.java
private static CoaxialPod leftFront(HardwareMap hardwareMap) {
    CoaxialPod pod = new CoaxialPod(
            hardwareMap,
            "leftFrontMotor", //the name of your motor in your config
            "leftFrontServo", //the name of your servo in your config
            "leftFrontEncoder", // the name of your analog encoder in your config
            new PIDFCoefficients(0.3, 0, 0.005, 0.01), //pod PIDF coefficients
            DcMotorSimple.Direction.FORWARD, //the direction of your motor
            DcMotorSimple.Direction.FORWARD, //the direction of your servo
            Math.toRadians(353.1), //your pod's angle offset, in radians
            new Pose(dtLength, dtWidth), //your pods x and y offsets,
                                         // in pedro coordinates (like with deadwheels)
            0 //analog min voltage
            3.3, //analog max voltage
            false); //encoder inverted
//  uncomment the below lines to change caching thresholds (by default 0.01)
//  pod.setMotorCachingThreshold(0.05); 
//  pod.setServoCachingThreshold(0.05);
    return pod;
}

Now we can update the createFollower method to take in our SwerveConstants and each SwervePod (you need to create a method for each pod).

Constants.java
public static Follower createFollower(HardwareMap hardwareMap) {
        return new FollowerBuilder(followerConstants, hardwareMap)
                .pathConstraints(pathConstraints)
                .swerveDrivetrain(swerveConstants,
                    leftFront(hardwareMap),
                    rightFront(hardwareMap),
                    leftBack(hardwareMap),
                    rightBack(hardwareMap))
                .build();
}

Last updated on