44import com .ctre .phoenix6 .signals .SensorDirectionValue ;
55import edu .wpi .first .math .geometry .Translation2d ;
66import edu .wpi .first .math .kinematics .SwerveDriveKinematics ;
7- import edu .wpi .first .math .system .plant .DCMotor ;
87import edu .wpi .first .math .trajectory .TrapezoidProfile ;
98import edu .wpi .first .math .trajectory .TrapezoidProfile .Constraints ;
109import edu .wpi .first .math .util .Units ;
@@ -82,19 +81,18 @@ public static final class DriveConstants {
8281 public static final InvertedValue REAR_RIGHT_DRIVE_ENCODER_REVERSED =
8382 InvertedValue .CounterClockwise_Positive ;
8483
85- public static final double MAX_ANGULAR_SPEED_RADIANS_PER_SECOND = 6 * Math . PI ;
86- public static final double LOW_ANGULAR_SPEED_RADIANS_PER_SECOND = 3 * Math . PI ;
84+ public static final double MAX_ANGULAR_SPEED_RADIANS_PER_SECOND = 20 ;
85+ public static final double LOW_ANGULAR_SPEED_RADIANS_PER_SECOND = 5 ;
8786
88- public static final double MAX_SPEED_METERS_PER_SECOND = 4.5 ;
87+ public static final double MAX_SPEED_METERS_PER_SECOND = 6.95 ;
8988 public static final double MAX_SHOOT_SPEED_METERS_PER_SECOND = 3 ;
9089
9190 public static final double HEADING_ACCEPTABLE_ERROR_RADIANS = Units .degreesToRadians (2.5 );
9291 public static final double HEADING_ACCEPTABLE_ERROR_MOVING_RADIANS = Units .degreesToRadians (4 );
9392 }
9493
9594 public class ModuleConstants {
96- public static final double DRIVE_GEAR_RATIO = 7.13 ;
97- public static final double TURN_GEAR_RATIO = 11.3142 ;
95+ public static final double DRIVE_GEAR_RATIO = 4.59 ;
9896 public static final double WHEEL_DIAMETER_METERS = Units .inchesToMeters (3.774788522800778 );
9997
10098 public static final double WHEEL_CIRCUMFERENCE_METERS = WHEEL_DIAMETER_METERS * Math .PI ;
@@ -105,27 +103,29 @@ public class ModuleConstants {
105103 public static final double DRIVE_SUPPLY_LIMIT = 45.0 ;
106104 public static final double DRIVE_STATOR_LIMIT = 50.0 ;
107105
108- public static final double TURN_P = 15 ;
106+ public static final double TURN_P = 116 ;
109107 public static final double TURN_I = 0.0 ;
110- public static final double TURN_D = 0.0 ;
108+ public static final double TURN_D = 0.64 ;
111109
112- public static final double TURN_S = 0 ;
110+ public static final double TURN_S = 0.0 ;
113111 public static final double TURN_V = 0.0 ;
114112 public static final double TURN_A = 0.0 ;
115113
116114 public static final double MAX_ANGULAR_SPEED_ROTATIONS_PER_SECOND = 30 ;
117115 public static final double MAX_ANGULAR_ACCELERATION_ROTATIONS_PER_SECOND_SQUARED = 24 ;
118116
119- public static final double DRIVE_P = 0.345 ;
117+ public static final double DRIVE_P = 0.417 ;
120118 public static final double DRIVE_I = 0.0 ;
121119 public static final double DRIVE_D = 0.0 ;
122120
123- public static final double DRIVE_S = 0.151315113225759 ;
121+ public static final double DRIVE_S = 0.16 ;
124122 // These values were gotten using recalc, then converted to the correct units & were confirmed
125123 // through testing and characterization
126124 // https://www.reca.lc/drive?appliedVoltageRamp=%7B%22s%22%3A1200%2C%22u%22%3A%22V%2Fs%22%7D&batteryAmpHours=%7B%22s%22%3A18%2C%22u%22%3A%22A%2Ah%22%7D&batteryResistance=%7B%22s%22%3A0.018%2C%22u%22%3A%22Ohm%22%7D&batteryVoltageAtRest=%7B%22s%22%3A12.6%2C%22u%22%3A%22V%22%7D&efficiency=97&filtering=1&gearRatioMax=%7B%22magnitude%22%3A15%2C%22ratioType%22%3A%22Reduction%22%7D&gearRatioMin=%7B%22magnitude%22%3A3%2C%22ratioType%22%3A%22Reduction%22%7D&maxSimulationTime=%7B%22s%22%3A4%2C%22u%22%3A%22s%22%7D&maxSpeedAccelerationThreshold=%7B%22s%22%3A0.15%2C%22u%22%3A%22ft%2Fs2%22%7D&motor=%7B%22quantity%22%3A4%2C%22name%22%3A%22Kraken%20X60%2A%22%7D&motorCurrentLimit=%7B%22s%22%3A60%2C%22u%22%3A%22A%22%7D&numCyclesPerMatch=24&peakBatteryDischarge=20&ratio=%7B%22magnitude%22%3A4.59%2C%22ratioType%22%3A%22Reduction%22%7D&sprintDistance=%7B%22s%22%3A25%2C%22u%22%3A%22ft%22%7D&swerve=1&targetTimeToGoal=%7B%22s%22%3A2%2C%22u%22%3A%22s%22%7D&throttleResponseMax=0.99&throttleResponseMin=0.5&weightAuxilliary=%7B%22s%22%3A24%2C%22u%22%3A%22lbs%22%7D&weightDistributionFrontBack=0.5&weightDistributionLeftRight=0.5&weightInspected=%7B%22s%22%3A125%2C%22u%22%3A%22lbs%22%7D&wheelBaseLength=%7B%22s%22%3A27%2C%22u%22%3A%22in%22%7D&wheelBaseWidth=%7B%22s%22%3A20%2C%22u%22%3A%22in%22%7D&wheelCOFDynamic=0.9&wheelCOFLateral=1.1&wheelCOFStatic=1.1&wheelDiameter=%7B%22s%22%3A4%2C%22u%22%3A%22in%22%7D
127- public static final double DRIVE_V = 0.027285425272591 ; // = 0.1203 V*s/m
128- public static final double DRIVE_A = 0.000261387517243 ; // = 0.02225 V*s^2/m
125+ public static final double DRIVE_V =
126+ 1.73 * WHEEL_CIRCUMFERENCE_METERS / DRIVE_GEAR_RATIO ; // = 0.1203 V*s/m
127+ public static final double DRIVE_A =
128+ 0.32 * WHEEL_CIRCUMFERENCE_METERS / DRIVE_GEAR_RATIO ; // = 0.02225 V*s^2/m
129129 }
130130
131131 public static final class TrajectoryConstants {
@@ -170,84 +170,6 @@ public static final class TrajectoryConstants {
170170 new Constraints (DriveConstants .MAX_ANGULAR_SPEED_RADIANS_PER_SECOND , 2 );
171171 }
172172
173- /**
174- * stores the constants and PID configs for chassis because we want an all-real simulation for the
175- * chassis, the numbers are required to be considerably precise
176- */
177- public class SimulationConstants {
178- /**
179- * numbers that needs to be changed to fit each robot TODO: change these numbers to match your
180- * robot
181- */
182- public static final double WHEEL_COEFFICIENT_OF_FRICTION = 0.95 ,
183- ROBOT_MASS_KG = 40 ; // with bumpers
184-
185- /** TODO: change motor type to match your robot */
186- public static final DCMotor DRIVE_MOTOR = DCMotor .getKrakenX60 (1 ),
187- STEER_MOTOR = DCMotor .getFalcon500 (1 );
188-
189- public static final double WHEEL_RADIUS_METERS = ModuleConstants .WHEEL_DIAMETER_METERS / 2.0 ,
190- DRIVE_GEAR_RATIO = ModuleConstants .DRIVE_GEAR_RATIO ,
191- STEER_GEAR_RATIO = 16.0 ,
192- TIME_ROBOT_STOP_ROTATING_SECONDS = 0.06 ,
193- STEER_FRICTION_VOLTAGE = 0.12 ,
194- DRIVE_FRICTION_VOLTAGE = ModuleConstants .DRIVE_S ,
195- DRIVE_INERTIA = 0.01 ,
196- STEER_INERTIA = 0.01 ;
197-
198- /* adjust current limit */
199- public static final double DRIVE_CURRENT_LIMIT = ModuleConstants .DRIVE_STATOR_LIMIT ;
200- // public static final double STEER_CURRENT_LIMIT = ModuleConstants.ST;
201-
202- /* equations that calculates some constants for the simulator (don't modify) */
203- private static final double GRAVITY_CONSTANT = 9.81 ;
204- public static final double DRIVE_BASE_RADIUS = DriveConstants .MODULE_TRANSLATIONS [0 ].getNorm (),
205- /* friction_force = normal_force * coefficient_of_friction */
206- MAX_FRICTION_ACCELERATION = GRAVITY_CONSTANT * WHEEL_COEFFICIENT_OF_FRICTION ,
207- MAX_FRICTION_FORCE_PER_MODULE =
208- MAX_FRICTION_ACCELERATION * ROBOT_MASS_KG / DriveConstants .MODULE_TRANSLATIONS .length ,
209- /* force = torque / distance */
210- MAX_PROPELLING_FORCE_NEWTONS =
211- DRIVE_MOTOR .getTorque (DRIVE_CURRENT_LIMIT ) * DRIVE_GEAR_RATIO / WHEEL_RADIUS_METERS ,
212- /* floor_speed = wheel_angular_velocity * wheel_radius */
213- CHASSIS_MAX_VELOCITY =
214- DRIVE_MOTOR .freeSpeedRadPerSec
215- / DRIVE_GEAR_RATIO
216- * WHEEL_RADIUS_METERS , // calculate using choreo
217- CHASSIS_MAX_ACCELERATION_MPS_SQ =
218- Math .min (
219- MAX_FRICTION_ACCELERATION , // cannot exceed max friction
220- MAX_PROPELLING_FORCE_NEWTONS / ROBOT_MASS_KG ),
221- CHASSIS_MAX_ANGULAR_VELOCITY_RAD_PER_SEC = CHASSIS_MAX_VELOCITY / DRIVE_BASE_RADIUS ,
222- CHASSIS_MAX_ANGULAR_ACCELERATION_RAD_PER_SEC_SQ =
223- CHASSIS_MAX_ACCELERATION_MPS_SQ / DRIVE_BASE_RADIUS ,
224- CHASSIS_FRICTIONAL_ANGULAR_ACCELERATION =
225- CHASSIS_MAX_ANGULAR_VELOCITY_RAD_PER_SEC / TIME_ROBOT_STOP_ROTATING_SECONDS ;
226-
227- /* for collision detection in simulation */
228- public static final double BUMPER_WIDTH_METERS = Units .inchesToMeters (34.5 ),
229- BUMPER_LENGTH_METERS = Units .inchesToMeters (36 ),
230- /* https://en.wikipedia.org/wiki/Friction#Coefficient_of_friction */
231- BUMPER_COEFFICIENT_OF_FRICTION = 0.75 ,
232- /* https://simple.wikipedia.org/wiki/Coefficient_of_restitution */
233- BUMPER_COEFFICIENT_OF_RESTITUTION = 0.08 ;
234-
235- /* Gyro Sim */
236- public static final double GYRO_ANGULAR_ACCELERATION_THRESHOLD_SKIDDING_RAD_PER_SEC_SQ = 100 ;
237- public static final double SKIDDING_AMOUNT_AT_THRESHOLD_RAD = Math .toRadians (1.2 );
238- /*
239- * https://store.ctr-electronics.com/pigeon-2/
240- * for a well-installed one with vibration reduction, only 0.4 degree
241- * but most teams just install it directly on the rigid chassis frame (including my team :D)
242- * so at least 1.2 degrees of drifting in 1 minutes for an average angular velocity of 60 degrees/second
243- * which is the average velocity during normal swerve-circular-offense
244- * */
245- public static final double NORMAL_GYRO_DRIFT_IN_1_MIN_Std_Dev_RAD = Math .toRadians (1.2 );
246- public static final double AVERAGE_VELOCITY_RAD_PER_SEC_DURING_TEST = Math .toRadians (60 );
247-
248- public static final int SIMULATION_TICKS_IN_1_PERIOD = 5 ;
249- }
250-
251173 public static final ModuleConfig [] moduleConfigs =
252174 new ModuleConfig [] {
253175 new ModuleConfig (
0 commit comments