Skip to content

Commit

Permalink
started adding code for getting closest note (based on target area)
Browse files Browse the repository at this point in the history
  • Loading branch information
PGgit08 committed Mar 26, 2024
1 parent e3a91b3 commit cb38c33
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
36 changes: 34 additions & 2 deletions src/main/java/frc/robot/subsystems/VisionSubsystem.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* Copyright (C) 2024 Team 334. All Rights Reserved.*/
package frc.robot.subsystems;

import java.util.Collections;
import java.util.Comparator;
import java.util.Optional;

import javax.swing.text.html.Option;
Expand Down Expand Up @@ -183,8 +185,38 @@ public double[] tagAngleOffsets(int ID) {
}

public double[] getNoteAngles() {
JsonNode target = _intake.getNeuralTarget();
double[] angles = {target.get("tx").asDouble(), target.get("ty").asDouble()};
ArrayNode targets = _intake.getNeuralTargets();

// Collections.sort(
// targets, new Comparator() {
// @Override
// public int compare(JsonNode noteA, JsonNode noteB) {
// double noteA_area = noteA.get("ta").asDouble();
// double noteB_area = noteB.get("ta").asDouble();

// if (noteA_area > noteB_area) {
// return 1;
// }

// if (noteB_area > noteA_area) {
// return -1;
// }

// else {
// return 0;
// }
// }
// }
// );

// return {0, 0};

JsonNode target = targets.get(0);

double[] angles = {
target.get("tx").asDouble(),
target.get("ty").asDouble()
};

return angles;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/frc/robot/utils/helpers/LimelightHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public JsonNode getJson() {
}

/**
* Returns the neural target from the limelight.
* Returns the neural targets from the limelight.
*
*/
public JsonNode getNeuralTarget() {
public ArrayNode getNeuralTargets() {
ArrayNode targets = (ArrayNode) getJson().get("Results").get("Detector");

return targets.get(0);
return targets;
}

/**
Expand Down

0 comments on commit cb38c33

Please sign in to comment.