For the complete documentation index, see llms.txt. This page is also available as Markdown.

AprilTag Pose Estimation

This tutorial fuses Limelight MegaTag2 vision measurements into a WPILib pose estimator, the way DrivebaseSubsystem does in YALL's example project.

1. Set up the camera offset once

MegaTag needs to know where the camera sits relative to robot center. Do this at construction time:

Pose3d cameraOffset = new Pose3d(Inches.of(5).in(Meters),
                                  Inches.of(5).in(Meters),
                                  Inches.of(5).in(Meters),
                                  Rotation3d.kZero);

limelight = new Limelight("limelight");
limelight.getSettings()
         .withLimelightLEDMode(LEDMode.PipelineControl)
         .withCameraOffset(cameraOffset)
         .save();

poseEstimator = limelight.createPoseEstimator(EstimationMode.MEGATAG2);

2. Submit robot orientation every loop

MegaTag2 fuses AprilTag detections with your robot's current heading. This only works if you tell the Limelight your heading every periodic loop, before reading a pose estimate:

3. Read and filter the pose estimate

poseEstimator above is your WPILib SwerveDrivePoseEstimator / DifferentialDrivePoseEstimator, a different object than YALL's LimelightPoseEstimator. Filtering on tag count, distance, and ambiguity before calling addVisionMeasurement keeps a single noisy or distant reading from corrupting your odometry.

Alternative: the BotPose enum directly

If you don't need a LimelightPoseEstimator instance around, BotPose gives the same data directly:

Or fetch the alliance-relative estimate without checking DriverStation yourself:

Next steps

Last updated

Was this helpful?