|
1 | | -// package org.ghrobotics.frc2024; |
| 1 | +package org.ghrobotics.frc2024; |
| 2 | + |
| 3 | +import edu.wpi.first.math.interpolation.InterpolatingDoubleTreeMap; |
| 4 | + |
| 5 | +import edu.wpi.first.math.geometry.Pose2d; |
| 6 | +import edu.wpi.first.math.geometry.Rotation2d; |
| 7 | + |
| 8 | + |
| 9 | +public class ShootingPosition { |
| 10 | + |
| 11 | + |
| 12 | + public double distanceToSpeaker(Pose2d robotPose, Pose2d speakerPose) { |
| 13 | + return Math.sqrt(Math.pow(speakerPose.getTranslation().getX() - robotPose.getTranslation().getX(), 2) + Math.pow(speakerPose.getTranslation().getY() - robotPose.getTranslation().getY(), 2)); |
| 14 | + } |
| 15 | + |
| 16 | + public static final InterpolatingDoubleTreeMap SHOOTER_DISTANCE_ANGLE = new InterpolatingDoubleTreeMap(); |
| 17 | + |
| 18 | + /** |
| 19 | + * 1st param is distance |
| 20 | + * 2nd param is armAngle |
| 21 | + */ |
| 22 | + static { |
| 23 | + SHOOTER_DISTANCE_ANGLE.put(0.5, 10.0); // Random Numbers for placeholder |
| 24 | + SHOOTER_DISTANCE_ANGLE.put(0.75, 20.0); |
| 25 | + SHOOTER_DISTANCE_ANGLE.put(1.0, 25.0); |
| 26 | + SHOOTER_DISTANCE_ANGLE.put(1.5, 34.0); |
| 27 | + SHOOTER_DISTANCE_ANGLE.put(2.0, 40.124); |
| 28 | + |
| 29 | + } |
| 30 | + |
2 | 31 |
|
3 | | -// import edu.wpi.first.math.geometry.Pose2d; |
4 | | -// import edu.wpi.first.math.geometry.Rotation2d; |
5 | 32 |
|
6 | | -// public class ShootingPosition { |
7 | 33 |
|
| 34 | + public double speakerAngle() { |
| 35 | + double angle = ShootingPosition.SHOOTER_DISTANCE_ANGLE.get(distanceToSpeaker(null, null)); |
| 36 | + |
| 37 | + // For Safety purposes |
| 38 | + // Set the correct max & min arm angles |
| 39 | + if (angle >= 50 || angle <= 10) { |
| 40 | + angle = 0.0; |
| 41 | + } |
| 42 | + |
| 43 | + return angle; |
| 44 | + } |
| 45 | + |
| 46 | + // public double armAngleToSpeaker() { |
| 47 | + // double angle; |
| 48 | + |
| 49 | + // angle = regressionFormula(distanceToSpeaker(null, null)) |
| 50 | + |
| 51 | + // return angle; |
| 52 | + // } |
| 53 | + |
| 54 | + public class Constants { |
| 55 | + // Red Subwoofer Pose 2d |
| 56 | + public static Pose2d kRedSubwooferPose = new Pose2d(16.5, 5.57, new Rotation2d(0)); |
8 | 57 |
|
9 | | -// public double distanceToSpeaker(Pose2d robotPose, Pose2d speakerPose) { |
10 | | -// return Math.sqrt(Math.pow(speakerPose.getTranslation().getX() - robotPose.getTranslation().getX(), 2) + Math.pow(speakerPose.getTranslation().getY() - robotPose.getTranslation().getY(), 2)); |
11 | | -// } |
12 | | - |
13 | | -// /** |
14 | | -// * Returns expected angle based on distance to speaker |
15 | | -// * @param x Distance to the speaker |
16 | | -// * @return Arm Angle to speaker |
17 | | -// */ |
18 | | -// public double regressionFormula(double x) { |
19 | | -// double y = (10.0286 * Math.log((9.48057 * x) - 8.57204)) + 8.226559; |
20 | | - |
21 | | -// if (y > 50) { |
22 | | -// y = 2; |
23 | | -// } else if (y < 0) { |
24 | | -// y = 2; |
25 | | -// } |
26 | | - |
27 | | -// return y; |
28 | | -// } |
29 | | - |
30 | | -// // public double armAngleToSpeaker() { |
31 | | -// // double angle; |
32 | | - |
33 | | -// // angle = regressionFormula(distanceToSpeaker(null, null)) |
34 | | - |
35 | | -// // return angle; |
36 | | -// // } |
37 | | - |
38 | | -// public class Constants { |
39 | | -// // Red Subwoofer Pose 2d |
40 | | -// public static Pose2d kRedSubwooferPose = new Pose2d(16.5, 5.57, new Rotation2d(0)); |
41 | | - |
42 | | -// // Blue Subwoofer Pose 2d |
43 | | -// public static Pose2d kBlueSubwooferPose = new Pose2d(0.05, 5.57, new Rotation2d(0)); |
44 | | -// } |
45 | | -// } |
| 58 | + // Blue Subwoofer Pose 2d |
| 59 | + public static Pose2d kBlueSubwooferPose = new Pose2d(0.05, 5.57, new Rotation2d(0)); |
| 60 | + } |
| 61 | +} |
0 commit comments