Autonomous // Advanced

AprilTagAuto

Triangulates a cluster center, turns toward it, approaches, and stops 24 inches away.

Before running: Ask your mentor first. Keep Driver Station STOP ready.

Read · predict · explain

Build the idea, one block at a time

Read these steps before exploring the full program. The numbered blue comments in the diagram link back to the matching step.

01ROBOT SETUP: Configure directions, BRAKE behavior, encoder mode, and zero motor power before anything can move.

02START THE LIMELIGHT: Pipeline 0 detects AprilTags. A fast poll rate gives the control loops frequent steering updates.

03INIT DISPLAY: Scan continuously before START. Show R1-R8 and the triangulated red-center distance while all motor powers remain zero.

04WAIT FOR START: Autonomous movement is blocked until the Driver Station START button is pressed.

05ACQUIRE MEANS FIND AND CHOOSE

For up to 3 seconds, scan for enough information to build a center: at least one visible tag from each half of an alliance. The program may see many tags, but it chooses the nearer complete red or blue center. The timeout prevents an endless loop when no usable target exists.

06CENTER USING A HORIZONTAL ANGLE

currentTx means the target’s horizontal X angle in degrees; Tx here does not mean transmit. Positive and negative tell which way to turn. Within 2 degrees counts as centered. Requiring 5 centered camera frames filters flicker: one lucky noisy reading cannot end the turn early.

Math breakoutClosed-loop camera centeringmeasure → turn → measure again → stop inside ±2°

The robot repeatedly corrects fresh angle error instead of guessing one perfect turn.

07DRIVE TO A 24-INCH RANGE

Range means straight-line distance from camera to calculated center. The robot drives while currentRange is greater than 24 inches and stops at 24 or less. Small unequal left/right powers correct the horizontal angle while moving. The 8-second timeout and found flag stop the robot if vision fails.

Math breakoutClosed-loop camera centeringmeasure → turn → measure again → stop inside ±2°

The robot repeatedly corrects fresh angle error instead of guessing one perfect turn.

08FINAL SAFETY STOP: Set every motor to zero and stop the Limelight when autonomous finishes.

09FRESH FRAME, FRESH FLAGS

Every camera frame is a new measurement. Reset found and visible flags before reading it. Otherwise a tag that disappeared could leave an old true value behind, making the robot steer using stale information.

10WHAT THE LIMELIGHT RETURNS

getLatestResult retrieves the newest processed image result. Fiducial means a known visual marker. FiducialResults is a list of all recognized AprilTags, and the for-each loop performs the same geometry on each list item.

11CAMERA COORDINATES AND POSE

Pose means position plus rotation. X is left/right, Y is up/down, and Z is forward from the camera. Yaw is left/right rotation; pitch is up/down tilt. All are needed because the tag strip may be viewed from an angle.

12SIGNED X, Y, Z VALUES

A signed number contains direction and size. For example, negative X may mean left and positive X right. Squaring removes the signs for distance, but keeping signs before that is essential for steering and projecting hidden points.

13DEGREES AND ROTATION

Yaw is like turning your head left/right; pitch is like nodding up/down. The Limelight gives degrees. The Blocks sine and cosine operations convert these degree angles internally, so students do not need to calculate radians.

14WHY SQUARE, ADD, THEN SQUARE ROOT?

Each axis is one side of a 3D right-angle path. Squaring makes every contribution positive. Adding X²+Y²+Z² combines all three dimensions. The square root returns the direct camera-to-tag distance. Multiply meters by 39.3701 for inches.

Math breakout3D Pythagorean distancerange = √(X² + Y² + Z²)

Three perpendicular camera measurements combine into one straight-line range.

15WHY FOUR GROUP NUMBERS?

0 means red first half R1–R4; 1 means red second half R5–R8; 2 and 3 are the matching blue halves. One visible tag in group 0 plus one in group 1 can build the red center. Groups 2 and 3 build blue.

16BIOBUZZ TAG MAP AND OFFSETS

IDs 30–37 are red R1–R8; IDs 38–45 are blue B1–B8. Tag centers within each four-tag strip sit at -6.5, -2.75, +2.75, and +6.5 inches. Those known measurements let one visible tag estimate a hidden endpoint.

17ROTATE A KNOWN OFFSET WITH TRIGONOMETRY

An offset measured along the tag strip is not automatically camera-left/right when the strip is angled. Cosine gives the component along an axis; sine gives the perpendicular component. Using yaw and pitch rotates the offset into camera X, Y, and Z. Divide inches by 39.3701 first because pose coordinates are meters.

Math breakoutRotate a known AprilTag offsetΔX = d·cos(yaw)·cos(pitch) ΔY = d·sin(yaw)·cos(pitch)

Sine and cosine split one known strip distance into camera-axis pieces.

18MIDPOINT, DISTANCE, AND DIRECTION

Average endpoint coordinates to find the center: (A+B)/2 on each axis. Then distance=square root of X²+Y²+Z², the 3D Pythagorean theorem. atan2(X,Z) gives the signed left/right angle even when X or Z is zero; ordinary tangent division could fail or lose the correct quadrant.

Math breakoutMidpoint and center bearingcenter = (A + B) ÷ 2 angle = atan2(X, Z)

Average two reconstructed endpoints, then calculate the signed turn toward their center.

19TARGET STATE VARIABLES

selectedId uses 0 for red center and 1 for blue center; it is not a physical tag ID. currentRange is center distance in inches. currentTx is center horizontal angle in degrees. found must be true before any vision-guided motor command is allowed.

Math in motion

Closed-loop camera centering

measure → turn → measure again → stop inside ±2°

Each camera frame produces a new horizontal error. The robot turns in the error direction, measures again, and stops only after the center remains close enough to straight ahead. Requiring several centered frames filters camera flicker.

  1. Measure currentTx from the newest complete center calculation.
  2. Turn left or right with a small bounded motor command.
  3. Stop after the error is within 2 degrees for the required number of fresh frames.

Robot proportions use the official REV Starter Bot Onshape assembly bounds.

Math in motion

3D Pythagorean distance

range = √(X² + Y² + Z²)

X, Y, and Z are three right-angle legs measured from the camera. Squaring removes direction signs, adding combines all three dimensions, and the square root returns the direct distance.

  1. Square X, Y, and Z so left/right and up/down signs cannot cancel distance.
  2. Add the three squared lengths.
  3. Take the square root, then convert meters to inches with × 39.3701.

Uses the official BIOBUZZ AprilTag cluster geometry from the FIRST field CAD.

Math in motion

Rotate a known AprilTag offset

ΔX = d·cos(yaw)·cos(pitch) ΔY = d·sin(yaw)·cos(pitch)

The measured offset lies along the AprilTag strip, but that strip can be turned relative to the camera. Yaw and pitch rotate the known offset into X, Y, and Z components before those components are added to the visible tag position.

  1. Convert the known offset from inches to meters.
  2. Use cosine for the component aligned with an axis and sine for the perpendicular component.
  3. Add the rotated components to the visible tag coordinates to estimate a hidden point.

The white strip is official BIOBUZZ field CAD; arrows are instructional overlays.

Math in motion

Midpoint and center bearing

center = (A + B) ÷ 2 angle = atan2(X, Z)

A midpoint is found independently on every axis. Once the center has X, Y, and Z coordinates, atan2 compares sideways X with forward Z and preserves the correct left/right sign and quadrant.

  1. Average endpoint A and endpoint B on X, Y, and Z.
  2. Use the midpoint coordinates for center range.
  3. Use atan2(X, Z) for a safe signed horizontal angle, even when one coordinate is zero.

AprilTag strips come from the official BIOBUZZ field model.

Put the steps together

Explore the full Blocks program

Zoom in to follow the connections. Click a blue comment or focus its label and press Enter to revisit that lesson step.

Ask your mentor before importing or running these Blocks. A download does not set up or start the robot.

For mentors: robot setup & safety

Review before running

Safety: Read and predict before running. Verify the required hardware and configuration. Raise the wheels for the first motor test, keep one person ready to press STOP, and never rely on camera code as the only safety system.