Skip to the content
LearnClasses, newPathsTools

394 lessons across 11 departments, from swerve geometry to the Impact Award essay. Written by a high-school student who needed this and couldn’t find it. Free to read, no account needed.

New lessons in your inbox

One email when something worth reading goes up. No other mail, ever.

Learn

  • Guides
  • Live classes
  • Articles
  • Learning paths
  • Glossary
  • Tools and calculators
  • Resources

Team

  • For teams
  • Dashboard
  • Leaderboard
  • Sign in
  • Get started

The record

  • Who made this
  • Contributions
  • Corrections
  • Contact
  • Teach a class

Elsewhere

  • LearnFRC for iPhone and iPad
  • LearnFRC Discord
  • LearnFRC on GitHub
  • FIRST Inspires
  • WPILib docs
  • Chief Delphi
  • The Blue Alliance

Lessons are AI-assisted: drafted from primary sources like the WPILib docs, the game manual and vendor sites, then reviewed for accuracy. If something looks wrong, open the lesson and suggest an edit. Every open suggestion is public on the contributions page, and every fix we make to a fact is written down in the corrections log.

© 2026 LearnFRC. Built by Jahaan Pardhanani. Not affiliated with or endorsed by FIRST®.

PrivacyTerms29pardhananij@sagehillschool.org394 lessons in 11 departments

LearnFRC is an independent project. FIRST®, FIRST® Robotics Competition, FRC®, FIRST® Tech Challenge, FTC®, Gracious Professionalism®, and Coopertition® are registered trademarks of FIRST® (www.firstinspires.org) which is not overseeing, involved with, or responsible for this activity, product, or service.

  1. Guides
  2. Programming, Controls & Sensors
  3. Worked Examples and Mini-Projects

Mini-Project: Vision-Aligned Scoring with Limelight

2 min readLesson 5 of 5Not done yet

Combine an AprilTag-relative aim controller with a pose-estimator vision fusion to drive up to a target and score reliably.

This capstone ties vision to motion: use a Limelight 3 to aim the robot at an AprilTag and to feed field-relative pose into your estimator, then run a command that auto-aligns and scores.

Simple aim: proportional control on tx#

Limelight publishes the horizontal angle to the target as tx (degrees). A P-only controller that spins the robot until tx is ~0 is the classic first vision feature. Use the LimelightHelpers wrapper for clean reads:

public Command aimAtTag() {
  final double kP = 0.035;
  return run(() -> {
    double tx = LimelightHelpers.getTX("");
    double omega = -tx * kP;            // degrees -> turn rate
    m_swerve.drive(0, 0, omega);
  }).until(() -> Math.abs(LimelightHelpers.getTX("")) < 1.0);
}

Add a small minimum command so the robot doesn't stall just shy of centered, and a deadband so it doesn't jitter when already aligned.

Robust localization: MegaTag2 fusion#

For scoring from a distance you want full field pose, not just an angle. MegaTag2 uses your gyro heading to disambiguate tag pose, dramatically reducing the ambiguity that hurt the original MegaTag. First send the robot's yaw to the Limelight every loop, then pull the estimate and feed it to your SwerveDrivePoseEstimator:

public void updateVision() {
  LimelightHelpers.SetRobotOrientation("",
      m_swerve.getHeading().getDegrees(), 0, 0, 0, 0, 0);

  var mt2 = LimelightHelpers.getBotPoseEstimate_wpiBlue_MegaTag2("");
  if (mt2 != null && mt2.tagCount > 0
      && Math.abs(m_gyro.getRate()) < 360) { // ignore while spinning fast (Limelight's documented MegaTag2 rejection threshold)
    m_poseEstimator.setVisionMeasurementStdDevs(
        VecBuilder.fill(0.7, 0.7, 9999999)); // trust x/y, not vision yaw
    m_poseEstimator.addVisionMeasurement(
        mt2.pose, mt2.timestampSeconds);
  }
}

Call updateVision() from the drivetrain's periodic(). Setting the rotation standard deviation huge tells the estimator to ignore vision yaw and keep trusting the gyro -- the standard MegaTag2 pattern, since MegaTag2 relies on your gyro for heading.

The scoring sequence#

Now compose: aim, drive to a known scoring pose using your odometry, then trigger the mechanism only when settled:

public Command autoScore(Pose2d scorePose) {
  return aimAtTag()
      .andThen(m_swerve.driveToPose(scorePose))
      .andThen(Commands.waitUntil(m_swerve::atPose))
      .andThen(m_arm.scoreL4());
}

Configure the pipeline correctly#

In the Limelight web UI, select AprilTag (Classic 36h11) -- the family FRC has used since 2024 -- and set the tag size to 165.1 mm for current FRC field tags. Limelight pushes targeting data faster than the default NetworkTables rate so you get fresh data each loop. Validate the fused pose in AdvantageScope's Odometry/3D view: the robot's vision pose should snap onto the real field position and stay stable as you drive, with no teleporting when a tag enters or leaves view.

Key takeaways

  • tx-based proportional aiming (LimelightHelpers.getTX) is the simplest reliable first vision feature; add a min command and deadband.
  • MegaTag2 needs your gyro yaw via SetRobotOrientation each loop, then returns a robust field pose via getBotPoseEstimate_wpiBlue_MegaTag2.
  • Feed vision into addVisionMeasurement() and set the rotation std-dev huge so the gyro owns heading.
  • Configure the pipeline as AprilTag Classic 36h11 (FRC's family since 2024) with 165.1 mm tag size, and verify the fused pose in AdvantageScope.

Quiz

3 questions. No account needed.

Get all 3 right to finish the lesson. Miss one and only that question comes back: anything you already got right stays banked.

Question 1 of 3

On a Limelight, what does the 'tx' value represent when aiming the robot at an AprilTag?

0 of 3 answered

Finish this lesson

3 questions, saved in this browser

Lesson 41 of 51 in Programming, Controls & Sensors. Pass the quiz and it's marked done, saved in this browser. No sign-up needed.

Got an account? Log in or create one free

Take the quiz

Sources

  • Limelight: Programming with LimelightLib (opens in a new tab)docs.limelightvision.io
  • Limelight: Robot Localization with MegaTag2 (opens in a new tab)docs.limelightvision.io
  • WPILib: Pose Estimators (opens in a new tab)docs.wpilib.org

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.

Spotted a mistake?Make a free account to suggest an edit
Previous lessonMini-Project: An Autonomous Routine with PathPlannerThe next module starts withA Systematic Debugging Workflow for FRC

Lesson 5 of 5 in Worked Examples and Mini-Projects, part of Programming, Controls & Sensors. New to Programming, Controls & Sensors? Start at lesson one.

All 51 lessons in Programming, Controls & Sensors

Programming Foundations: A Java Primer

  • Not done yet:Programming Basics: Variables, Data Types, and Operators
  • Not done yet:Control Flow: Conditionals, Loops, and Methods
  • Not done yet:Object-Oriented Java: Classes, Objects, and Inheritance
  • Not done yet:Why Java for FRC and How to Read WPILib Code

Foundations: Tools, Languages, and Your First Robot Program

  • Not done yet:The FRC Software Stack: What Runs Where
  • Not done yet:Choosing a Language: Java, C++, or Python
  • Not done yet:Installing the Toolchain: WPILib, Game Tools, and Driver Station
  • Not done yet:VS Code, the WPILib Extension, and Deploying Code

The Robot Program: Lifecycle and Command-Based Architecture

  • Not done yet:TimedRobot and the Robot Lifecycle
  • Not done yet:Why Command-Based? Subsystems and the Scheduler
  • Not done yet:Writing Commands and Compositions
  • Not done yet:Reading Joysticks and Binding Triggers

Motors, Sensors, and Closed-Loop Control

  • Not done yet:CTRE Phoenix 6: Talon FX, Kraken X60/X44, and Falcon 500
  • Not done yet:REVLib: SPARK MAX / SPARK Flex with NEO and NEO Vortex
  • Not done yet:PID Feedback Control
  • Not done yet:Feedforward and Motion Profiling

Autonomous: Odometry, Trajectories, and Simulation

  • Not done yet:Kinematics and Odometry: Knowing Where You Are
  • Not done yet:Trajectories with PathPlanner and Choreo
  • Not done yet:Building Autonomous Routines
  • Not done yet:Simulation: Test Without a Robot

Sensing Fundamentals: Digital, Analog, and CAN Inputs

  • Not done yet:How Sensors Talk to the roboRIO: DIO, Analog, and CAN
  • Not done yet:Limit Switches and Beam Breaks
  • Not done yet:Distance Sensors and Current Sensing

Encoders: Measuring Position and Velocity

  • Not done yet:Quadrature Encoders and How They Work
  • Not done yet:Absolute Encoders: Duty-Cycle, Analog, and the REV Through Bore
  • Not done yet:Integrated and CAN Encoders: NEO, Falcon/Kraken, and CANcoder

Gyros, IMUs, and Orientation

  • Not done yet:Gyros and IMUs: Pigeon 2.0, NavX2, and ADIS
  • Not done yet:Mounting, Calibrating, and Trusting Your IMU
  • Not done yet:The Field Coordinate System and Odometry

Closed-Loop Control: PID, Feedforward, and SysId

  • Not done yet:Open Loop vs Closed Loop, and the PID Controller
  • Not done yet:A Methodical PID Tuning Process
  • Not done yet:Feedforward: kS, kV, kA, and kG
  • Not done yet:Characterizing a Mechanism with SysId

Computer Vision and Pose Estimation

  • Not done yet:AprilTags and Vision Coprocessors
  • Not done yet:Pose Estimation with Limelight (MegaTag2) and PhotonVision
  • Not done yet:Fusing Vision with Odometry

Worked Examples and Mini-Projects

  • Not done yet:Mini-Project: A Closed-Loop Elevator with Motion Magic
  • Not done yet:Mini-Project: A Velocity-Controlled Shooter on REVLib
  • Not done yet:Mini-Project: A Teleop Swerve Drive Subsystem
  • Not done yet:Mini-Project: An Autonomous Routine with PathPlanner
  • Not done yet:Mini-Project: Vision-Aligned Scoring with Limelight

Common Mistakes and Troubleshooting

  • Not done yet:A Systematic Debugging Workflow for FRC
  • Not done yet:Command-Based Pitfalls and How to Avoid Them
  • Not done yet:Loop Overruns and Watchdog Warnings
  • Not done yet:Power, Brown-Outs, and CAN Bus Faults
  • Not done yet:Control Loop Tuning Problems

Advanced Techniques and Case Studies

  • Not done yet:State-Space Control and Kalman Filtering
  • Not done yet:Log Replay Architecture with AdvantageKit
  • Not done yet:Advanced Pose Estimation: Multi-Tag Fusion and Standard Deviations
  • Not done yet:Robot Coordination, Alerts, and Operator Feedback
  • Not done yet:Case Study: Hardening Software Before an Event
3 articles that go further on this

The lesson gets you through the topic. These go wider on it, and each reads in one sitting.

  • FRC Vision: Limelight vs PhotonVision and AprilTag Tracking

    Compare Limelight and PhotonVision for FRC vision: AprilTag tracking, pose estimation with addVisionMeasurement, MegaTag2, latency, calibration, and cost.

    8 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.

    15 min read
  • PhotonVision Setup for FRC: Install, Pipelines & AprilTag Pose

    PhotonVision setup for FRC: install it on a Raspberry Pi or Orange Pi coprocessor, build an AprilTag pipeline, run multi-tag pose, and feed swerve odometry.

    20 min read

Module

Worked Examples and Mini-Projects

  1. Mini-Project: A Closed-Loop Elevator with Motion Magic
  2. Mini-Project: A Velocity-Controlled Shooter on REVLib
  3. Mini-Project: A Teleop Swerve Drive Subsystem
  4. Mini-Project: An Autonomous Routine with PathPlanner
  5. Mini-Project: Vision-Aligned Scoring with Limelight

All 51 Programming, Controls & Sensors lessons

On this page

  • Simple aim: proportional control on tx
  • Robust localization: MegaTag2 fusion
  • The scoring sequence
  • Configure the pipeline correctly
  • Key takeaways
  • Quiz
  • Sources

Your progress

Finish a lesson and it gets counted here. No account needed.

On this page

  • Simple aim: proportional control on tx
  • Robust localization: MegaTag2 fusion
  • The scoring sequence
  • Configure the pipeline correctly
  • Key takeaways
  • Quiz
  • Sources