Skip to content

Commit 11005ac

Browse files
committed
Added abstract class for turret angle.
1 parent 5b9149e commit 11005ac

5 files changed

Lines changed: 38 additions & 5 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.team1816.lib.util;
2+
3+
import com.team1816.lib.BaseRobotState;
4+
import edu.wpi.first.math.geometry.Rotation2d;
5+
import edu.wpi.first.math.geometry.Translation2d;
6+
7+
public abstract class BaseShooterCalculator implements IShooterCalculator {
8+
public Rotation2d getTurrentAngle(Translation2d shooter, Translation2d target) {
9+
Translation2d shooterToTargetTranslation2d = target.minus(shooter);
10+
Rotation2d fieldRelativeRotation2dToTarget = shooterToTargetTranslation2d.getAngle();
11+
Rotation2d robotRotation2d = BaseRobotState.robotPose.getRotation();
12+
return fieldRelativeRotation2dToTarget.minus(robotRotation2d);
13+
}
14+
15+
}

src/main/java/com/team1816/lib/util/IShooterCalculator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.team1816.lib.util;
22

3+
import com.team1816.lib.BaseRobotState;
4+
import edu.wpi.first.math.geometry.Rotation2d;
35
import edu.wpi.first.math.geometry.Translation2d;
46

57
public interface IShooterCalculator {

src/main/java/com/team1816/lib/util/ShooterCalculatorResponse.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package com.team1816.lib.util;
22

3+
import edu.wpi.first.math.geometry.Rotation2d;
4+
35
public class ShooterCalculatorResponse {
46
private double inclineAngleDegrees = 0;
57
private double launchVelocityRPS = 0;
8+
private Rotation2d turretAngle = null;
69

7-
ShooterCalculatorResponse(double inclineAngleDegrees, double launchVelocityRPS) {
10+
ShooterCalculatorResponse(Rotation2d turretAngle, double inclineAngleDegrees, double launchVelocityRPS) {
11+
this.turretAngle = turretAngle;
812
this.inclineAngleDegrees = inclineAngleDegrees;
913
this.launchVelocityRPS = launchVelocityRPS;
1014
}
@@ -16,4 +20,8 @@ public double getInclineAngelDegrees() {
1620
public double getLaunchVelocityRPS() {
1721
return launchVelocityRPS;
1822
}
23+
24+
public Rotation2d getTurrentAngle() {
25+
return turretAngle;
26+
}
1927
}

src/main/java/com/team1816/lib/util/ShooterTableCalculator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.team1816.lib.util;
22

3+
import com.team1816.lib.BaseRobotState;
34
import com.team1816.lib.hardware.ShooterSettingsConfig;
45
import edu.wpi.first.math.MathUtil;
6+
import edu.wpi.first.math.geometry.Rotation2d;
57
import edu.wpi.first.math.geometry.Translation2d;
68
import edu.wpi.first.math.util.Units;
79
import org.apache.commons.math3.analysis.interpolation.LinearInterpolator;
@@ -11,7 +13,7 @@
1113

1214
import static com.team1816.lib.Singleton.factory;
1315

14-
public class ShooterTableCalculator implements IShooterCalculator {
16+
public class ShooterTableCalculator extends BaseShooterCalculator {
1517

1618
private final PolynomialSplineFunction inclineAngleRotationsFunction, launchVelocityRPSFunction;
1719

@@ -45,7 +47,7 @@ public ShooterCalculatorResponse getShooterSettings(Translation2d shooter, Trans
4547
double inclineAngleDegrees = Units.rotationsToDegrees(inclineAngleRotations);
4648
double launchVelocityRPS = getLaunchVelocityRPS(distanceToTargetInches);
4749

48-
return new ShooterCalculatorResponse(inclineAngleDegrees, launchVelocityRPS);
50+
return new ShooterCalculatorResponse(getTurrentAngle(shooter, target), inclineAngleDegrees, launchVelocityRPS);
4951
}
5052

5153
private double getInclineAngleRotations(double distanceInches) {

src/main/java/com/team1816/season/subsystems/Shooter.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,14 @@ private void applyState() {
322322

323323
if (autoAimTurret || wantedDistanceState == ShooterDistanceState.AUTOMATIC) {
324324
target = getTargetTranslation2d();
325-
aimTurretAtTarget(target);
326-
aimInclineAndLaunchersAtTarget(target);
325+
ShooterCalculatorResponse response = shooterTableCalculator.getShooterSettings(getCurrentTurretPose2d().getTranslation(),
326+
target, useChassisSpeedForHoodAngleAndSpeed);
327+
328+
double robotRelativeDegreesToTarget = response.getTurrentAngle().getDegrees();
329+
330+
setTurretAngle(robotRelativeDegreesToTarget);
331+
setInclineAngle(response.getInclineAngelDegrees());
332+
setLaunchVelocities(response.getLaunchVelocityRPS());
327333
} else {
328334
setTurretAngle(turretFixedAngleDegrees);
329335
switch (wantedDistanceState) {

0 commit comments

Comments
 (0)