}
SmartDashboard.putData("Turret Mech", mech);
+
+ // 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.GEAR_RATIO;
+
+ //Sets the initial motor position
+ motor.setPosition(motorRotations);
+
}
/* ---------------- Public API ---------------- */
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 = TurretConstants.EXTRAPOLATION_TIME_CONSTANT;
double futureRobotAngle = goalAngle.getRadians() + (goalVelocityRadPerSec * lookAheadSeconds);