Skip to content

Commit bd0ae9e

Browse files
Fuel classes, fuel detection algorithm
1 parent 7991afe commit bd0ae9e

3 files changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package frc.robot.subsystems.fuelDetector;
2+
3+
public class FuelCoordinates {
4+
public double chance;
5+
public double centerX;
6+
public double centerY;
7+
public double boxX;
8+
public double boxY;
9+
public double boxX2;
10+
public double boxY2;
11+
public double width;
12+
public double height;
13+
14+
public FuelCoordinates(double x, double y, double boxWidth, double boxHeight, double c) {
15+
boxX = x;
16+
boxY = y;
17+
boxX2 = FuelCoordinates.pointFromDistance(x, boxWidth);
18+
boxY2 = FuelCoordinates.pointFromDistance(y, boxHeight);
19+
computeCenterPoint(boxX, boxY, boxX2, boxY2);
20+
width = boxWidth;
21+
height = boxHeight;
22+
chance = c;
23+
}
24+
private static double pointFromDistance(double point, double length) {
25+
//Get a second point from one point and a distance
26+
return point + length;
27+
}
28+
public void computeCenterPoint(double x, double y, double x2, double y2) {
29+
centerX = (x2 - x) / 2;
30+
centerY = (y2 - y) / 2;
31+
}
32+
public void assignSelfToFuelSquare(int gridWidth, int gridHeight, FuelSquare[][] squareArray) {
33+
int squareX = (int) Math.round(centerX / gridWidth);
34+
int squareY = (int) Math.round(centerY / gridHeight);
35+
squareArray[squareX][squareY].addFuel(this);
36+
}
37+
}

src/main/java/frc/robot/subsystems/fuelDetector/FuelDetector.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package frc.robot.subsystems.fuelDetector;
22

3+
import java.lang.reflect.Array;
4+
import java.util.ArrayList;
5+
36
import edu.wpi.first.wpilibj2.command.SubsystemBase;
47

58
public class FuelDetector extends SubsystemBase {
@@ -14,4 +17,26 @@ public double[][] getFuelClusters() {
1417
};
1518
return output;
1619
}
20+
public ArrayList<FuelCoordinates> filterByHighChance(FuelCoordinates[] inputs) {
21+
//There's probably an easier and shorter way of doing this, but this is simple. Feel free to change it as long as the output doesn't change.
22+
ArrayList<FuelCoordinates> output = new ArrayList<>();
23+
for(int i = 0; i < inputs.length; i++) {
24+
if(inputs[i].chance >= 80.0) {
25+
output.add(inputs[i]);
26+
}
27+
}
28+
return output;
29+
}
30+
public FuelSquare[][] divideIntoSquares(ArrayList<FuelCoordinates> fuelCoords, int gridWidth, int gridHeight) {
31+
FuelSquare[][] output = new FuelSquare[gridWidth][gridHeight];
32+
for(int w = 0; w < output.length; w++) {
33+
for(int h = 0; h < output[w].length; h++) {
34+
output[w][h] = new FuelSquare();
35+
}
36+
}
37+
for(int i = 0; i < fuelCoords.size(); i++) {
38+
fuelCoords.get(i).assignSelfToFuelSquare(gridWidth, gridHeight, output);
39+
}
40+
return output;
41+
}
1742
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package frc.robot.subsystems.fuelDetector;
2+
3+
import java.util.ArrayList;
4+
5+
public class FuelSquare {
6+
public ArrayList<FuelCoordinates> fuelList = new ArrayList<>();
7+
8+
public int gridX;
9+
public int gridY;
10+
public double squareWidth;
11+
public double squareHeight;
12+
13+
public FuelSquare(int x, int y, double width, double height) {
14+
gridX = x;
15+
gridY = y;
16+
squareWidth = width;
17+
squareHeight = height;
18+
}
19+
public FuelSquare() {
20+
21+
}
22+
23+
public void addFuel(FuelCoordinates fuel) {
24+
fuelList.add(fuel);
25+
}
26+
}

0 commit comments

Comments
 (0)