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.
the part worth keeping
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.
Programming, Controls & SensorsGyros, IMUs, and Orientationlesson 3 of 3
Keep going
Take the quiz+10 XP with an accountMore in Gyros, IMUs, and Orientation
where this came from
Sources and 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, in public, in the corrections log.
sources and further reading
- docs.wpilib.orgWPILib: Coordinate System
- docs.wpilib.orgWPILib: Differential Drive Odometry
- docs.wpilib.orgWPILib: Swerve Drive Odometry
clipped to this lesson
Articles that go further on this
The lesson gets you through the topic. These go wider on it, and they read in one sitting.
- 15 min readFRC Odometry and Pose Estimation: Field-Centric Control with WPILibHow an FRC robot tracks its field position with WPILib: wheel odometry vs pose estimation, gyro heading, fusing AprilTag vision, and field-centric driving./blogread it
- 8 min readAprilTags in FRC: How Robots See the FieldAprilTags 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./blogread it
answer sheet
Lesson quiz
All 3 right completes the lesson. Miss one and only that question comes back, anything you already answered correctly stays banked.
0 of 3 answered
01In the WPILib field coordinate system, where is the origin and which way does +X point?
02Using the WPILib field convention, what does a heading of 0 degrees mean, and which rotation direction is positive?
03Why 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 & Sensorsopenclose
01 / prerequisites
02 / foundations-tools-and-first-program
03 / robot-program-and-command-based
04 / motors-and-control
05 / autonomous-trajectories-simulation
06 / sensing-fundamentals
07 / encoders
08 / gyros-imus-orientation
09 / closed-loop-control
10 / vision-pose-estimation
11 / worked-examples-mini-projects
- Not read yet:Mini-Project: A Closed-Loop Elevator with Motion Magic
- Not read yet:Mini-Project: A Velocity-Controlled Shooter on REVLib
- Not read yet:Mini-Project: A Teleop Swerve Drive Subsystem
- Not read yet:Mini-Project: An Autonomous Routine with PathPlanner
- Not read yet:Mini-Project: Vision-Aligned Scoring with Limelight
12 / common-mistakes-troubleshooting
13 / advanced-techniques-case-studies
- Not read yet:State-Space Control and Kalman Filtering
- Not read yet:Log Replay Architecture with AdvantageKit
- Not read yet:Advanced Pose Estimation: Multi-Tag Fusion and Standard Deviations
- Not read yet:Robot Coordination, Alerts, and Operator Feedback
- Not read yet:Case Study: Hardening Software Before an Event