From 01207015f8576c675710e4fc60ec34cec5bf3116 Mon Sep 17 00:00:00 2001 From: Vivian Qi Date: Sun, 16 Nov 2025 11:54:07 -0500 Subject: [PATCH 1/2] added comments to clarify how encoder conversion factors work --- src/main/java/frc/robot/subsystems/Drivetrain.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/Drivetrain.java b/src/main/java/frc/robot/subsystems/Drivetrain.java index b821bd1..3603859 100644 --- a/src/main/java/frc/robot/subsystems/Drivetrain.java +++ b/src/main/java/frc/robot/subsystems/Drivetrain.java @@ -23,9 +23,15 @@ public class Drivetrain extends SubsystemBase { private final SparkClosedLoopController motorRightClosedLoopController; private final SparkClosedLoopController motorLeftClosedLoopController; - + + /* 8 inches for diameter of wheel + multiplied by pi to get circumference + 10/52 is the gear ratio for the motor gear and gear it's connected to + 30/68 is the gear ratio for the last two gears */ private final Distance ENCODER_POSITION_FACTOR = Inches.of(8 * Math.PI * (10./52.) * (30./68.)); - private final Distance ENCODER_VELOCITY_FACTOR = Inches.of((8 * Math.PI * (10./52.) * (30./68.)) / 60.0); //inches per rotation + + //distance divided by 60 to get velocity in inches per rotations + private final Distance ENCODER_VELOCITY_FACTOR = Inches.of(ENCODER_POSITION_FACTOR.in(Inches) / 60.0); private final double drivetrainP = 0.08; From 2ebc22cf6cc9e4575129ac424d202900358e6de1 Mon Sep 17 00:00:00 2001 From: Vivian Qi Date: Mon, 17 Nov 2025 18:45:32 -0500 Subject: [PATCH 2/2] added position and encoder conversion factors --- src/main/java/frc/robot/subsystems/Drivetrain.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/Drivetrain.java b/src/main/java/frc/robot/subsystems/Drivetrain.java index 3603859..d934c82 100644 --- a/src/main/java/frc/robot/subsystems/Drivetrain.java +++ b/src/main/java/frc/robot/subsystems/Drivetrain.java @@ -15,6 +15,8 @@ import edu.wpi.first.units.measure.LinearVelocity; import edu.wpi.first.wpilibj2.command.SubsystemBase; + + public class Drivetrain extends SubsystemBase { private SparkMax rightFront = new SparkMax (3, SparkLowLevel.MotorType.kBrushless); private SparkMax leftFront = new SparkMax (1, SparkLowLevel.MotorType.kBrushless); @@ -28,10 +30,14 @@ public class Drivetrain extends SubsystemBase { multiplied by pi to get circumference 10/52 is the gear ratio for the motor gear and gear it's connected to 30/68 is the gear ratio for the last two gears */ - private final Distance ENCODER_POSITION_FACTOR = Inches.of(8 * Math.PI * (10./52.) * (30./68.)); + private final double WHEEL_CIRCUMFERENCE = 8 * Math.PI; + private final double MOTOR_GEAR_REDUCTION = (10./52.); + private final double FINAL_TWO_GEAR_REDUCTION = (30./68.); + + private final Distance ENCODER_POSITION_FACTOR = Inches.of(WHEEL_CIRCUMFERENCE * MOTOR_GEAR_REDUCTION * FINAL_TWO_GEAR_REDUCTION); - //distance divided by 60 to get velocity in inches per rotations - private final Distance ENCODER_VELOCITY_FACTOR = Inches.of(ENCODER_POSITION_FACTOR.in(Inches) / 60.0); + //distance divided by 60 to get velocity in inches per second + private final Distance ENCODER_VELOCITY_FACTOR = Inches.of(ENCODER_POSITION_FACTOR.in(Inches)).divide(60); private final double drivetrainP = 0.08;