|
7 | 7 | import edu.wpi.first.wpilibj.DriverStation; |
8 | 8 | import frc.robot.config.FlywheelConfig; |
9 | 9 | import java.util.Optional; |
| 10 | +import org.apache.commons.math3.stat.*; |
| 11 | +import org.apache.commons.math3.stat.regression.SimpleRegression; |
10 | 12 |
|
11 | 13 | public class ShotCalculator { |
12 | 14 | /* Calculation Methods */ |
| 15 | + // Calculate variable shot |
13 | 16 | public static double calculateFlywheelShot(Translation2d robotPosition) { |
14 | 17 | // 1. Calculate distance between goal and robot position |
15 | 18 | double distanceToGoal = calculateHubPosition().getDistance(robotPosition); |
16 | | - // 2. Retrieve correlating RPS from map |
| 19 | + // 2. Retrieve correlating RPS from map based off of distance |
| 20 | + if (distanceToGoal > Units.inchesToMeters(87) || distanceToGoal < Units.inchesToMeters(43)) { |
| 21 | + System.out.println(getRPM(distanceToGoal)); |
| 22 | + return getRPM(distanceToGoal); |
| 23 | + } |
| 24 | + System.out.println(DISTANCE_TO_FLYWHEEL.get(distanceToGoal)); |
17 | 25 | return DISTANCE_TO_FLYWHEEL.get(distanceToGoal); |
18 | 26 | } |
19 | 27 |
|
| 28 | + // Determine if flywheel should be running before active period and run at mid level speed |
20 | 29 | public static double calculateFlywheelDefaultShot(Translation2d robotPosition) { |
21 | 30 | // 1. Determine if within shooter run period (five seconds before or during active period) |
22 | 31 | if (shouldRunShooter(5)) { |
@@ -144,8 +153,26 @@ public static boolean shouldRunShooter(double graceSeconds) { |
144 | 153 | DISTANCE_TO_FLYWHEEL.put(Units.inchesToMeters(141), 70.0); |
145 | 154 | DISTANCE_TO_FLYWHEEL.put(Units.inchesToMeters(90), 60.0); |
146 | 155 | DISTANCE_TO_FLYWHEEL.put(Units.inchesToMeters(61), 50.0); |
147 | | - DISTANCE_TO_FLYWHEEL.put(Units.inchesToMeters(43), 40.0); |
| 156 | + DISTANCE_TO_FLYWHEEL.put(Units.inchesToMeters(43), 47.0); |
148 | 157 | DISTANCE_TO_FLYWHEEL.put(Units.inchesToMeters(74), 50.0); |
149 | 158 | DISTANCE_TO_FLYWHEEL.put(Units.inchesToMeters(134), 65.0); |
150 | 159 | } |
| 160 | + |
| 161 | + // Distance (m) -> Speed (RPS) |
| 162 | + private static final SimpleRegression regression = new SimpleRegression(); |
| 163 | + |
| 164 | + // Set inputs |
| 165 | + static { |
| 166 | + regression.addData(Units.inchesToMeters(174), 87.0); |
| 167 | + regression.addData(Units.inchesToMeters(141), 70.0); |
| 168 | + regression.addData(Units.inchesToMeters(90), 60.0); |
| 169 | + regression.addData(Units.inchesToMeters(61), 50.0); |
| 170 | + regression.addData(Units.inchesToMeters(43), 47.0); |
| 171 | + regression.addData(Units.inchesToMeters(74), 50.0); |
| 172 | + regression.addData(Units.inchesToMeters(134), 65.0); |
| 173 | + } |
| 174 | + |
| 175 | + public static double getRPM(double distance) { |
| 176 | + return regression.getSlope() * distance + regression.getIntercept(); |
| 177 | + } |
151 | 178 | } |
0 commit comments