Skip to content

Commit bc67026

Browse files
add fuel depth functions
1 parent 5c4f9b9 commit bc67026

4 files changed

Lines changed: 32 additions & 1 deletion

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
public class FuelCluster {
66
public ArrayList<FuelSquare> fuelSquares = new ArrayList<>(0);
7+
public double clusterDepth;
78

89
public FuelCluster() {
910

@@ -21,4 +22,14 @@ public void addFuelSquare(FuelSquare square) {
2122
fuelSquares.add(square);
2223
square.addToCluster(this);
2324
}
25+
26+
public double averageSquareDepth() {
27+
int size = fuelSquares.size();
28+
double sum = 0;
29+
for(int i = 0; i < size; i++) {
30+
sum += fuelSquares.get(i).averageDepth;
31+
}
32+
sum /= size;
33+
return sum;
34+
}
2435
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class FuelCoordinates {
1010
public double boxY2;
1111
public double width;
1212
public double height;
13+
public double depth;
1314

1415
public FuelCoordinates(double x, double y, double boxWidth, double boxHeight, double c) {
1516
boxX = x;
@@ -19,6 +20,7 @@ public FuelCoordinates(double x, double y, double boxWidth, double boxHeight, do
1920
computeCenterPoint(boxX, boxY, boxX2, boxY2);
2021
width = boxWidth;
2122
height = boxHeight;
23+
computeDepth(45); //TODO: replace 45 with constant for camera FOV
2224
chance = c;
2325
}
2426
private static double pointFromDistance(double point, double length) {
@@ -34,4 +36,8 @@ public void assignSelfToFuelSquare(int gridWidth, int gridHeight, FuelSquare[][]
3436
int squareY = (int) Math.round(centerY / gridHeight);
3537
squareArray[squareX][squareY].addFuel(this);
3638
}
39+
//TODO: implement depth function
40+
public double computeDepth(double cameraFOV) {
41+
return 0.0;
42+
}
3743
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public void periodic() {
1313

1414
//Implement when Limelight/camera detection is actually working
1515
}
16+
1617
public ArrayList<FuelCoordinates> filterByHighChance(FuelCoordinates[] inputs) {
1718
//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.
1819
ArrayList<FuelCoordinates> output = new ArrayList<>(0);
@@ -23,6 +24,7 @@ public ArrayList<FuelCoordinates> filterByHighChance(FuelCoordinates[] inputs) {
2324
}
2425
return output;
2526
}
27+
2628
public FuelSquare[][] divideIntoSquares(ArrayList<FuelCoordinates> fuelCoords, int gridWidth, int gridHeight) {
2729
FuelSquare[][] output = new FuelSquare[gridWidth][gridHeight];
2830
for(int w = 0; w < output.length; w++) {
@@ -35,6 +37,7 @@ public FuelSquare[][] divideIntoSquares(ArrayList<FuelCoordinates> fuelCoords, i
3537
}
3638
return output;
3739
}
40+
3841
public ArrayList<FuelCluster> getFuelClusters(FuelSquare[][] fuelSquares) {
3942
ArrayList<FuelCluster> clusters = new ArrayList<>(0);
4043
int width = fuelSquares.length;
@@ -53,7 +56,7 @@ public ArrayList<FuelCluster> getFuelClusters(FuelSquare[][] fuelSquares) {
5356
fuelSquares[w][h - 1].cluster.addFuelSquare(fuelSquare);
5457
} else {
5558
FuelCluster c = new FuelCluster(fuelSquare);
56-
clusters.add(new FuelCluster(fuelSquare));
59+
clusters.add(c);
5760
}
5861
}
5962
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class FuelSquare {
1313
public boolean isInFuelCluster = false;
1414
public FuelCluster cluster;
1515

16+
public double averageDepth;
17+
1618
private int fuelCount = 0;
1719

1820
public FuelSquare(int x, int y, double width, double height) {
@@ -42,4 +44,13 @@ public void addToCluster(FuelCluster c) {
4244
isInFuelCluster = true;
4345
cluster = c;
4446
}
47+
public double averageFuelDepth() {
48+
int size = fuelList.size();
49+
double sum = 0;
50+
for(int i = 0; i < size; i++) {
51+
sum += fuelList.get(i).depth;
52+
}
53+
sum /= size;
54+
return sum;
55+
}
4556
}

0 commit comments

Comments
 (0)