|
1 | 1 | package frc.robot.constants; |
2 | 2 |
|
3 | | -public class DriveConstants {} |
| 3 | +import com.ctre.phoenix.motorcontrol.FeedbackDevice; |
| 4 | +import com.ctre.phoenix.motorcontrol.LimitSwitchSource; |
| 5 | +import com.ctre.phoenix.motorcontrol.can.TalonSRXConfiguration; |
| 6 | +import com.ctre.phoenix.sensors.SensorVelocityMeasPeriod; |
| 7 | +import com.ctre.phoenix6.configs.CurrentLimitsConfigs; |
| 8 | +import com.ctre.phoenix6.configs.MotorOutputConfigs; |
| 9 | +import com.ctre.phoenix6.configs.Pigeon2Configuration; |
| 10 | +import com.ctre.phoenix6.configs.Slot0Configs; |
| 11 | +import com.ctre.phoenix6.configs.TalonFXConfiguration; |
| 12 | +import com.ctre.phoenix6.signals.NeutralModeValue; |
| 13 | +import edu.wpi.first.math.geometry.Translation2d; |
| 14 | + |
| 15 | +public class DriveConstants { |
| 16 | + public static final double kDriveGearRatio = 6.5; |
| 17 | + public static final double kWheelDiameterInches = 4.0; |
| 18 | + public static final double kMaxSpeedMetersPerSecond = 12.0; |
| 19 | + public static final double kSpeedStillThreshold = 0.1; // meters per second |
| 20 | + public static final double kGyroRateStillThreshold = 10.0; // 25 5 degrees per second |
| 21 | + public static final double kGyroDifferentThreshold = 5.0; // 5 degrees |
| 22 | + public static final int kGyroDifferentCount = 3; |
| 23 | + |
| 24 | + public static final double kRobotLength = 22.0; |
| 25 | + public static final double kRobotWidth = 22.0; |
| 26 | + public static final double kFieldMaxX = 690.0; |
| 27 | + |
| 28 | + public static final double kPOmega = 4.5; |
| 29 | + public static final double kIOmega = 0.0; |
| 30 | + public static final double kDOmega = 0.0; |
| 31 | + public static final double kMaxVelOmega = |
| 32 | + (kMaxSpeedMetersPerSecond / Math.hypot(kRobotWidth / 2.0, kRobotLength / 2.0)) / 2.0; |
| 33 | + public static final double kMaxAccelOmega = 5.0; |
| 34 | + |
| 35 | + public static final double kPHolonomic = 3.0; // was 3 |
| 36 | + public static final double kIHolonomic = 0.0000; |
| 37 | + public static final double kDHolonomic = 0.00; // kPHolonomic/100 |
| 38 | + |
| 39 | + public static Translation2d[] getWheelLocationMeters() { |
| 40 | + final double x = kRobotLength / 2.0; // front-back, was ROBOT_LENGTH |
| 41 | + final double y = kRobotWidth / 2.0; // left-right, was ROBOT_WIDTH |
| 42 | + Translation2d[] locs = new Translation2d[4]; |
| 43 | + locs[0] = new Translation2d(x, y); // left front |
| 44 | + locs[1] = new Translation2d(x, -y); // right front |
| 45 | + locs[2] = new Translation2d(-x, y); // left rear |
| 46 | + locs[3] = new Translation2d(-x, -y); // right rear |
| 47 | + return locs; |
| 48 | + } |
| 49 | + |
| 50 | + // temp stuff |
| 51 | + public static final int kTempAvgCount = 25; |
| 52 | + public static final double kTripTemp = 1300; |
| 53 | + public static final double kRecoverTemp = 1290; |
| 54 | + public static final double kNotifyTemp = 1295; |
| 55 | + |
| 56 | + public static TalonSRXConfiguration |
| 57 | + getAzimuthTalonConfig() { // will be changed to a TalonFXConfiguration |
| 58 | + // constructor sets encoder to Quad/CTRE_MagEncoder_Relative |
| 59 | + TalonSRXConfiguration azimuthConfig = new TalonSRXConfiguration(); |
| 60 | + |
| 61 | + azimuthConfig.primaryPID.selectedFeedbackCoefficient = 1.0; |
| 62 | + azimuthConfig.auxiliaryPID.selectedFeedbackSensor = FeedbackDevice.None; |
| 63 | + |
| 64 | + azimuthConfig.forwardLimitSwitchSource = LimitSwitchSource.Deactivated; |
| 65 | + azimuthConfig.reverseLimitSwitchSource = LimitSwitchSource.Deactivated; |
| 66 | + |
| 67 | + azimuthConfig.continuousCurrentLimit = 10; |
| 68 | + azimuthConfig.peakCurrentDuration = 0; |
| 69 | + azimuthConfig.peakCurrentLimit = 0; |
| 70 | + |
| 71 | + azimuthConfig.slot0.kP = 15.0; |
| 72 | + azimuthConfig.slot0.kI = 0.0; |
| 73 | + azimuthConfig.slot0.kD = 150.0; |
| 74 | + azimuthConfig.slot0.kF = 1.0; |
| 75 | + azimuthConfig.slot0.integralZone = 0; |
| 76 | + azimuthConfig.slot0.allowableClosedloopError = 0; |
| 77 | + azimuthConfig.slot0.maxIntegralAccumulator = 0; |
| 78 | + |
| 79 | + azimuthConfig.motionCruiseVelocity = 800; |
| 80 | + azimuthConfig.motionAcceleration = 10_000; |
| 81 | + azimuthConfig.velocityMeasurementWindow = 64; |
| 82 | + azimuthConfig.velocityMeasurementPeriod = SensorVelocityMeasPeriod.Period_100Ms; |
| 83 | + azimuthConfig.voltageCompSaturation = 12; |
| 84 | + azimuthConfig.voltageMeasurementFilter = 32; |
| 85 | + azimuthConfig.neutralDeadband = 0.04; |
| 86 | + return azimuthConfig; |
| 87 | + } |
| 88 | + |
| 89 | + public static TalonFXConfiguration getDriveTalonConfig() { |
| 90 | + TalonFXConfiguration driveConfig = new TalonFXConfiguration(); |
| 91 | + |
| 92 | + CurrentLimitsConfigs currentConfig = new CurrentLimitsConfigs(); |
| 93 | + currentConfig.SupplyCurrentLimit = 60; |
| 94 | + |
| 95 | + currentConfig.StatorCurrentLimit = 140; |
| 96 | + |
| 97 | + currentConfig.SupplyCurrentLimitEnable = true; |
| 98 | + currentConfig.StatorCurrentLimitEnable = true; |
| 99 | + |
| 100 | + driveConfig.CurrentLimits = currentConfig; |
| 101 | + |
| 102 | + Slot0Configs slot0Config = new Slot0Configs(); |
| 103 | + slot0Config.kP = 0.5; // 0.16 using phoenix 6 migrate |
| 104 | + slot0Config.kI = 0.5; // 0.0002 using phoenix 6 migrate |
| 105 | + slot0Config.kD = 0.0; |
| 106 | + slot0Config.kV = 0.12; // 0.047 using phoenix 6 migrate |
| 107 | + driveConfig.Slot0 = slot0Config; |
| 108 | + |
| 109 | + MotorOutputConfigs motorConfigs = new MotorOutputConfigs(); |
| 110 | + motorConfigs.DutyCycleNeutralDeadband = 0.01; |
| 111 | + motorConfigs.NeutralMode = NeutralModeValue.Brake; |
| 112 | + driveConfig.MotorOutput = motorConfigs; |
| 113 | + |
| 114 | + return driveConfig; |
| 115 | + } |
| 116 | + |
| 117 | + public static final int kPigeonCanID = 1000; // fix later |
| 118 | + |
| 119 | + public static Pigeon2Configuration getPigeon2Configuration() { |
| 120 | + Pigeon2Configuration config = new Pigeon2Configuration(); |
| 121 | + |
| 122 | + config.MountPose.MountPoseYaw = -90.0; |
| 123 | + config.MountPose.MountPoseRoll = 0.0; |
| 124 | + config.MountPose.MountPosePitch = 0.0; |
| 125 | + |
| 126 | + config.GyroTrim.GyroScalarX = 0.0; |
| 127 | + config.GyroTrim.GyroScalarY = 0.0; |
| 128 | + config.GyroTrim.GyroScalarZ = -2.12; |
| 129 | + |
| 130 | + return config; |
| 131 | + } |
| 132 | + |
| 133 | + public static CurrentLimitsConfigs getSafeDriveLimits() { |
| 134 | + CurrentLimitsConfigs currentConfig = new CurrentLimitsConfigs(); |
| 135 | + currentConfig.SupplyCurrentLimit = 30; |
| 136 | + currentConfig.SupplyCurrentLimitEnable = true; |
| 137 | + currentConfig.StatorCurrentLimitEnable = false; |
| 138 | + return currentConfig; |
| 139 | + } |
| 140 | + |
| 141 | + public static CurrentLimitsConfigs getNormDriveLimits() { |
| 142 | + CurrentLimitsConfigs currentConfig = new CurrentLimitsConfigs(); |
| 143 | + currentConfig.SupplyCurrentLimit = 30; |
| 144 | + |
| 145 | + currentConfig.StatorCurrentLimit = 140; |
| 146 | + |
| 147 | + currentConfig.SupplyCurrentLimitEnable = true; |
| 148 | + currentConfig.StatorCurrentLimitEnable = true; |
| 149 | + return currentConfig; |
| 150 | + } |
| 151 | +} |
0 commit comments