← Vision lessons

From AprilTag to robot position

Follow one observation. Change one thing at a time.

APRILTAG WALKTHROUGH

Seven steps

Capture an image

A camera image becomes a pose only after detection, geometry, known field landmarks and a measured camera mount.

Illustrative scene. No real image detection, camera calibration or robot Java runs here.

Synthetic camera image

AprilTag vision walkthrough The numerical example below explains the visual.

How the model works, sources and checks

A worked example, not a camera test

The hypothetical robot starts at field (2.00, 2.00) m, heading zero. The camera is 0.40 m forward and 0.20 m left, so its field position is (2.40, 2.20) m. A known tag faces it at (6.00, 2.20) m. In this frontal case, depth is 3.60 m. With assumed focal length 900 px and black-border width 0.165 m, the marker spans 41.25 px: depth = focal length × tag width / pixel width.

The tag width, field location and camera calibration are teaching assumptions, not a season layout or a print specification. The original PNG includes a white margin; the corner overlay measures the black border. The view shows a crop of a synthetic 640 × 400 image. At a fixed yaw and height, forward placement changes tag size; the lateral offset is held fixed.

Stage What must be known What can go wrong
Detection Tag family, pattern and observed corners Blur, occlusion, wrong ID or too few pixels
Camera pose Calibration, tag geometry and field layout Distortion, pose ambiguity, wrong layout
Robot pose Measured robot-to-camera transform Incorrect translation or orientation
Current estimate Capture time and intervening motion Clock mismatch, unavailable history or uncertain odometry

The demo constructs ideal corner observations and a camera-to-tag transform analytically; it does not decode the PNG or solve general 3D PnP. It then composes field-to-tag with the inverse camera-to-tag transform, and removes the robot-to-camera transform. A physical system also handles camera pitch/roll/height, distortion, ambiguity, noise, multiple tags and measurement acceptance.

For latency, velocity is exactly 2 m/s along field +x. A 200 ms delay gives 0.40 m travel. Adding that known motion illustrates why timestamps matter; it is not a reproduction of WPILib's estimator or a guarantee that vision is accurate. A real estimator needs compatible timestamps, retained odometry, uncertainty and rejection policies.

Check your understanding

  1. Why does decoding tag ID 7 alone not locate the robot?
  2. If the camera moves forward by 0.60 m but code retains the old mount, which direction does the estimated robot center shift?
  3. How far does this robot move during 300 ms? Can a timestamp fix an incorrect camera mount?

Answers: identity still needs geometry, calibration, field layout and a mount transform; the estimated center shifts forward by 0.60 m; travel is 0.60 m, and timestamps do not repair mount geometry.

Sources and related lessons