Official competition fields place 2D fiducial markers called AprilTags at known positions. By observing these tags and matching them against the published field layout, an optical camera calculates the robot’s absolute 3D pose.
This lesson covers camera mounting calibration, Perspective-n-Point (PnP) solving, and Limelight’s MegaTag algorithms.
1. Camera Mounting Transformation (Extrinsics)
Section titled “1. Camera Mounting Transformation (Extrinsics)”Before a camera can locate the robot on the field, software must know where the camera is located relative to the robot’s physical center of rotation:
- Forward (): Distance from robot center to camera lens (+Forward / -Backward).
- Right (): Distance from robot center to camera lens (+Right / -Left).
- Up (): Height of camera lens above carpet.
- Roll: Tilt around forward axis.
- Pitch: Upward angle of camera lens (+Up / -Down, typically 15° to 25°).
- Yaw: Pan angle relative to robot forward (+Clockwise).
Enter these measured numbers into your camera configuration web UI (e.g. http://limelight.local:5801 or http://photonvision.local:5800).
A 1-degree error in camera pitch or a 2 cm error in camera offset produces a 15 cm localization error when viewing a tag 4 meters away. Measure your camera mounting bracket with calipers or reference your CAD model directly.
2. How Perspective-n-Point (PnP) Works
Section titled “2. How Perspective-n-Point (PnP) Works”When the camera detects an AprilTag, it identifies the four pixel corners in the image. Knowing the focal length of the camera lens and the physical 8.125-inch dimension of the tag, the camera’s coprocessor solves a Perspective-n-Point (PnP) mathematical system to compute the 3D translation and rotation vector from camera to tag.
Multi-Tag vs. Single-Tag Ambiguity:
Section titled “Multi-Tag vs. Single-Tag Ambiguity:”- Single-Tag Observation: Optical perspective distortion can cause “pose ambiguity” where the solver cannot determine whether the tag is slightly tilted left or right. This causes the calculated pose to flip intermittently.
- Multi-Tag Observation: When two or more tags are in the camera’s field of view simultaneously, ambiguity is mathematically zero. The multi-tag PnP solver locks the 3D pose with millimeter precision.
3. Limelight MegaTag1 vs. MegaTag2
Section titled “3. Limelight MegaTag1 vs. MegaTag2”Limelight cameras support two distinct 3D localization pipelines:
MegaTag1 (Classic Multi-Tag PnP)
Section titled “MegaTag1 (Classic Multi-Tag PnP)”- Solves 3D pose using optical tag corners alone.
- Excellent when 2 or more tags are visible.
- If only one tag is visible, optical tilt ambiguity can cause slight rotational jumps.
MegaTag2 (Gyro-Constrained Localization)
Section titled “MegaTag2 (Gyro-Constrained Localization)”- Ingests the robot’s high-precision IMU yaw angle (Pigeon 2.0) into the PnP solver as a known mathematical constraint.
- Because the robot heading is known with 0.1° accuracy, the solver eliminates single-tag ambiguity entirely.
- Extremely stable even while the robot is accelerating violently, bumping over obstacles, or being defended.
Supplying Gyro Yaw to MegaTag2 in Java:
Section titled “Supplying Gyro Yaw to MegaTag2 in Java:”// Inside robot periodic loop: send IMU yaw to Limelight for MegaTag2double yawDegrees = m_pigeon2.getYaw().getValueAsDouble();LimelightHelpers.SetRobotOrientation("limelight", yawDegrees, 0.0, 0.0, 0.0, 0.0, 0.0);4. Camera Exposure and Pipeline Tuning
Section titled “4. Camera Exposure and Pipeline Tuning”In the Limelight web interface:
- Set Pipeline Type to
Fiducial Markers (AprilTags). - Reduce Exposure to
1000to2500microseconds. The image will look dark to human eyes, but high contrast between white and black squares eliminates motion blur while driving at 4.5 m/s. - Set Gain low to prevent digital noise on tag edges.
Common Failure Modes
Section titled “Common Failure Modes”1. Tag Corners Wash Out While Driving
Section titled “1. Tag Corners Wash Out While Driving”- Symptom: Tags are recognized while stationary, but drop out as soon as the robot accelerates.
- Cause: Exposure is too high, creating motion blur across tag borders.
- Fix: Lower exposure until only the high-contrast tag squares are clearly visible.
2. Robot Position Jumps When Turning
Section titled “2. Robot Position Jumps When Turning”- Symptom: In MegaTag2 mode, rotating the robot causes the field position to jump 1 meter sideways.
- Cause: Camera mounting offset () was measured from the edge of the chassis instead of the center of rotation.
- Fix: Re-measure camera coordinates relative to the center of rotation between the four swerve modules.
Check Your Work
Section titled “Check Your Work”- Place the robot at a known tape mark on the field (e.g. 2.0 meters directly in front of Tag 7).
- Open the camera web interface.
- Confirm that the calculated camera distance matches your physical tape measurement within 2 cm.
Verified Sources & Standards
- Limelight Documentation - MegaTag AprilTag Pipelinesdocs.limelightvision.ioHardware Vendor
- PhotonVision AprilTag Detection & Calibration Guidedocs.photonvision.orgCommunity Reference