Swerve Constants Example
A fully setup Constants file using swerve
package org.firstinspires.ftc.teamcode.pedroPathing;
import com.pedropathing.VectorCalculator;
import com.pedropathing.control.FilteredPIDFCoefficients;
import com.pedropathing.control.PIDFCoefficients;
import com.pedropathing.control.PredictiveBrakingCoefficients;
import com.pedropathing.follower.Follower;
import com.pedropathing.follower.FollowerConstants;
import com.pedropathing.ftc.FollowerBuilder;
import com.pedropathing.ftc.drivetrains.CoaxialPod;
import com.pedropathing.ftc.drivetrains.SwerveConstants;
import com.pedropathing.ftc.localization.constants.PinpointConstants;
import com.pedropathing.geometry.Pose;
import com.pedropathing.paths.PathConstraints;
import com.qualcomm.hardware.gobilda.GoBildaPinpointDriver;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.hardware.HardwareMap;
import org.firstinspires.ftc.robotcore.external.navigation.DistanceUnit;
public class PedroConstants {
public static FollowerConstants followerConstants = new FollowerConstants()
.forwardZeroPowerAcceleration(-197.1)
.lateralZeroPowerAcceleration(-197.1)
.useSecondaryDrivePIDF(true).useSecondaryHeadingPIDF(true)
.useSecondaryTranslationalPIDF(true)
.translationalPIDFCoefficients(new PIDFCoefficients(0.125, 0, 0.008, 0))
.secondaryTranslationalPIDFCoefficients(new PIDFCoefficients(0.0825, 0, 0.008, 0))
.headingPIDFCoefficients(new PIDFCoefficients(1.75, 0, 0.003, 0))
.secondaryHeadingPIDFCoefficients(new PIDFCoefficients(0.8, 0, 0.015, 0))
.drivePIDFCoefficients(new FilteredPIDFCoefficients(0.005, 0, 0.00003, 0.6, 0.13))
.secondaryDrivePIDFCoefficients(
new FilteredPIDFCoefficients(0.004, 0, 0.000002, 0.6, 0.13))
// .drivePIDFCoefficients(new FilteredPIDFCoefficients(0,0,0,0,0))
// .secondaryDrivePIDFCoefficients(new FilteredPIDFCoefficients(0,0,0,0,0))
// .predictiveBrakingCoefficients(new PredictiveBrakingCoefficients(
// 0.05, //0.05 to 0.3
// 0,//0.38735914623969386,
// 0.002)
// )
.centripetalScaling(0.0005).
mass(13.732);
public static PinpointConstants localizerConstants = new PinpointConstants()
.forwardPodY(-2.9350393701) //-74.5mm
.strafePodX(-5.9133858268) //-150.2
.distanceUnit(DistanceUnit.INCH).hardwareMapName("pinpoint")
.encoderResolution(GoBildaPinpointDriver.GoBildaOdometryPods.goBILDA_4_BAR_POD)
.forwardEncoderDirection(GoBildaPinpointDriver.EncoderDirection.FORWARD)
.strafeEncoderDirection(GoBildaPinpointDriver.EncoderDirection.REVERSED);
public static SwerveConstants swerveConstants = new SwerveConstants()
.velocity(73.9)
// .zeroPowerBehavior(SwerveConstants.ZeroPowerBehavior.IGNORE_ANGLE_CHANGES)
.useBrakeModeInTeleOp(true);
private static double kP = 0.0055 * 180 / Math.PI;
private static double kD = 0.00015 * 180 / Math.PI;
private static double kFFront = 0.0130;
private static double kFBack = 0.0190;
private static double dtLength = 271.148;
private static double dtWidth = 270.7;
private static CoaxialPod leftFront(HardwareMap hardwareMap) {
CoaxialPod pod = new CoaxialPod(hardwareMap, "sm2", "ss2", "se2",
new PIDFCoefficients(kP, 0, kD, kFFront), DcMotorSimple.Direction.REVERSE,
DcMotorSimple.Direction.REVERSE, Math.toRadians(353.1), new Pose(dtLength, dtWidth),
0.025, 3.290, false);
pod.setMotorCachingThreshold(0.05);
pod.setServoCachingThreshold(0.05);
return pod;
}
private static CoaxialPod rightFront(HardwareMap hardwareMap) {
CoaxialPod pod = new CoaxialPod(hardwareMap, "sm1", "ss1", "se1",
new PIDFCoefficients(kP, 0, kD, kFFront), DcMotorSimple.Direction.FORWARD,
DcMotorSimple.Direction.REVERSE, Math.toRadians(348.2), new Pose(dtLength, -dtWidth),
0.018, 3.288, false);
pod.setMotorCachingThreshold(0.05);
pod.setServoCachingThreshold(0.05);
return pod;
}
private static CoaxialPod leftBack(HardwareMap hardwareMap) {
CoaxialPod pod = new CoaxialPod(hardwareMap, "sm3", "ss3", "se3",
new PIDFCoefficients(kP, 0, kD, kFBack), DcMotorSimple.Direction.REVERSE,
DcMotorSimple.Direction.REVERSE, Math.toRadians(179.3), new Pose(-dtLength, dtWidth),
0.029, 3.307, false);
pod.setMotorCachingThreshold(0.05);
pod.setServoCachingThreshold(0.05);
return pod;
}
private static CoaxialPod rightBack(HardwareMap hardwareMap) {
CoaxialPod pod = new CoaxialPod(hardwareMap, "sm0", "ss0", "se0",
new PIDFCoefficients(kP, 0, kD, kFBack), DcMotorSimple.Direction.FORWARD,
DcMotorSimple.Direction.REVERSE, Math.toRadians(289.5), new Pose(-dtLength, -dtWidth),
0.014, 3.301, false);
pod.setMotorCachingThreshold(0.05);
pod.setServoCachingThreshold(0.05);
return pod;
}
// public static PathConstraints pathConstraints = new PathConstraints(0.95, 100, 1, 1);
public static PathConstraints pathConstraints =
new PathConstraints(0.9, 2, 2, 0.03, 50, 1, 10, 1);
// default
// public static PathConstraints defaultConstraints = new PathConstraints(0.995, 0.1, 0.1,
// 0.007, 100, 1, 10, 1);
public static Follower createFollower(HardwareMap hardwareMap) {
return new FollowerBuilder(followerConstants, hardwareMap).pathConstraints(pathConstraints)
.swerveDrivetrain(swerveConstants, leftFront(hardwareMap), rightFront(hardwareMap),
leftBack(hardwareMap), rightBack(hardwareMap))
.pinpointLocalizer(localizerConstants).build();
}
}Last updated on