public void periodic() {
updateInputs();
Logger.processInputs("Turret", inputs);
-
+
+ // Do this for both encoders in the constructor
+ double leftPosition = encoderLeft.getAbsolutePosition().getValueAsDouble();
+
+ double leftAbs = wrapUnit(leftPosition - TurretConstants.LEFT_ENCODER_OFFSET);
+
+ double rightPosition = encoderRight.getAbsolutePosition().getValueAsDouble();
+
+ double rightAbs = wrapUnit(rightPosition - TurretConstants.RIGHT_ENCODER_OFFSET);
+
+ int leftTooth = (int) Math.round(leftAbs * TurretConstants.LEFT_ENCODER_TEETH)
+ % TurretConstants.LEFT_ENCODER_TEETH;
+ //SmartDashboard.putNumber("Left Tooth", leftTooth);
+
+ int rightTooth = (int) Math.round(rightAbs * TurretConstants.RIGHT_ENCODER_TEETH)
+ % TurretConstants.RIGHT_ENCODER_TEETH;
+ //SmartDashboard.putNumber("Right Tooth", rightTooth);
+
+ int turretIndex = ChineseRemainderTheorem.solve(leftTooth, TurretConstants.LEFT_ENCODER_TEETH, rightTooth, TurretConstants.RIGHT_ENCODER_TEETH);
+ //SmartDashboard.putNumber("Turret Index", turretIndex);
+
+ double turretRotations = turretIndex / (double) TurretConstants.TURRET_TEETH_COUNT;
+ if(Units.rotationsToDegrees(turretRotations) > 500.0){
+ turretRotations -= Units.degreesToRotations(846.0);
+ }
+ SmartDashboard.putNumber("CRT Position", Units.rotationsToDegrees(turretRotations));
+
+ double motorRotations = turretRotations * TurretConstants.TURRET_GEAR_RATIO;
+
+ //Sets the initial motor position
+ motor.setPosition(motorRotations);
+
// Position extrapolation
- double lookAheadSeconds = EXTRAPOLATION_TIME_CONSTANT;
+ double lookAheadSeconds = TurretConstants.EXTRAPOLATION_TIME_CONSTANT;
double futureRobotAngle = goalAngle.getRadians() + (goalVelocityRadPerSec * lookAheadSeconds);
//Continuous wrap selection
public static int RIGHT_ENCODER_TEETH = 22; // read above
public static int ENCODER_COUNT_TOTAL = 8192; // how many intervals it can have, like clicks on a clock chat gpt explained to me
- public static double LEFT_ENCODER_OFFSET = 9.52; // degrees 9.52 rot
- public static double RIGHT_ENCODER_OFFSET = 6.53; // degrees 6.53 rot
+ public static double LEFT_ENCODER_OFFSET = 0.463379; // rot
+ public static double RIGHT_ENCODER_OFFSET = 0.197266; // rot
+ // Turret is in center of robot, but make use of the height in shooter physics
public static Translation3d DISTANCE_FROM_ROBOT_CENTER = new Translation3d(0,0, Units.inchesToMeters(22.172)); //meters
public static double CRT_TOLERANCE = 0.01;