Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
0336b4c
some small stuff
Levercpu Mar 22, 2025
416b040
MORE linear algebra
Levercpu Mar 22, 2025
c27a848
find quaternions are better
Levercpu Mar 22, 2025
848990e
for loops are better
Levercpu Mar 22, 2025
cc499ae
fixed
Levercpu Mar 22, 2025
99f5a8c
linter
Levercpu Mar 22, 2025
49d1967
corrected for api
Levercpu Mar 22, 2025
49da7b6
fixed some sutff
Levercpu Mar 22, 2025
da456e9
made code more maintanable and stuff
Levercpu Mar 22, 2025
2e4df64
all linear algebra now
Levercpu Mar 22, 2025
f649214
linter
Levercpu Mar 22, 2025
fd5830a
more generilization
Levercpu Mar 22, 2025
1292172
EA SPORTS
Levercpu Mar 22, 2025
47fe8e0
fixed
Levercpu Mar 23, 2025
a302451
added limelight
Levercpu Mar 23, 2025
baca8c9
small changes
Levercpu Mar 23, 2025
1926177
added colors
Levercpu Mar 23, 2025
a2cdbdc
fixed reflecton issue
Levercpu Mar 23, 2025
6cf0016
fixed reflecton issue
Levercpu Mar 23, 2025
69cdd68
fixed reflecton issue
Levercpu Mar 23, 2025
8f331ef
small pr fixed
Levercpu Mar 24, 2025
0a0dbe7
made only check closest and neighboring algae, coral.
Levercpu Mar 24, 2025
61dc0a2
made unit tests (#295)
noahheller Mar 24, 2025
5d2e9ab
Merge branch 'main' of https://github.com/FRC4048/FRC2025_Java into L…
Levercpu Mar 24, 2025
035c70b
fixed noah's pr comments
Levercpu Mar 24, 2025
e50b0e7
small fix and linter
Levercpu Mar 24, 2025
671981a
small fix and linter
Levercpu Mar 24, 2025
2a1e4d1
fixed some pr
Levercpu Mar 25, 2025
edb20ed
fixed some pr
Levercpu Mar 25, 2025
6573d07
Nh limelight (#298)
noahheller Mar 25, 2025
b41c8a7
small pr fixed, changed from radians to degrees
Levercpu Mar 25, 2025
30003bc
small changes
Levercpu Mar 25, 2025
ae91005
last
Levercpu Mar 25, 2025
d4660c5
last
Levercpu Mar 25, 2025
e21394d
last
Levercpu Mar 25, 2025
6d565ac
fixed
Levercpu Mar 25, 2025
bd584a2
done
Levercpu Mar 25, 2025
639624d
unit test
Mar 25, 2025
2e1a40f
fixed algae to be more consistent
Levercpu Mar 25, 2025
4bdc724
Merge remote-tracking branch 'origin/LS_MATHZ' into LS_MATHZ
Mar 25, 2025
2d20b22
fixed out of range
Levercpu Mar 25, 2025
939cbb7
Merge remote-tracking branch 'origin/LS_MATHZ' into LS_MATHZ
Mar 25, 2025
cec8d79
use Math.floorMod() because % does not work with negatives in java
Mar 25, 2025
b06c20d
omg it works!!!!
Mar 26, 2025
c6f47d5
removed limelight feed
Mar 26, 2025
f733205
added more tests
Mar 26, 2025
e4f0ad5
built code
Mar 26, 2025
e3bc5f9
fixed some pr
Levercpu Mar 26, 2025
e9c5c97
added some small stuff
Levercpu Mar 26, 2025
81373b6
added some "reasonable" estimates for what the constants should be
Levercpu Mar 27, 2025
0564e2d
linter
Levercpu Mar 27, 2025
50a4185
merged
Levercpu Mar 27, 2025
e727b60
fixed build and lint
Levercpu Mar 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,6 @@ public RobotVisualizer getRobotVisualizer() {
}

public void putShuffleboardCommands() {

if (Constants.CORAL_DEBUG) {
SmartDashboard.putData(
"Shoot Coral", new ShootCoral(coralSubsystem, Constants.CORAL_SHOOTER_SPEED));
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/frc/robot/constants/GameConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ public enum Mode {
new Transform3d(
0.3429, -0.0635, 0, new Rotation3d(0.0, (-47 * Math.PI) / 180, 0.0)); // z = 0.720725
public static final String LIMELIGHT_IP_ADDRESS = "10.40.48.104"; // TODO Change Later
public static final double MINIMUM_PIECE_DETECTION_DOT = 0;
public static final double MINIMUM_PIECE_DETECTION_DOT = 0.5;
public static final double PIECE_DETECTION_PROBABILITY_SCALAR = 0.195571; // TODO: change later
public static final double MINUMUM_PIECE_DETECTION_CONFIRMED_DOT = 0.8;
public static final double DECAY_CONSTANT = 1.0002; // TODO: change later
public static final boolean ENABLE_FANCY_LIMELIGHT_MATH = false;
}
44 changes: 35 additions & 9 deletions src/main/java/frc/robot/subsystems/limelight/Vision.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

package frc.robot.subsystems.limelight;

import edu.wpi.first.math.Matrix;
import edu.wpi.first.math.Nat;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.numbers.N1;
import edu.wpi.first.math.numbers.N12;
import edu.wpi.first.math.numbers.N6;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.constants.AlgaePositions;
import frc.robot.constants.BranchPositions;
Expand All @@ -18,7 +23,9 @@
public class Vision extends SubsystemBase {
LoggableSystem<VisionIO, VisionInputs> system;
private final Supplier<Pose2d> pose2dSupplier;
Matrix<N12, N1> algaeConfidences = new Matrix<N12, N1>(Nat.N12(), Nat.N1(), new double[12]);
ArrayList<AlgaePositions> currentAlgaePosition = new ArrayList<>();
Matrix<N6, N6> coralConfidences = new Matrix<N6, N6>(Nat.N6(), Nat.N6(), new double[36]);
ArrayList<BranchPositions> currentCoralPositions = new ArrayList<>();

public Vision(VisionIO io, Supplier<Pose2d> pose2dSupplier) {
Expand Down Expand Up @@ -59,6 +66,8 @@ public void periodic() {
locateGamePieces();
Logger.recordOutput("coralPoses", getAllBranchPosition());
Logger.recordOutput("algaePoses", getAllAlgaePosition());
algaeConfidences.elementPower(Constants.DECAY_CONSTANT);
coralConfidences.elementPower(Constants.DECAY_CONSTANT);
}
}

Expand All @@ -71,19 +80,36 @@ private void locateGamePieces() {
}
for (int i = 0; i < detectionLength; i++) {
String className = system.getInputs().className[i];
if (className.equalsIgnoreCase("coral")) {
BranchPositions coralBranch =
if (className.equalsIgnoreCase("algae")) {
double[] returnArray =
GamePieceLocate.findCoralBranch(
pose2dSupplier.get(), system.getInputs().tx[i], system.getInputs().ty[i]);
if (coralBranch != null) {
currentCoralPositions.add(coralBranch);
AlgaePositions algaePos = AlgaePositions.values()[(int) returnArray[0]];
algaeConfidences.set(
(int) returnArray[0],
1,
(algaeConfidences.get((int) (returnArray[0]), 1)
+ Math.pow(returnArray[2], 3)
* Math.pow(returnArray[1], 2)
* Constants.PIECE_DETECTION_PROBABILITY_SCALAR));
if (algaeConfidences.get((int) (returnArray[0] / 6), (int) (returnArray[0] % 6))
> Constants.MINUMUM_PIECE_DETECTION_CONFIRMED_DOT) {
currentAlgaePosition.add(algaePos);
}
} else if (className.equalsIgnoreCase("algae")) {
AlgaePositions algaePos =
GamePieceLocate.findAlgaePos(
} else if (className.equalsIgnoreCase("coral")) {
double[] returnArray =
GamePieceLocate.findCoralBranch(
pose2dSupplier.get(), system.getInputs().tx[i], system.getInputs().ty[i]);
if (algaePos != null) {
currentAlgaePosition.add(algaePos);
BranchPositions coralBranch = BranchPositions.values()[(int) returnArray[0]];
coralConfidences.set(
((int) returnArray[0]) / 6,
((int) returnArray[1]) % 6,
Math.pow(returnArray[2], 3)
* Math.pow(returnArray[1], 2)
* Constants.PIECE_DETECTION_PROBABILITY_SCALAR);
if (coralConfidences.get((int) (returnArray[0] / 6), (int) (returnArray[0] % 6))
> Constants.MINUMUM_PIECE_DETECTION_CONFIRMED_DOT) {
currentCoralPositions.add(coralBranch);
}
}
}
Expand Down
34 changes: 25 additions & 9 deletions src/main/java/frc/robot/utils/GamePieceLocate.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class GamePieceLocate {
.toArray(Vector[]::new);

// piece pos is in DEGREES, not RD
public static BranchPositions findCoralBranch(
public static double[] findCoralBranch(
Pose2d robotPos, double piecePosTXDeg, double piecePosTYDeg) {
final Pose3d cameraPos = new Pose3d(robotPos).transformBy(Constants.LIMELIGHT_TO_ROBOT);
final Vector<N3> cameraPosVec = cameraPos.getTranslation().toVector();
Expand All @@ -40,8 +40,10 @@ public static BranchPositions findCoralBranch(
Math.tan(Math.toRadians(piecePosTYDeg)))
.unit();
double maxDot = Constants.MINIMUM_PIECE_DETECTION_DOT;
BranchPositions closest = null;
int n = CenterPositions.getClosest(robotPos);
int maxf = 0;
double secondDot = Constants.MINIMUM_PIECE_DETECTION_DOT;
double[] returnArray = new double[3];
for (int i = 6 * n - 3; i < 6 * n + 9; i++) {
int f = Math.floorMod(i, BRANCHES.length);
Matrix<N3, N1> locationVec =
Expand All @@ -51,17 +53,22 @@ public static BranchPositions findCoralBranch(
VecBuilder.fill(locationVec.get(0, 0), locationVec.get(1, 0), locationVec.get(2, 0))
.unit());
if (dot > maxDot) {
secondDot = maxDot;
maxDot = dot;
closest = BRANCHES[f];
maxf = f;
}
if (dot > secondDot && dot != maxDot) {
secondDot = dot;
}
}

return closest;
returnArray[0] = maxf;
returnArray[1] = maxDot - secondDot;
returnArray[2] = maxDot;
return returnArray;
}

// piece pos is in DEGREES, not RD
public static AlgaePositions findAlgaePos(
Pose2d robotPos, double piecePosTXDeg, double piecePosTYDeg) {
public static double[] findAlgaePos(Pose2d robotPos, double piecePosTXDeg, double piecePosTYDeg) {
final Pose3d cameraPos = new Pose3d(robotPos).transformBy(Constants.LIMELIGHT_TO_ROBOT);
final Vector<N3> cameraPosVec = cameraPos.getTranslation().toVector();
final Matrix<N3, N3> invCameraRotation = cameraPos.getRotation().unaryMinus().toMatrix();
Expand All @@ -74,6 +81,9 @@ public static AlgaePositions findAlgaePos(
double maxDot = Constants.MINIMUM_PIECE_DETECTION_DOT;
AlgaePositions closest = null;
int n = CenterPositions.getClosest(robotPos);
int maxf = 0;
double secondDot = Constants.MINIMUM_PIECE_DETECTION_DOT;
double[] returnArray = new double[3];
for (int i = 2 * n - 2; i < 2 * n + 4; i++) {
int f = Math.floorMod(i, ALGAES.length);
Matrix<N3, N1> locationVec =
Expand All @@ -83,10 +93,16 @@ public static AlgaePositions findAlgaePos(
VecBuilder.fill(locationVec.get(0, 0), locationVec.get(1, 0), locationVec.get(2, 0))
.unit());
if (dot > maxDot) {
secondDot = maxDot;
maxDot = dot;
closest = ALGAES[f];
maxf = f;
} else if (dot > secondDot && dot != maxDot) {
secondDot = dot;
}
}
return closest;
returnArray[0] = maxf;
returnArray[1] = maxDot - secondDot;
returnArray[2] = maxDot;
return returnArray;
}
}
20 changes: 16 additions & 4 deletions src/test/java/frc/robot/utils/GamePieceLocateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,37 @@ void findAlgaePos() {
double txDeg = 0; // degrees
double dyDeg = -5; // degrees
AlgaePositions algaePos =
GamePieceLocate.findAlgaePos(new Pose2d(robotX, robotY, new Rotation2d(0)), txDeg, dyDeg);
AlgaePositions.values()[
(int)
GamePieceLocate.findAlgaePos(
new Pose2d(robotX, robotY, new Rotation2d(0)), txDeg, dyDeg)[0]];
assertEquals(AlgaePositions.Algae_AB_LOW, algaePos);

txDeg = 0; // degrees
dyDeg = 20; // degrees
algaePos =
GamePieceLocate.findAlgaePos(new Pose2d(robotX, robotY, new Rotation2d(0)), txDeg, dyDeg);
AlgaePositions.values()[
(int)
GamePieceLocate.findAlgaePos(
new Pose2d(robotX, robotY, new Rotation2d(0)), txDeg, dyDeg)[0]];
assertEquals(AlgaePositions.Algae_AB_HIGH, algaePos);

txDeg = 10; // degrees
dyDeg = 0; // degrees
algaePos =
GamePieceLocate.findAlgaePos(new Pose2d(robotX, robotY, new Rotation2d(0)), txDeg, dyDeg);
AlgaePositions.values()[
(int)
GamePieceLocate.findAlgaePos(
new Pose2d(robotX, robotY, new Rotation2d(0)), txDeg, dyDeg)[0]];
assertEquals(AlgaePositions.Algae_CD_LOW, algaePos);

txDeg = -10; // degrees
dyDeg = 0; // degrees
algaePos =
GamePieceLocate.findAlgaePos(new Pose2d(robotX, robotY, new Rotation2d(0)), txDeg, dyDeg);
AlgaePositions.values()[
(int)
GamePieceLocate.findAlgaePos(
new Pose2d(robotX, robotY, new Rotation2d(0)), txDeg, dyDeg)[0]];
assertEquals(AlgaePositions.Algae_KL_LOW, algaePos);
}
}