Skip to content

Reject Limelight vision frames relying on far AprilTags - #45

Open
YehudaRothstein wants to merge 1 commit into
mainfrom
district-one-day-one
Open

Reject Limelight vision frames relying on far AprilTags#45
YehudaRothstein wants to merge 1 commit into
mainfrom
district-one-day-one

Conversation

@YehudaRothstein

@YehudaRothstein YehudaRothstein commented Jun 28, 2026

Copy link
Copy Markdown
Member

Summary

Vision pose updates now ignore any frame that includes an AprilTag farther than 5 m from the turret Limelight, so far/noisy tags no longer pull the robot pose.

Why

Swerve.periodic() uses getBotPoseEstimate_wpiBlue (MegaTag1), which fuses every visible tag into a single pose. A single distant tag is noisy and degrades the whole estimate. Rather than averaging it in, we drop the entire frame when any contributing tag is out of range.

Changes

  • Constants.SwerveConstants.MAX_VISION_TAG_DISTANCE_METERS = 5.0 — new, tunable threshold.
  • Swerve.periodic() — added an allTagsWithinRange(...) gate to the existing visionReliable condition. The frame is accepted only if all rawFiducials have distToCamera <= 5 m (in addition to the existing tag-count, motion, and ambiguity checks).

Notes

  • Filtering is per-frame on distToCamera; to change the cutoff, edit the one constant.
  • A softer alternative (keep far tags but scale addVisionMeasurement std devs with distance) was considered; this PR uses the hard cutoff as requested. Easy to switch later if smoother boundary behavior is wanted.

Testing

  • ./gradlew compileJava passes.

🤖 Generated with Claude Code


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved vision-based driving accuracy by ignoring unreliable tag detections that are too far from the camera.
    • Reduced the chance of pose updates being applied from weak or low-confidence vision readings.
    • Added a configurable distance limit for accepting vision measurements.

Vision pose updates now ignore any frame that contains an AprilTag
farther than MAX_VISION_TAG_DISTANCE_METERS (5 m). Because the MegaTag
estimate fuses every visible tag into one pose, a single distant, noisy
tag degrades the whole result, so such frames are dropped entirely in
Swerve.periodic() before addVisionMeasurement.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TQtWGoST1ZmacrRjafx2RV
Copilot AI review requested due to automatic review settings June 28, 2026 09:48
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9d8896f3-05a5-4e5a-a538-26b7d0b0adae

📥 Commits

Reviewing files that changed from the base of the PR and between 883a0ea and 297787f.

📒 Files selected for processing (2)
  • src/main/java/frc/excalib/swerve/Swerve.java
  • src/main/java/frc/robot/Constants.java

📝 Walkthrough

Walkthrough

Adds a MAX_VISION_TAG_DISTANCE_METERS constant (5.0 m) to SwerveConstants and a private allTagsWithinRange helper in Swerve. The helper rejects pose estimates with zero fiducials or any fiducial beyond the threshold. The periodic() vision reliability check is extended to call this helper before inserting odometry measurements.

Changes

Vision Tag Distance Filter

Layer / File(s) Summary
Constant, filter helper, and periodic wiring
src/main/java/frc/robot/Constants.java, src/main/java/frc/excalib/swerve/Swerve.java
MAX_VISION_TAG_DISTANCE_METERS = 5.0 added to SwerveConstants; allTagsWithinRange helper implemented to return false when no fiducials exist or any exceeds the limit; periodic() visionReliable condition extended to call the helper.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: rejecting Limelight vision frames with distant AprilTags.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch district-one-day-one

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens Limelight (MegaTag1) vision integration in Swerve.periodic() by rejecting pose-estimate frames that include any AprilTag beyond a configurable distance threshold, preventing distant/noisy tags from degrading fused pose updates.

Changes:

  • Added MAX_VISION_TAG_DISTANCE_METERS (default 5.0) as a tunable vision cutoff in Constants.SwerveConstants.
  • Added allTagsWithinRange(...) gating in Swerve.periodic() so a frame is only accepted when every rawFiducial.distToCamera is within the threshold.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/main/java/frc/robot/Constants.java Introduces a single tunable constant to define the maximum acceptable AprilTag distance for vision pose frames.
src/main/java/frc/excalib/swerve/Swerve.java Filters Limelight pose updates by rejecting frames containing any AprilTag farther than the configured threshold before fusing into odometry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants