TeleOp + Vision // Next challenge

AprilTagTeleOp

Manual driving, live cluster distances, and Square-button alignment using AprilTag geometry.

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.

01WHY RESET EVERY SCAN?

A camera produces many separate pictures called frames. A tag visible in the previous frame might disappear in the next one. We begin with found=false and not visible values so yesterday’s—or even 1/100-second-old—data cannot steer the robot by mistake.

02CAMERA RESULT AND LIST

getLatestResult asks for the newest processed camera frame. The result can contain zero, one, or many tags. Fiducial is the camera word for a known visual marker such as an AprilTag. The list lets us repeat the same math for every marker found.

03THE CAMERA COORDINATE SYSTEM

For each tag, X is left/right, Y is up/down, and Z is forward/back from the camera. The pose also has yaw and pitch angles. Yaw means turning left/right; pitch means tilting up/down. These are geometry terms—not wireless transmit or receive abbreviations.

04POSITION NUMBERS

X, Y, and Z are distances measured from the camera to the tag center. They are signed numbers: the sign tells which direction, while the absolute size tells how far along that axis. Keeping all three axes lets the program measure a diagonal line through 3D space.

05ANGLE NUMBERS

Yaw rotates around the up/down axis, like shaking your head “no.” Pitch rotates up/down, like nodding “yes.” The Limelight reports degrees. Sine and cosine blocks expect degrees here, so no student-written radians conversion is needed.

06PYTHAGOREAN DISTANCE IN 3D

In 2D, a right triangle has hypotenuse square root of X²+Z². The camera also has height Y, so we add Y²: square root of X²+Y²+Z². Multiply meters by 39.3701 to display inches.

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

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

07FOUR HALF-GROUPS

Group 0 estimates R4 from R1–R4. Group 1 estimates R5 from R5–R8. Group 2 estimates B4, and group 3 estimates B5. One visible tag from each matching pair of groups is enough to calculate that alliance center.

08TAG NUMBERS AND KNOWN OFFSETS

Red tags are IDs 30–37; blue tags are IDs 38–45. Each four-tag strip has centers at -6.5, -2.75, +2.75, and +6.5 inches from its middle. Example: R1 is 13 inches left of R4, so seeing R1 lets us estimate where hidden R4 should be.

09WHY SINE AND COSINE?

The known tag offset lies along the tag strip, but the camera may view that strip at an angle. Cosine tells how much of the offset points along one camera axis; sine tells the perpendicular part. We use yaw and pitch to rotate the offset into camera X, Y, and Z. Inches are divided by 39.3701 because the camera pose uses 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.

10CLUSTER CENTER DISTANCE

A cluster is one sticker containing four AprilTags. clusterOffset moves from whichever tag is visible to that sticker’s middle. Sine and cosine rotate the offset into camera coordinates. Then square root of X²+Y²+Z² gives distance to the cluster center, not distance to one tag.

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.

11HOW CENTER DISTANCE AND ANGLE WORK

First average the estimated endpoints: center=(end1+end2)/2 for X, Y, and Z. Then use the 3D Pythagorean theorem: distance=square root of X²+Y²+Z². atan2(X,Z) answers “what left/right angle points from the camera to that center?” This angle replaces the raw tag horizontal angle.

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

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

12FOUND, SELECTED ID, AND CURRENT VALUES

found is a true/false safety flag. selectedId is 0 for the red center or 1 for the blue center; it is not an AprilTag number. currentRange stores inches to the chosen center. currentTx stores its horizontal angle in degrees; here Tx means target X angle, not transmit.

13ROBOT SETUP: Configure motor directions, braking, and encoder mode. Reversing the left motors makes positive power mean forward on both sides.

14START THE CAMERA: Pipeline 0 looks for AprilTags. Starting the Limelight here lets INIT and Square alignment use fresh vision results.

15INIT VISION: Before START, repeatedly scan tags and show R1-R8 plus the calculated red-center distance. Motor powers stay at zero during INIT.

16WAIT FOR START: The robot is ready, but this block prevents driving until the Driver Station START button is pressed.

17MANUAL DRIVE: Read the joysticks every loop. Left stick drives and strafes; right stick X rotates; left bumper chooses slow mode.

18WHEEL POWERS: Mecanum drive mixes forward, strafe, and turn differently for each wheel. Dividing by the denominator keeps every command in the safe -1 to +1 range.

19WHAT SQUARE DOES

Square temporarily overrides the joystick motor powers. The program scans the tags, calculates a center, and turns until the center is within 2 degrees of straight ahead. A degree is 1/360 of a full circle. Releasing Square immediately gives control back to the driver. If the center cannot be calculated, all motor powers become zero.

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

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

20FOUR CLUSTER DISTANCES

These rows are live after START. Red Scoring means IDs 30–33, Red Audience 34–37, Blue Audience 38–41, and Blue Scoring 42–45. “not visible” means no tag from that sticker was found in the newest camera frame.

21DRIVER STATION DISPLAY: Send commands, motor powers, buttons, and Square-alignment information to the Driver Station.

22SAFETY STOP: After STOP is pressed, set all motors to zero and stop the Limelight.

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.

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.

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.