Skip to content

Commit 013f24e

Browse files
committed
Enhance HoodedShooterSupersystem with ShooterDataPoint class and interpolation logic
1 parent a930ec7 commit 013f24e

File tree

3 files changed

+71
-17
lines changed

3 files changed

+71
-17
lines changed

src/main/java/frc/robot/Subsystems/HoodedShooterSupersystem/HoodedShooterSupersystem.java

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,50 @@
11
package frc.robot.Subsystems.HoodedShooterSupersystem;
22

33
import static edu.wpi.first.units.Units.Degrees;
4+
import static edu.wpi.first.units.Units.Meters;
5+
import static edu.wpi.first.units.Units.RotationsPerSecond;
46
import static frc.robot.Subsystems.HoodedShooterSupersystem.HoodedShooterSupersystemConstants.*;
5-
6-
import edu.wpi.first.math.interpolation.InterpolatingDoubleTreeMap;
7+
import java.util.List;
78
import edu.wpi.first.units.measure.Angle;
89
import edu.wpi.first.units.measure.AngularVelocity;
10+
import edu.wpi.first.units.measure.Distance;
911
import frc.robot.Subsystems.AdjustableHood.AdjustableHood;
1012
import frc.robot.Subsystems.Shooter.Shooter;
1113
import org.littletonrobotics.junction.Logger;
1214
import org.team7525.subsystem.Subsystem;
1315

16+
class ShooterDataPoint {
17+
private AngularVelocity speed;
18+
private Angle angle;
19+
private Distance distance;
20+
21+
public ShooterDataPoint(AngularVelocity speed, Angle angle, Distance distance) {
22+
this.speed = speed;
23+
this.angle = angle;
24+
this.distance = distance;
25+
}
26+
27+
public AngularVelocity getSpeed() {
28+
return speed;
29+
}
30+
31+
public Angle getAngle() {
32+
return angle;
33+
}
34+
35+
public Distance getDistance() {
36+
return distance;
37+
}
38+
}
39+
1440
public class HoodedShooterSupersystem extends Subsystem<HoodedShooterSupersystemStates> {
1541

1642
private static HoodedShooterSupersystem instance;
1743
private AdjustableHood hood;
1844
private Shooter shooter;
19-
private InterpolatingDoubleTreeMap hoodCalculator;
45+
private int dataLength;
46+
private List<ShooterDataPoint> shots;
47+
private ShooterDataPoint currentShot;
2048

2149
public static HoodedShooterSupersystem getInstance() {
2250
if (instance == null) {
@@ -29,16 +57,18 @@ private HoodedShooterSupersystem() {
2957
super(SUBSYSTEM_NAME, HoodedShooterSupersystemStates.IDLE);
3058
hood = AdjustableHood.getInstance();
3159
shooter = Shooter.getInstance();
32-
hoodCalculator = new InterpolatingDoubleTreeMap();
33-
for (int i = 0; i < ANGLES.length; i++) {
34-
hoodCalculator.put(DISTANCES[i], ANGLES[i]);
35-
}
60+
dataLength = SHOOTER_DATA_POINTS.size() - 1;
61+
shots = SHOOTER_DATA_POINTS;
62+
currentShot = null;
3663
}
3764

3865
@Override
3966
public void runState() {
4067
hood.setState(getState().getAdjustableHoodState());
4168
shooter.setState(getState().getShooterState());
69+
if (getState() == HoodedShooterSupersystemStates.DYNAMIC){
70+
currentShot = interpolateShotValues(Limelight.getInstance().getDistanceToTarget());
71+
}
4272

4373
hood.periodic();
4474
shooter.periodic();
@@ -55,12 +85,29 @@ public boolean readyToShoot() {
5585
return hood.atSetpoint() && shooter.atSetpoint();
5686
}
5787

58-
public Angle calculateHoodSetpoint() {
59-
// ZERO is placeholder for logic to get distance from the target.
60-
return Degrees.of(hoodCalculator.get((double) 0));
61-
}
88+
public ShooterDataPoint interpolateShotValues(Distance targetDistance) {
89+
shots.sort((a, b) -> a.getDistance().compareTo(b.getDistance()));
90+
for (int i = 0; i < dataLength; i++) {
91+
ShooterDataPoint s1 = shots.get(i);
92+
ShooterDataPoint s2 = shots.get(i + 1);
6293

63-
public AngularVelocity calculateShooterSetpoint() {
64-
return MEDIUM_SPEED;
94+
if (targetDistance.in(Meters) >= s1.getDistance().in(Meters) && targetDistance.in(Meters) <= s2.getDistance().in(Meters)) {
95+
96+
double ratio = (targetDistance.in(Meters) - s1.getDistance().in(Meters)) /
97+
(s2.getDistance().in(Meters) - s1.getDistance().in(Meters));
98+
// Interpolate speed
99+
double interpolatedSpeedValue = s1.getDistance().in(Meters)
100+
+ ratio * (s1.getSpeed().in(RotationsPerSecond) - s1.getSpeed().in(RotationsPerSecond));
101+
AngularVelocity interpolatedSpeed = RotationsPerSecond.of(interpolatedSpeedValue);
102+
// Interpolate angle
103+
double interpolatedAngleValue = s1.getAngle().in(Degrees)
104+
+ ratio * (s2.getAngle().in(Degrees) - s1.getAngle().in(Degrees));
105+
Angle interpolatedAngle = Degrees.of(interpolatedAngleValue);
106+
107+
// Set states
108+
return new ShooterDataPoint(interpolatedSpeed, interpolatedAngle, targetDistance); // Successful interpolation
109+
}
110+
}
111+
return null;
65112
}
66113
}

src/main/java/frc/robot/Subsystems/HoodedShooterSupersystem/HoodedShooterSupersystemConstants.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package frc.robot.Subsystems.HoodedShooterSupersystem;
22

3+
import static edu.wpi.first.units.Units.Degrees;
4+
import static edu.wpi.first.units.Units.Meters;
35
import static edu.wpi.first.units.Units.RotationsPerSecond;
6+
import java.util.List;
47

58
import edu.wpi.first.units.measure.AngularVelocity;
69

@@ -14,6 +17,10 @@ public class HoodedShooterSupersystemConstants {
1417
public static final AngularVelocity MEDIUM_SPEED = RotationsPerSecond.of(1500);
1518

1619
// Random values and stuff
17-
public static final double[] ANGLES = { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90 };
18-
public static final double[] DISTANCES = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
20+
public static final List<ShooterDataPoint> SHOOTER_DATA_POINTS = List.of(
21+
new ShooterDataPoint(RotationsPerSecond.of(1500), Degrees.of(30), Meters.of(2.0)),
22+
new ShooterDataPoint(RotationsPerSecond.of(2000), Degrees.of(35), Meters.of(3.0)),
23+
new ShooterDataPoint(RotationsPerSecond.of(2500), Degrees.of(40), Meters.of(3.5)),
24+
new ShooterDataPoint(RotationsPerSecond.of(3000), Degrees.of(45), Meters.of(4.0))
25+
);
1926
}

vendordeps/maple-sim.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"fileName": "maple-sim.json",
33
"name": "maplesim",
4-
"version": "0.3.11",
4+
"version": "0.3.14",
55
"frcYear": "2025",
66
"uuid": "c39481e8-4a63-4a4c-9df6-48d91e4da37b",
77
"mavenUrls": [
@@ -13,7 +13,7 @@
1313
{
1414
"groupId": "org.ironmaple",
1515
"artifactId": "maplesim-java",
16-
"version": "0.3.11"
16+
"version": "0.3.14"
1717
},
1818
{
1919
"groupId": "org.dyn4j",

0 commit comments

Comments
 (0)