-
Notifications
You must be signed in to change notification settings - Fork 1
records #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
records #10
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,43 +30,22 @@ public class TigerHelpers { | |
|
|
||
| private static final Map<String, DoubleArrayEntry> doubleArrayEntries = new ConcurrentHashMap<>(); | ||
|
|
||
| /** Represents a Limelight Raw Fiducial result from Limelight's NetworkTables output. */ | ||
| public static class RawFiducial { | ||
| /** The id of the april tag */ | ||
| public int id = 0; | ||
|
|
||
| /** | ||
| * The horizontal offset of the target from the Limelight's principle pixel (the images central | ||
| * pixel) in degrees. Positive values mean the target is to the right of the crosshair. | ||
| */ | ||
| public double txnc = 0; | ||
|
|
||
| /** | ||
| * The vertical offset of the target from the Limelight's principle pixel (the images central | ||
| * pixel) in degrees. Positive values mean the target is below the crosshair. | ||
| */ | ||
| public double tync = 0; | ||
|
|
||
| /** | ||
| * The area of the target in the Limelight's view as a percentage of the total image area. So, | ||
| * if the target takes up 10% of the image, this value will be 0.1. | ||
| */ | ||
| public double ta = 0; | ||
|
|
||
| /** The distance from the Limelight to the april tag in meters. */ | ||
| public double distToCamera = 0; | ||
|
|
||
| /** The distance from the robot to the april tag in meters. */ | ||
| public double distToRobot = 0; | ||
|
|
||
| /** | ||
| * The ambiguity of the april tag. This ranges from 0 to 1, a lower values meaning less | ||
| /** Represents a Limelight Raw Fiducial result from Limelight's NetworkTables output. | ||
| * | ||
| * @param id The id of the april tag | ||
| * @param txnc The horizontal offset of the target from the Limelight's principle pixel (the images central pixel) in degrees. | ||
| * @param tync The vertical offset of the target from the Limelight's principle pixel (the images central pixel) in degrees. | ||
| * @param ta The area of the target in the Limelight's view as a percentage of the total image area. | ||
| * @param distToCamera The distance from the Limelight to the april tag in meters. | ||
| * @param distToRobot The distance from the robot to the april tag in meters. | ||
| * @param ambiguity The ambiguity of the april tag. This ranges from 0 to 1, a lower values meaning less | ||
| * ambiguous. The higher this is, the more likely it is that you will see ambiguity flipping. | ||
| * Ambiguity flipping is when there are multiple possible "solutions" for the pose estimate, so | ||
| * if this is higher your estimate will be less reliable. The best way to reduce this it to make | ||
| * the april tag look as trapezoidal as possible from the Limelight's perspective. | ||
| */ | ||
| public double ambiguity = 0; | ||
| */ | ||
| public record RawFiducial(int id, double txnc, double tync, double ta, double distToCamera, double distToRobot, double ambiguity) { | ||
|
|
||
|
|
||
| /** | ||
| * Initializes a RawFidicual with the provided values. This represents data from reading a | ||
|
|
@@ -120,7 +99,7 @@ public boolean equals(Object obj) { | |
| * Represents a Limelight pose estimate from Limelight's NetworkTables output. This is for any | ||
| * botpose estimate, so MegaTag1 or MegaTag2 | ||
| */ | ||
| public static class PoseEstimate { | ||
| public record PoseEstimate { | ||
| /** The estimated 2D pose of the robot, including position and rotation. */ | ||
| public Pose2d pose; | ||
|
|
||
|
|
@@ -153,15 +132,16 @@ public static class PoseEstimate { | |
|
|
||
| /** Initializes an "empty" PoseEstimate object with default values */ | ||
| public PoseEstimate() { | ||
| this.pose = new Pose2d(); | ||
| this.timestampSeconds = 0; | ||
| this.latency = 0; | ||
| this.tagCount = 0; | ||
| this.tagSpan = 0; | ||
| this.avgTagDist = 0; | ||
| this.avgTagArea = 0; | ||
| this.rawFiducials = new RawFiducial[] {}; | ||
| this.isMegaTag2 = false; | ||
| this(new Pose2d(), 0, 0, 0, 0, 0, 0, new RawFiducial[0], false); | ||
| } | ||
|
|
||
| /** | ||
| * Returns an empty PoseEstimate. | ||
| * | ||
| * @return a PoseEstimate with default values | ||
| */ | ||
| public static PoseEstimate empty() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this necessary? |
||
| return new PoseEstimate(); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -1027,33 +1007,33 @@ public static void setBotPoseEstimate( | |
| // Because network tables don't support 2D arrays, we need to flatten the data into a 1D array | ||
| // Calculates array size: 11 (for PoseEstimate data) + 7 * number of fiducials (for each raw | ||
| // fiducial) | ||
| int fiducialCount = poseEstimate.rawFiducials.length; | ||
| int fiducialCount = poseEstimate.rawFiducials().length; | ||
| double[] data = new double[11 + 7 * fiducialCount]; | ||
|
|
||
| // Populates the PoseEstimate, matching unpackBotPoseEstimate | ||
| data[0] = poseEstimate.pose.getX(); // x | ||
| data[1] = poseEstimate.pose.getY(); // y | ||
| data[0] = poseEstimate.pose().getX(); // x | ||
| data[1] = poseEstimate.pose().getY(); // y | ||
| data[2] = 0.0; // z (Pose2d doesn't use this) | ||
| data[3] = 0.0; // roll (not used) | ||
| data[4] = 0.0; // pitch (not used) | ||
| data[5] = poseEstimate.pose.getRotation().getDegrees(); // yaw | ||
| data[6] = poseEstimate.latency; // latency | ||
| data[5] = poseEstimate.pose().getRotation().getDegrees(); // yaw | ||
| data[6] = poseEstimate.latency(); // latency | ||
| data[7] = fiducialCount; // tagCount (must match fiducials length) | ||
| data[8] = poseEstimate.tagSpan; // tagSpan | ||
| data[9] = poseEstimate.avgTagDist; // avgTagDist | ||
| data[10] = poseEstimate.avgTagArea; // avgTagArea | ||
| data[8] = poseEstimate.tagSpan(); // tagSpan | ||
| data[9] = poseEstimate.avgTagDist(); // avgTagDist | ||
| data[10] = poseEstimate.avgTagArea(); // avgTagArea | ||
|
|
||
| // Add data for each fiducial | ||
| for (int i = 0; i < fiducialCount; i++) { | ||
| int baseIndex = 11 + (i * 7); | ||
| RawFiducial fid = poseEstimate.rawFiducials[i]; | ||
| data[baseIndex] = fid.id; // id (cast to double) | ||
| data[baseIndex + 1] = fid.txnc; // txnc | ||
| data[baseIndex + 2] = fid.tync; // tync | ||
| data[baseIndex + 3] = fid.ta; // ta | ||
| data[baseIndex + 4] = fid.distToCamera; // distToCamera | ||
| data[baseIndex + 5] = fid.distToRobot; // distToRobot | ||
| data[baseIndex + 6] = fid.ambiguity; // ambiguity | ||
| RawFiducial fid = poseEstimate.rawFiducials()[i]; | ||
| data[baseIndex] = fid.id(); // id (cast to double) | ||
| data[baseIndex + 1] = fid.txnc(); // txnc | ||
| data[baseIndex + 2] = fid.tync(); // tync | ||
| data[baseIndex + 3] = fid.ta(); // ta | ||
| data[baseIndex + 4] = fid.distToCamera(); // distToCamera | ||
| data[baseIndex + 5] = fid.distToRobot(); // distToRobot | ||
| data[baseIndex + 6] = fid.ambiguity(); // ambiguity | ||
| } | ||
|
|
||
| // Write the array to NetworkTables | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol idk why i didnt do this