To navigate, a robot needs a shared definition of 'where' on the field. WPILib standardizes this.
The WPILib field coordinate system
WPILib uses the NWU (North-West-Up) convention. For the field, the commonly recommended origin is the bottom-left corner as you stand at the blue alliance wall looking downfield. From that viewpoint:
- The +X axis points away from you, down the field.
- The +Y axis points to your left.
- Positive rotation (theta) is counter-clockwise (CCW), following the right-hand rule. Facing straight downfield is
Rotation2d.fromDegrees(0).
WPILib recommends the 'always blue origin' approach: keep the origin fixed at the blue-alliance corner for both alliances and account for your alliance in code, rather than moving the origin. This is the convention the major tools — the AprilTag field layout, PathPlanner, Choreo, and Glass/Field2d — follow, which is why it keeps everything consistent. (You may also see an alliance-relative-origin approach in older code, but the blue-origin convention is the modern standard.)
Pose2d and Rotation2d
A robot's position is a Pose2d: an (x, y) translation in meters plus a Rotation2d heading. Prefer Rotation2d.fromDegrees() / fromRadians() over juggling raw angles — Rotation2d stores sine/cosine and avoids wrap-around bugs.
Odometry
Odometry estimates the robot's Pose2d over time by combining:
- Wheel encoders — how far each wheel has rolled (and, for swerve, each module's angle).
- The gyro — the robot's heading.
WPILib provides DifferentialDriveOdometry, SwerveDriveOdometry, and MecanumDriveOdometry. Each loop you feed in the gyro angle and wheel measurements, and it integrates the motion into a new pose:
SwerveDriveOdometry odometry = new SwerveDriveOdometry(kinematics, gyro.getRotation2d(), modulePositions, startPose);
// periodic:
odometry.update(gyro.getRotation2d(), modulePositions);
Pose2d robotPose = odometry.getPoseMeters();
Why odometry alone is not enough
Odometry is smooth and updates fast, but it accumulates error: wheel slip, scrub, and gyro drift make the estimate wander from reality over a match. There is no absolute correction. The fix — covered in the vision module — is to periodically blend in absolute measurements from AprilTags using a pose estimator, which keeps the smoothness of odometry while pulling the estimate back to the truth.
Key takeaways
- WPILib's recommended field origin is the blue-alliance bottom-left corner; +X is downfield, +Y is left, and CCW rotation is positive.
- A Pose2d is (x, y) in meters plus a Rotation2d heading; use Rotation2d.fromDegrees to avoid wrap-around bugs.
- Odometry fuses wheel encoders and the gyro into a pose but drifts over time, so it needs absolute correction.
Keep going
Take the quiz · +10 XP with an accountMore in Gyros, IMUs, and Orientation
Sources & corrections
This lesson is AI-assisted: drafted from primary sources, then reviewed and edited by hand. Errors still get through. When one is reported we fix it and write down what changed — publicly, in the corrections log.
Sources and further reading
- WPILib: Coordinate Systemdocs.wpilib.org
- WPILib: Differential Drive Odometrydocs.wpilib.org
- WPILib: Swerve Drive Odometrydocs.wpilib.org
Read next
Articles on this, for competition day
The lesson covers how it works. These cover what to do when it breaks.
- 15 min read
FRC Odometry and Pose Estimation: Field-Centric Control with WPILib
How an FRC robot tracks its field position with WPILib: wheel odometry vs pose estimation, gyro heading, fusing AprilTag vision, and field-centric driving.
Read - 8 min read
AprilTags in FRC: How Robots See the Field
AprilTags in FRC are the fiducial markers robots use to see the field and know their exact position. How the tags, cameras, and pose estimation actually work.
Read
Lesson quiz
RequiredAll 3 right completes the lesson. Miss one and only that question comes back — anything you already answered correctly stays banked.
0 of 3 answered
01.In the WPILib field coordinate system, where is the origin and which way does +X point?
02.Using the WPILib field convention, what does a heading of 0 degrees mean, and which rotation direction is positive?
03.Why does encoder-and-gyro odometry drift over a match, and how does WPILib correct it?
Answer every question to submit.
All 51 lessons in Programming, Controls & Sensors
- Not started:Mini-Project: A Closed-Loop Elevator with Motion Magic
- Not started:Mini-Project: A Velocity-Controlled Shooter on REVLib
- Not started:Mini-Project: A Teleop Swerve Drive Subsystem
- Not started:Mini-Project: An Autonomous Routine with PathPlanner
- Not started:Mini-Project: Vision-Aligned Scoring with Limelight
- Not started:State-Space Control and Kalman Filtering
- Not started:Log Replay Architecture with AdvantageKit
- Not started:Advanced Pose Estimation: Multi-Tag Fusion and Standard Deviations
- Not started:Robot Coordination, Alerts, and Operator Feedback
- Not started:Case Study: Hardening Software Before an Event