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
Pose2dcoordinates in meters - Explain the blue-alliance origin convention and how
AprilTagFieldLayouthandles red-alliance mirroring - Distinguish between
Pose2d,Pose3d,Transform2d, andTransform3dand 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).
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 center0 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 Y0 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 heightA 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 blueInteractive 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.
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.
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.
SwerveDrivePoseEstimator returns, and what PathPlanner uses for path waypoints. Most robot-level operations use Pose2d because FRC robots operate primarily in a horizontal plane.
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().
pose.minus(otherPose). The critical distinction from Pose2d: a Transform2d has no fixed origin — it's meaningful only relative to some starting point.
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.
// ── .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();
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.
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:
// 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 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
🔌 System Check
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?
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?
3. A programmer calls currentPose.minus(previousPose). What does the result represent, and in which coordinate frame is it expressed?
Build Your Vision Coordinate Infrastructure
- Create a
VisionConstants.javafile in your project. Define:FIELD_LAYOUTusingAprilTagFields.kCurrentYear.loadAprilTagLayoutField();TAG_SIZE_METERSfrom the current season's game manual; and at least oneROBOT_TO_CAMERATransform3dwith placeholder values measured from your robot (forward, left, up offsets in meters, and pitch angle in radians). - Add a method to your drivetrain or vision subsystem that publishes all tag field poses to a
Field2dwidget 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. - 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? - 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). InautonomousInit(), select the correct constant based onDriverStation.getAlliance(). Verify by setting the DS to both alliances in simulation and confirming the logged starting pose matches the expected position. - 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.