Unit 10 · Lesson 2

Field Coordinate Frames and the Field Layout

Every pose estimate your robot produces is meaningless without a shared coordinate system. This lesson establishes the WPILib field frame, the blue-origin convention, how 3D tag poses are stored in the layout file, and the transform algebra that connects camera detections to robot field positions.

By the end of this lesson, you will:

  • State the WPILib field coordinate origin and the direction of each axis for an FRC field
  • Convert a physical field position (described in feet from a corner) to WPILib Pose2d coordinates in meters
  • Explain the blue-alliance origin convention and how AprilTagFieldLayout handles red-alliance mirroring
  • Distinguish between Pose2d, Pose3d, Transform2d, and Transform3d and state when each is appropriate
  • Chain transforms correctly using .plus(), .minus(), and .relativeTo()
  • Identify the three most common coordinate frame mistakes in FRC vision code

Why Coordinate Frames Are a Source of Bugs

Vision-based localization involves at least three distinct coordinate frames: the camera frame, the robot frame, and the field frame. A pose expressed in one frame is a completely different set of numbers when expressed in another. If you add a camera-relative measurement to a field-relative pose without converting between frames, the result is garbage — and the robot will drive to a garbage location without any error or exception.

This class of mistake is among the hardest to debug because the code compiles cleanly, deploys successfully, and produces plausible-looking numbers on SmartDashboard. Only on the field does the robot's behavior reveal that every pose estimate has been wrong from the beginning. Understanding coordinate frames before writing a single line of vision code is what prevents hours of competition-day debugging.

The WPILib Field Coordinate System

WPILib defines a fixed, field-relative coordinate system used by odometry, path following, and vision. Everything in this unit assumes this coordinate system. Deviating from it — even for "simplicity" — produces bugs that are difficult to trace.

The key rules:

  • Origin: The bottom-left corner of the field when viewed from above with the blue alliance on the left. For a standard FRC field (roughly 16.54 m × 8.21 m), the origin is the corner at the intersection of the blue alliance wall and the bottom field wall.
  • +X axis: Points to the right in the top-down view — away from the blue alliance wall, toward the red alliance wall. Increasing X = moving toward the red alliance side.
  • +Y axis: Points upward in the top-down view — away from the bottom field wall, toward the top field wall. Increasing Y = moving toward the top wall.
  • +Z axis: Points up out of the field surface (for 3D poses). Increasing Z = increasing height above the carpet.
  • Headings: Counter-clockwise positive when viewed from above. 0° = facing the red alliance wall (+X direction). 90° = facing the top field wall (+Y direction). 180° = facing the blue alliance wall (−X direction).
X axis (red) Along the field length

0 at the blue alliance wall, 16.54 m at the red alliance wall. A robot starting at the blue alliance station has X ≈ 1.5 m.

new Translation2d(8.27, y) // field center
Y axis (green) Along the field width

0 at the bottom wall, 8.21 m at the top wall. The center of the field width is at Y ≈ 4.11 m.

new Translation2d(x, 4.11) // center Y
Z axis (blue) Height above carpet (3D only)

0 at carpet level. AprilTags are typically mounted at Z = 0.36–1.45 m depending on the game. Used in Pose3d and Transform3d.

new Pose3d(x, y, 0.57, rot) // tag height
Heading (theta) CCW positive, 0° = facing +X

A robot facing the red alliance scores at 0°. Facing the top wall is 90°. Facing blue alliance is 180°. Facing the bottom wall is −90° or 270°.

Rotation2d.fromDegrees(180) // face blue

Interactive Field Coordinate Explorer

Click anywhere on the field below to see the WPILib coordinates for that point. Toggle between viewing from the blue and red alliance perspective to see how the displayed position changes — and critically, why the WPILib coordinates themselves don't change between alliances.

Field coordinate explorer — WPILib frame click anywhere on the field
Field view:
Standard (blue left)
Flipped (red left)
Show:
Axes
Tag positions
WPILib X (m) —
WPILib Y (m) —
Alliance —
Pose2d code click to generate
🔍 Why the coordinates don't flip between alliances

Notice that as you move the cursor across the field, the WPILib X and Y coordinates don't change when you toggle between "Standard" and "Flipped" view modes. The coordinate system is fixed — it's a property of the field, not of which alliance you're on. Your robot on the red alliance side has X ≈ 15.0 m (near the red wall), not X ≈ 1.5 m. Your autonomous paths and vision-computed poses are always in the same absolute coordinate system. What changes for red alliance is which tags you see and which scoring targets your code points to — not the coordinate system itself. PathPlanner handles this by mirroring path coordinates across X = 8.27 m (the field center) when on red alliance.

The Blue-Alliance Origin Convention

FIRST publishes the AprilTag field layout with all tag poses expressed in the blue-alliance coordinate system. This means the origin (0, 0) is always at the blue alliance's corner, regardless of which alliance is playing. Every tag ID has a single, fixed Pose3d in the layout — there are no "blue version" and "red version" of the same tag ID.

This has a direct implication for your code: when your robot is on the red alliance, the starting pose you reset odometry to before autonomous is not a mirror of the blue alliance starting pose. It's the actual field-absolute coordinate of the red alliance starting position, which has a large X value (near 16.54 m) and the same range of Y values as the blue alliance side. PathPlanner and Choreo both implement path mirroring — they flip path coordinates across X = 8.27 m (the halfway point) automatically when the alliance flip lambda returns true. This is the correct behavior: the paths are drawn in blue coordinates, then mathematically reflected to find the equivalent red-alliance positions.

💡 Your starting pose constants need a red-alliance version

A common mistake is writing a single STARTING_POSE constant and using it for both alliances. This works during testing at your shop (where you always "start" from the same spot) but fails at competition when you're assigned to red alliance. Use DriverStation.getAlliance() to detect the alliance and select the appropriate starting pose: isBlue ? BLUE_STARTING_POSE : RED_STARTING_POSE. The red starting pose is not simply the blue pose with X negated — it's the actual field-absolute coordinate of where a robot starts on the red side, which you can compute by reflecting across X = 8.27 m: redX = fieldLength - blueX = 16.54 - blueX.

Pose2d, Pose3d, Transform2d, Transform3d

WPILib's geometry library provides four distinct types for representing positions and relative movements. Using the wrong type for a situation is one of the most common sources of vision bugs. The distinction between a pose and a transform is particularly important.

A Pose is an absolute position and orientation in a specific coordinate frame — it answers "where is this thing in the world?" A Transform is a relative displacement — it answers "how do you get from point A to point B?" You cannot meaningfully add two poses together, but you can add a transform to a pose to get a new pose. The .plus() and .minus() operations on these types enforce this distinction.

P2
Pose2d — field position and heading (2D) Used for robot position on the field in 2D: X (meters), Y (meters), heading (Rotation2d). This is what odometry tracks, what SwerveDrivePoseEstimator returns, and what PathPlanner uses for path waypoints. Most robot-level operations use Pose2d because FRC robots operate primarily in a horizontal plane.
P3
Pose3d — full 3D position and orientation Used for objects that exist at a specific height and orientation in 3D space — primarily AprilTags and camera positions. The field layout stores every tag as a Pose3d. Camera poses on the robot (for configuring PhotonPoseEstimator) are also expressed as Pose3d because cameras can be tilted at angles. When you need only the 2D projection for robot navigation, use .toPose2d().
T2
Transform2d — relative displacement in 2D A relative move: how far forward, how far sideways, and how much to rotate. Used for robot-to-camera offsets in 2D, and as the result of pose.minus(otherPose). The critical distinction from Pose2d: a Transform2d has no fixed origin — it's meaningful only relative to some starting point.
T3
Transform3d — relative displacement in 3D The 3D version of Transform2d. The camera-to-tag transform returned by PhotonTrackedTarget.getBestCameraToTarget() is a Transform3d. The robot-to-camera transform you configure in PhotonPoseEstimator is a Transform3d. Understanding this type is essential for tracing the pose estimation pipeline from Lesson 1.

Transform Algebra: plus(), minus(), and relativeTo()

Three operations connect poses and transforms. Getting these right is the difference between a vision system that works and one that produces plausible-looking wrong answers.

WPILib geometry operations — annotated examples
// ── .plus(Transform2d) — apply a transform to a pose ──────────────────────
// Returns a new Pose2d that is the result of moving from 'pose' by 'transform'.
// This is how you apply a camera-offset to get from camera pose to robot pose.
Pose2d robotPose = cameraPose.plus(cameraToRobotTransform);
// Note: cameraToRobotTransform must be expressed IN THE CAMERA'S frame.

// ── .minus(Pose2d) — get the transform between two poses ──────────────────
// Returns the Transform2d that takes you from 'other' to 'this'.
// The result is expressed in the coordinate frame of 'other'.
Transform2d delta = currentPose.minus(previousPose);
// delta.getX() = how far ahead (in previous pose's frame) we moved
// delta.getY() = how far sideways (in previous pose's frame) we moved

// ── .relativeTo(Pose2d) — express a pose in another frame ─────────────────
// Returns 'this' pose expressed relative to 'reference' instead of the field.
// Example: what are the robot's coordinates relative to a specific scoring zone?
Pose2d relativeToTarget = robotPose.relativeTo(targetPose);
// relativeToTarget.getX() = how far forward from the target the robot is
// relativeToTarget.getY() = how far sideways from the target the robot is

// ── 3D transform chain — the full vision pipeline ─────────────────────────
// Step 1: camera-to-tag transform (from PhotonVision detection)
Transform3d cameraToTag = target.getBestCameraToTarget();

// Step 2: tag field pose (from AprilTagFieldLayout)
Pose3d tagFieldPose = fieldLayout.getTagPose(tagId).get();

// Step 3: camera field pose = tag field pose + (tag-to-camera transform)
Pose3d cameraFieldPose = tagFieldPose.plus(cameraToTag.inverse());

// Step 4: robot field pose = camera field pose + (camera-to-robot transform)
// robotToCamera is the camera's position on the robot, measured and configured
Pose3d robotFieldPose3d = cameraFieldPose.plus(robotToCamera.inverse());

// Step 5: convert to 2D for odometry/navigation
Pose2d robotFieldPose = robotFieldPose3d.toPose2d();
💡 PhotonPoseEstimator does steps 2–5 automatically

You don't have to implement the transform chain manually in production code. PhotonPoseEstimator (Lesson 4) takes the field layout and robot-to-camera transform as constructor arguments and handles the entire chain internally. Understanding the chain — as shown above — is still essential because it tells you which inputs matter and what goes wrong when any of them is incorrect. When a pose estimate is wrong, the chain is where you look: wrong tag layout, wrong robot-to-camera offset, or inverted transform direction are the three most common causes.

AprilTagFieldLayout: Loading and Using the Field

WPILib's AprilTagFieldLayout class encapsulates the official tag positions for each FRC season. It's loaded once and shared across the robot's vision pipeline — typically stored as a field in VisionSubsystem or RobotContainer.

VisionSubsystem.java — loading and using the field layout
import edu.wpi.first.apriltag.AprilTagFieldLayout;
import edu.wpi.first.apriltag.AprilTagFields;
import edu.wpi.first.math.geometry.*;

public class VisionSubsystem extends SubsystemBase {

    // Load once in the constructor — this reads the JSON embedded in the WPILib jar.
    private final AprilTagFieldLayout m_fieldLayout =
        AprilTagFields.k2025ReefScapeV2.loadAprilTagLayoutField();
    // Replace k2025ReefScapeV2 with the correct constant for the current season.

    public void exampleUsage() {
        // Get a tag's 3D field pose by ID
        Optional<Pose3d> tagPoseOpt = m_fieldLayout.getTagPose(7);
        if (tagPoseOpt.isPresent()) {
            Pose3d tagPose = tagPoseOpt.get();
            // tagPose.getX(), tagPose.getY(), tagPose.getZ() in meters
            // tagPose.getRotation() in Rotation3d (pitch, roll, yaw)
        }

        // Iterate all tags to find those on a specific side of the field
        var blueSideTags = m_fieldLayout.getTags().stream()
            .filter(tag -> tag.pose.getX() < 8.27)   // left half = blue side
            .collect(Collectors.toList());

        // Get the total number of tags on this field
        int tagCount = m_fieldLayout.getTags().size();

        // Publish all tag positions to SmartDashboard for verification
        // The Field2d widget can display them as orange markers
        m_field.getObject("tags").setPoses(
            m_fieldLayout.getTags().stream()
                .map(t -> t.pose.toPose2d())
                .collect(Collectors.toList()));
    }
}

The Robot-to-Camera Transform: Measuring Your Camera Position

The transform from the robot's coordinate origin to the camera's optical center is the one value in the entire vision pipeline that you must measure physically. Every other value (field layout, tag poses) is provided by FIRST or WPILib. This one you compute from your robot's mechanical drawings or by careful measurement.

The convention in PhotonVision and most WPILib vision code is: the transform describes where the camera is relative to the robot center, expressed in the robot's coordinate frame. If the camera is mounted 0.3 m forward of center, 0.1 m to the left, 0.5 m above the carpet, angled 15° upward:

VisionConstants.java — robot-to-camera transform
// The camera's position relative to the robot's coordinate origin.
// Robot frame: +X = robot forward, +Y = robot left, +Z = robot up.
// These values come from your robot's mechanical drawings or direct measurement.
//
// CRITICAL: Re-measure these after any change to camera mounting.
// A 2 cm error in the X offset produces ~2 cm of systematic bias in all
// vision pose estimates. At scoring positions, 2 cm can be the difference
// between a successful and a failed game piece delivery.

public static final Transform3d ROBOT_TO_FRONT_CAMERA =
    new Transform3d(
        new Translation3d(0.30, -0.10, 0.50),   // forward, right, up (meters)
        new Rotation3d(0, Units.degreesToRadians(-15), 0)
        // roll=0°, pitch=-15° (tilted up toward tags), yaw=0°
    );

// If you have multiple cameras, define one constant per camera.
public static final Transform3d ROBOT_TO_BACK_CAMERA =
    new Transform3d(
        new Translation3d(-0.28, 0.0, 0.45),   // backward, center, up
        new Rotation3d(0, Units.degreesToRadians(-10),
                        Units.degreesToRadians(180))
        // pitch=-10° (tilted up), yaw=180° (faces backward)
    );

// Verify these values by publishing to SmartDashboard and manually
// confirming the displayed camera position matches the physical robot.
🔍 The most common robot-to-camera mistake I see

The robot-to-camera transform uses the robot's coordinate frame, not the field frame. In the robot frame, +X is forward, +Y is left. On the field, +X is toward the red alliance wall. These are completely different directions. A camera mounted to the left side of the robot (−Y in field frame when facing red) is at +Y in the robot frame (which is the robot's left). Teams that measure camera offsets while thinking in the field frame and enter them into the robot frame get every vision measurement systematically rotated. The giveaway is that vision estimates are correct when the robot faces 0° but diverge as the heading changes — the offset rotates with the robot's heading instead of being fixed to the robot body.

Three Common Coordinate Frame Mistakes

Pitfall 1 — Wrong alliance starting pose
Using blue starting pose for red alliance A robot starting on the red side at X ≈ 15 m with a blue starting pose of X ≈ 1.5 m resets odometry to the wrong side of the field. All subsequent pose estimates and path commands drive to wrong-alliance positions.
Fix: select starting pose based on DriverStation.getAlliance() with a red-specific constant, or let AutoBuilder.configure()'s flip lambda handle it.
Pitfall 2 — Camera offset in field frame
Robot-to-camera Transform3d measured in field coordinates The camera offset must be in the robot's body frame (+X = robot forward), not the field frame (+X = toward red wall). Entering field-frame measurements produces correct estimates only when the robot faces 0° — the error grows with heading deviation.
Fix: measure the camera's forward/left/up offsets relative to the robot's front face, not relative to the field walls.
Pitfall 3 — Inverted transform direction
Using camera-to-robot instead of robot-to-camera (or vice versa) The transform chain requires a specific direction at each step. The PhotonPoseEstimator constructor takes a robot-to-camera transform (where the camera is relative to the robot). Passing a camera-to-robot transform instead produces a reflected pose estimate — the robot appears on the opposite side of every tag.
Fix: confirm the transform direction convention with your vision library's documentation. When in doubt, log both raw and transformed poses and check for systematic reflection errors.

🔌 System Check

⚙️ Verifying Your Coordinate Frame Setup

Before running any vision-based autonomous, verify the coordinate frame setup is correct with these physical tests:

  • Starting pose logs correctly at competition starting position. Place the robot at your intended autonomous starting position on the field, reset odometry to your starting pose constant, and read the SmartDashboard pose. The displayed pose should match the physical robot position on the field to within 3 cm. If the robot is at (1.5, 4.0) on the field but SmartDashboard shows (15.0, 4.0), you're using the wrong alliance starting pose.
  • Odometry updates in the correct direction. Drive the robot 1 meter toward the red alliance side. The displayed X should increase by approximately 1.0. Drive 1 meter toward the top field wall. The displayed Y should increase by approximately 1.0. Wrong sign on either axis means the encoder or kinematics configuration is inverted.
  • Camera position is visually verified on Field2d. Publish the camera's estimated field position to SmartDashboard using m_field.getObject("camera").setPose(cameraFieldPose.toPose2d()). When the robot is at a known field position and heading, verify the camera marker appears at the physically correct offset from the robot marker. If the camera appears on the wrong side, the robot-to-camera transform direction is inverted.
  • Tag poses from the layout match the physical field. Publish all tag poses to Field2d and drive the robot around the field. The displayed tag markers should match where the real tags are physically mounted. Any mismatch indicates the wrong season's layout is loaded or the field has been set up incorrectly.

Knowledge Check

1. In WPILib's field coordinate system, what is the heading in degrees of a robot that is facing directly toward the blue alliance wall?

  • A 0°
  • B 90°
  • C 180°
  • D 270°

2. A team's robot is on the red alliance. Their code calls m_drive.resetPose(new Pose2d(1.5, 4.0, Rotation2d.fromDegrees(0))) in autonomousInit() — the same constant they use for blue alliance. The robot starts physically near the red alliance wall at approximately X = 15.0, Y = 4.0. What goes wrong with the first PathPlanner path?

  • A The path runs correctly because PathPlanner's alliance flip automatically adjusts the starting pose
  • B The path controller believes the robot is at X = 1.5 when it's actually at X = 15.0 — a 13.5 m error — so the controller immediately commands full-speed motion toward X = 1.5, driving the robot directly into the field wall or an opposing robot
  • C PathPlanner detects the pose mismatch and pauses until odometry stabilizes
  • D The path runs correctly for the first waypoint but drifts by the end

3. A programmer calls currentPose.minus(previousPose). What does the result represent, and in which coordinate frame is it expressed?

  • A The vector from the field origin to the current position, expressed in the field frame
  • B The absolute difference in X and Y coordinates, expressed as a Pose2d
  • C A Transform2d representing how far and in what direction the robot moved from its previous pose to its current pose, expressed in the coordinate frame of the previous pose (i.e., forward/left relative to the previous heading, not relative to the field)
  • D The robot's velocity, which requires dividing by the time delta
💪 Practice Prompt

Build Your Vision Coordinate Infrastructure

  1. Create a VisionConstants.java file in your project. Define: FIELD_LAYOUT using AprilTagFields.kCurrentYear.loadAprilTagLayoutField(); TAG_SIZE_METERS from the current season's game manual; and at least one ROBOT_TO_CAMERA Transform3d with placeholder values measured from your robot (forward, left, up offsets in meters, and pitch angle in radians).
  2. Add a method to your drivetrain or vision subsystem that publishes all tag field poses to a Field2d widget on SmartDashboard. Deploy and open SmartDashboard. Verify that orange markers appear at the correct field positions when you open the Field view. If the tags appear in wrong locations, check which season's layout is loaded.
  3. Write a unit test (or a temporary method you call from testInit()) that verifies the transform chain: given a simulated camera-to-tag transform and the known field pose of tag 5, compute the robot's field pose and print it. Manually verify the math: is the result consistent with where the robot would have to be to see tag 5 at that camera angle and distance?
  4. Add alliance-aware starting pose constants to your AutoConstants: one for blue, one for red. The red poses should be computed by reflecting the blue X coordinate across the field center (redX = 16.54 − blueX). In autonomousInit(), select the correct constant based on DriverStation.getAlliance(). Verify by setting the DS to both alliances in simulation and confirming the logged starting pose matches the expected position.
  5. Bonus: Implement a logCameraFieldPose(Transform3d cameraToTag, int tagId) method that manually chains the transforms and publishes the result camera field position to SmartDashboard. Call it whenever a vision measurement would be processed. Compare the logged camera pose against where the camera physically is on the robot — they should match. Any consistent offset means the robot-to-camera transform has an error.