-
Notifications
You must be signed in to change notification settings - Fork 9
Limelight Subsystem replacement (REVIEWS ONLY, WILL NOT MERGE) #194
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
base: main
Are you sure you want to change the base?
Conversation
just jotting down my ideas
| //// Use one of these, first one is current second is what advantage kit example is | ||
| // DISTANCE_SC_STANDARD_DEVS.times(Math.max(0, distanceMeters - | ||
| // 1)).plus(STANDARD_DEVS)); |
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.
Please do the math (Excel is good at this) to compare the two methods for various tag distances & see how that affects the values in the vector below.
|
/gemini review |
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.
Code Review
This pull request replaces the PhotonVision-based vision subsystem with a Limelight-based one. The changes include adding a Limelight helper library, a wrapper class for it, and updating the VisionSubsystem to use Limelight. While this is a good step, there are several critical issues in the implementation that need to be addressed. The LLCamera helper class has a fundamental flaw with a static name field that will cause incorrect behavior with multiple cameras. The VisionSubsystem has a critical bug in its update logic that will lead to incorrect pose estimation, and another bug that prevents tracking of vision data freshness. I've left detailed comments on these issues with suggestions for fixes.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.
Code Review
This pull request replaces the PhotonVision-based vision subsystem with a new implementation using Limelight, including new helper classes and updated dependencies. The changes are a good step towards the new system, but I've identified a critical bug in the LLCamera helper class where a static field is used for the camera name, which will cause both cameras to point to the same device. There is also a high-severity logic issue in VisionSubsystem where state is being incorrectly overwritten in a loop, and several medium-severity issues related to UI layout, code duplication, and dead code. Please review the detailed comments for suggestions on how to address these issues.
| private static String name; | ||
|
|
||
| public LLCamera(String name) { | ||
| LLCamera.name = name; | ||
| } |
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.
The name field is declared as static, which means it's shared across all instances of LLCamera. When you create two LLCamera objects (one for left_limelight and one for right_limelight), the second object's constructor will overwrite the name for both instances. This will cause both LLCamera objects to refer to the right_limelight, which is a significant bug.
To fix this, name should be an instance field.
| private static String name; | |
| public LLCamera(String name) { | |
| LLCamera.name = name; | |
| } | |
| private final String name; | |
| public LLCamera(String name) { | |
| this.name = name; | |
| } |
| private void processFiducials(RawFiducial rf) { | ||
| // distance to closest fiducial | ||
| double distanceMeters = distance; | ||
| Optional<Pose3d> tagPose = fieldLayout.getTagPose(rf.id); | ||
| if (tagPose.isPresent()) { | ||
| distanceMeters = rf.distToCamera; | ||
| } | ||
| distance = distanceMeters; | ||
| tagAmbiguity = rf.ambiguity; | ||
| } |
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.
The processFiducials method updates the instance variables distance and tagAmbiguity for every valid fiducial it processes. Since this is called in a loop within update(), these variables are overwritten on each iteration. As a result, they will only reflect the values of the last valid fiducial seen by either camera, not necessarily the most relevant one (e.g., the closest).
If the goal is to track the closest target, you should compare the current fiducial's distance with the stored distance and only update if it's smaller. This would require initializing distance to a large value (e.g., Double.MAX_VALUE) at the beginning of the update() method.
private void processFiducials(RawFiducial rf) {
// distance to closest fiducial
Optional<Pose3d> tagPose = fieldLayout.getTagPose(rf.id);
if (tagPose.isPresent() && rf.distToCamera < this.distance) {
this.distance = rf.distToCamera;
this.tagAmbiguity = rf.ambiguity;
}
}| processLimelight(leftCamera, rawFieldPose3dEntryLeft); | ||
| RawFiducial[] rawFiducialsL = leftCamera.getRawFiducials(); | ||
| if (rawFiducialsL != null) { | ||
| for (RawFiducial rf : rawFiducialsL) { | ||
| processFiducials(rf); | ||
| } | ||
| } | ||
| for (PhotonPipelineResult result : rightCamera.getAllUnreadResults()) { | ||
| process(result, photonPoseEstimatorRightCamera, rawFieldPose3dEntryRight); | ||
| processLimelight(rightCamera, rawFieldPose3dEntryRight); | ||
| RawFiducial[] rawFiducialsR = rightCamera.getRawFiducials(); | ||
| if (rawFiducialsR != null) { | ||
| for (RawFiducial rf : rawFiducialsR) { | ||
| processFiducials(rf); | ||
| } | ||
| } |
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.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
For our switch to Limelight looking to get reviews on it very basic essentials for a vision subsystem