Cookie CodersFTC Team 39092

TeleOp + Vision // Student lesson

Tele-Learn-AprilTagAlignment
AprilTag Alignment

Code Lab / Tele-Learn-AprilTagAlignment

Use Tele-Learn-AprilTagAlignment to reconstruct red or blue centers from real AprilTag Blocks and trace the held Square override of manual mecanum drive. Learn identifies an educational example, not permission to run it. The source lacks a validated vision-freshness gate and wall protection; keep this a supervised code study until independently reviewed.

Latest-result retrieval is not an age or distinct-frame check. Read the literal X/Y/Z projections, the mounting-specific back-right direction, and the stronger front-right turn command. The sample selects a nearer center again each loop rather than locking an alliance while Square is held.

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

Mission control

Read, predict, compare, explain.

22source-linked steps
7scored quiz checks
Start with a question

If the camera sees a tag left of the target's middle, why is pointing at that tag not the same as pointing at the calculated center?

  • Camera coordinates
  • Tag IDs
  • Sine and cosine
  • atan2

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.

Start with a question

If the camera sees a tag left of the target's middle, why is pointing at that tag not the same as pointing at the calculated center?

By the end, you can…

  • Reconstruct hidden endpoints using signed offsets, degree trig, and camera-space meters.
  • Require matching half-groups before choosing a complete red or blue center.
  • Trace manual normalization and the priority of held Square alignment.
  • Identify missing freshness guarantees and distinguish a sticker range from an alliance-center range.

01Erase visibility before each scan

Actual Blocks for this section
Blocks for Erase visibility before each scan
Blocks to noticeHover, focus or tap a block to see what it does.
  • Sets found to false at the start of each scan, so no center counts as usable until this scan finds a complete pair of halves.
  • Clears the four endpoint-seen flags, so a half spotted in an earlier scan cannot count toward a red or blue center now.
  • Resets the displayed tag, sticker, and red-center distances to a not-visible or not-available message so old readings are not shown. It does not prove a new frame.

scanTags clears found, the four endpoint flags, and the displayed tag distances before inspecting a result. Red-center display becomes not available. TeleOp also clears the four sticker-distance displays. Old coordinates can remain in variables, but cleared flags prevent a missing half from completing a center. Resetting state is not the same as proving the camera returned a new frame.

For example: A scan with R4 and R5 can set found true. A later scan containing only R4 leaves r5Seen false and cannot rebuild the red center.

Think first

May yesterday's r5 coordinates complete today's red center when r5Seen is false?

Show Answer

No. Both endpoint flags must be true in this scan; stored numbers alone are insufficient.

02Read a result, then its fiducial list

Actual Blocks for this section
Blocks for Read a result, then its fiducial list
Blocks to noticeHover, focus or tap a block to see what it does.
  • Asks the Limelight camera for its newest processed result, which may hold zero, one, or many tags. It does not check how old that result is.
  • True when the camera returned a result, so the tag-reading blocks only run then. A non-null result can still hold an empty tag list.
  • Gets the list of recognized AprilTag markers (fiducials) from the result. The list can be empty.
  • Stores the fiducial list in the variable list so the loop that follows can visit each tag one at a time.

The non-null branch reads the result's list of fiducials, meaning recognized markers. A non-null result can still contain an empty list. These AprilTag sources do not check IsValid, Staleness, pipeline index, or a distinct frame timestamp here. Calling getLatestResult does not itself guarantee a fresh image, so this sample is not a validated freshness guard.

For example: An empty current list builds no center. Repeated retrieval of an old nonempty result could repeat the same geometry even though all flags were reset.

Think first

Does the non-null test prove that the image is less than 250 ms old?

Show Answer

No. There is no age comparison in this scan; null handling and freshness are separate checks.

03Repeat camera-space geometry for each tag

Actual Blocks for this section
Blocks for Repeat camera-space geometry for each tag
Blocks to noticeHover, focus or tap a block to see what it does.
  • Repeats the blocks inside once for every tag in the list, with the variable tag holding the current one. Several tags in one result are not several camera frames.
  • Gets the tag's position and rotation measured from the camera. It is a camera-to-tag observation, not the robot's location on the field.
  • Stores that camera-space pose in the variable pose so the next blocks can read its x, y, z, yaw, and pitch.

For each fiducial, the source retrieves its TargetPoseCameraSpace: position plus orientation relative to the camera, not a robot field pose. The instructional convention calls x left/right, y up/down, and z forward/back; yaw and pitch describe rotation, not wireless transmit/receive. Later projection formulas must be read literally and checked against the SDK pose convention before any physical use.

For example: Two tags in the list produce two passes through the position, angle, ID, and offset calculations; they are not two distinct camera frames.

Think first

Is a camera-space tag pose automatically a field location of the robot?

Show Answer

No. It is a relative camera-to-tag observation; field localization would need additional transforms and references.

04Keep signs until distance is calculated

Actual Blocks for this section
Blocks for Keep signs until distance is calculated
Blocks to noticeHover, focus or tap a block to see what it does.
  • Reads the tag's left/right distance from the camera in meters. The sign tells which side, so it is kept.
  • Reads the tag's up/down distance from the camera in meters. The sign is kept for the center math that follows.
  • Reads the tag's forward/back distance from the camera in meters, keeping the sign.
  • Saves the three signed positions in variables x, y, and z so later blocks can compute range and endpoints.

The pose getters copy all three signed coordinates in meters. Signs matter when adding an offset and when computing steering. Squaring for range removes signs only at that later calculation; taking absolute values first would lose which side the reconstructed center lies on.

For example: A practice pose (-0.30, 0.40, 0.00) m has a 0.50 m range, but its negative x is still important to direction.

Think first

Do x = -0.30 m and x = +0.30 m contribute different amounts to x*x?

Show Answer

No. Both contribute 0.09 square meters, although their signed positions differ.

05Use degree-based yaw and pitch

Actual Blocks for this section
Blocks for Use degree-based yaw and pitch
Blocks to noticeHover, focus or tap a block to see what it does.
  • Reads the tag pose's yaw, its left/right turning angle, in degrees. The Blocks trig operations expect degrees, so it is not converted.
  • Reads the tag pose's pitch, its up/down tilt angle, in degrees and stores it for the trig blocks that follow.
  • Takes the sine of an angle in degrees. Later, sin(yaw) sets the Y part of an offset and sin(pitch) sets the Z part.
  • Takes the cosine of an angle in degrees. Later, cos(yaw) and cos(pitch) scale how much of a strip offset is added to X and Y.

The source copies yaw and pitch from the pose and passes them to Blocks trig operations, which use degrees. Yaw is taught as a left/right rotation and pitch as a tilt. Do not insert a student radians conversion into this chain: it would change the inputs the Blocks operations expect. Review the exact axis mapping as well as the angle units.

For example: At yaw = 0 and pitch = 0, cosines are 1 and sines are 0, so an offset changes only the source's endpoint X.

Think first

Should a 90-degree pose angle be manually replaced with about 1.57 before the COS block?

Show Answer

No. This Blocks operation expects degrees; cos(90 degrees) is 0.

06Measure the line to a tag center

Actual Blocks for this section
Blocks for Measure the line to a tag center
Blocks to noticeHover, focus or tap a block to see what it does.
  • Squares each camera-space coordinate by multiplying it by itself, so the signs drop out of the distance calculation.
  • Adds the three squared coordinates together to get the sum that goes under the square root in the 3D distance formula.
  • Takes the square root of that sum, giving the straight-line distance from the camera to the tag center in meters.
  • Converts meters to inches by multiplying by 39.3701, then stores the result as this tag's range.
  • Reads the number of the AprilTag, which the program compares with 30 through 45 to find the tag's group and offset.
  • Reads the camera's own left/right angle to this tag, in degrees, and stores it as tx. Center steering later uses a rebuilt angle instead.

Square each camera-space coordinate, add all three, take the square root, then multiply by 39.3701 inches per meter. This range is to the individual visible tag center, not yet a sticker or alliance center. The source also reads the physical tag ID and its raw TargetXDegrees; later center steering replaces that raw angle with a reconstructed-center angle.

For example: For (0.30, 0.40, 0) m: sqrt(0.09 + 0.16) = 0.50 m, or about 19.685 inches.

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

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

Think first

What goes wrong if you omit y when it is 0.40 m in this example?

Show Answer

You get 0.30 m instead of 0.50 m and understate the full camera-to-tag distance.

07Require a pair of matching half-groups

Actual Blocks for this section
Blocks for Require a pair of matching half-groups
Blocks to noticeHover, focus or tap a block to see what it does.
  • Starts each tag as unassigned by setting its group to -1. Only a recognized tag ID changes it to 0 through 3.
  • Starts each tag with an offset of 0 inches until its ID is recognized and a real offset is assigned.
  • Groups 0 and 1 are the two red halves that give endpoints R4 and R5. Groups 2 and 3 are the blue halves for B4 and B5.
  • Turns on r4Seen, r5Seen, b4Seen, or b5Seen when a tag from that half is read. A center needs both flags of one color.

Each tag begins unassigned at group -1 and offset 0. IDs 30-33 form group 0 and reconstruct R4; 34-37 form group 1 and reconstruct R5. Groups 2 and 3 similarly reconstruct B4 and B5 from IDs 38-41 and 42-45. One visible tag from each matching pair of groups is sufficient; two tags from only one group are not.

For example: IDs 30 and 37 can supply both red endpoints. IDs 30 and 31 supply only the R4 half, however many times they are read.

Think first

Can group 0 plus group 3 form a complete red or blue center?

Show Answer

No. The required pairs are 0 with 1, or 2 with 3.

08Convert tag identity into a signed known offset

Actual Blocks for this section
Blocks for Convert tag identity into a signed known offset
Blocks to noticeHover, focus or tap a block to see what it does.
  • Checks the tag's ID against each number from 30 to 45 to work out which red or blue tag the camera saw.
  • Records which half-group, 0 through 3, the tag belongs to, based on its ID.
  • Stores the signed distance in inches from this tag to its group's endpoint, such as +13 for R1 or -13 for R8.
  • Saves this tag's measured range in the display variable for that exact tag, from R1 through B8, so telemetry can show it.

IDs 30-37 are R1-R8; 38-45 are B1-B8. Within each four-tag sticker the centers sit at -6.5, -2.75, +2.75, +6.5 inches. To reconstruct endpoint 4, the first half uses offsets +13, +9.25, +3.75, 0; to reconstruct endpoint 5, the second half uses 0, -3.75, -9.25, -13. These are signed tag-to-endpoint corrections, not the tag's measured range. TeleOp additionally uses tag-to-sticker offsets +6.5, +2.75, -2.75, -6.5.

For example: R1 at ID 30 is 13 inches left of R4, so its endpoint correction is +13. R8 at ID 37 gets -13 to reconstruct R5.

Think first

For R6, ID 35, is the endpoint offset +3.75 or -3.75 inches?

Show Answer

It is -3.75 inches: move back along the strip from R6 to R5.

09Project the strip offset exactly as written

Actual Blocks for this section
Blocks for Project the strip offset exactly as written
Blocks to noticeHover, focus or tap a block to see what it does.
  • Converts the offset from inches to meters by dividing by 39.3701, so it matches the camera's meter units.
  • Finds cos(yaw) in degrees. The written X formula multiplies the offset by it.
  • Finds sin(yaw) in degrees. The written Y formula multiplies the offset by it.
  • Finds cos(pitch) in degrees. The X and Y formulas both multiply the offset by it.
  • Finds sin(pitch) in degrees. The Z formula subtracts the offset times this value.
  • Stores the shifted endpoint: X = x + d*cos(yaw)*cos(pitch), Y = y + d*sin(yaw)*cos(pitch), Z = z - d*sin(pitch), where d is the offset in meters.

Let d be the signed inch offset divided by 39.3701. The source reconstructs X = x + d*cos(yaw)*cos(pitch), Y = y + d*sin(yaw)*cos(pitch), Z = z - d*sin(pitch). Notice that yaw contributes to X and Y in these actual Blocks, while pitch changes Z. That is not the usual simplified claim that yaw rotates an offset between X and Z. Treat pose-axis interpretation as a supervised verification task, not an already proven physical model.

For example: For d = 0.10 m, yaw = 90 degrees and pitch = 0, the written equations add about 0 to X, +0.10 to Y, and 0 to Z.

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.

Think first

At yaw = 0 and pitch = 90 degrees, what is the signed Z correction for positive d?

Show Answer

Z decreases by d, because the source subtracts d*sin(pitch); X and Y corrections are zero.

10Separate sticker distance from alliance-center distance

Actual Blocks for this section
Blocks for Separate sticker distance from alliance-center distance
Blocks to noticeHover, focus or tap a block to see what it does.
  • Projects the tag-to-sticker-middle offset with the same formulas, giving the 3D position of the middle of this tag's own four-tag sticker.
  • Calculates the straight-line distance in inches from the camera to that sticker middle, using clusterX, clusterY, and clusterZ.
  • Stores the sticker distance by group: 0 fills redScoring, 1 redAudience, 2 blueAudience, 3 blueScoring. A later tag in the same group overwrites it.
  • Turns on the matching endpoint flag (r4Seen, r5Seen, b4Seen, or b5Seen). One half alone is not a full alliance center.

clusterOffset goes from a visible tag to the middle of its own four-tag sticker. The source projects it with the same X/Y/Z equations and calculates a 3D clusterRange. Group 0 fills redScoring, 1 redAudience, 2 blueAudience, 3 blueScoring. Separate offset calculations then reconstruct R4/R5/B4/B5 for the alliance midpoint. Multiple tags in one group overwrite that group's estimate in list order; there is no averaging or best-confidence selection.

For example: ID 30 has +6.5 inches to its sticker middle but +13 inches to R4. These two different corrections must not be interchanged.

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.

Think first

Does one visible tag on the red scoring sticker prove that the complete red alliance center exists?

Show Answer

No. It gives that sticker's distance and the R4 endpoint estimate; the R5 half is still required.

11Average coordinates, then find range and bearing

Actual Blocks for this section
Blocks for Average coordinates, then find range and bearing
Blocks to noticeHover, focus or tap a block to see what it does.
  • True only when this scan saw a tag from both red halves. The same test with b4Seen and b5Seen guards the blue center.
  • Averages the two endpoints' X, Y, and Z values to get the midpoint between them. It averages coordinates, not ranges.
  • Finishes the 3D distance to the midpoint: the root of X*X + Y*Y + Z*Z, which is then multiplied by 39.3701 to give inches.
  • Turns the center's X and Z values into a signed left/right angle in degrees, atan2(X, Z). This becomes the steering error.
  • Copies the red center's range in inches into redCenterDistance for display. It stays not available until both red halves are seen.

A complete red pair averages R4 and R5 coordinates; a complete blue pair averages B4 and B5. Each midpoint's 3D magnitude becomes its inch range. atan2 uses center X as the numerator-like Y socket and center Z as the X socket, giving atan2(center X, center Z) in degrees. This reconstructed bearing, not the raw visible tag's tx, guides centering. It is a geometric midpoint estimate, not full field GPS or multi-camera triangulation.

For example: Endpoints (-0.20, 0, 1.00) and (+0.40, 0, 1.00) m yield center (0.10, 0, 1.00), range about 39.57 inches, and tx about +5.71 degrees.

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

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

Think first

Can you obtain the same midpoint by averaging the two endpoint ranges?

Show Answer

Not in general. Average the signed coordinates first, then compute the center's magnitude.

12Choose a center anew each driver loop

Actual Blocks for this section
Blocks for Choose a center anew each driver loop
Blocks to noticeHover, focus or tap a block to see what it does.
  • Checks whether this scan should choose a center. Each TeleOp loop sets selecting to true first, so it chooses again every loop.
  • True only when a complete center is strictly nearer than the best so far. Red is tested first, so a tie keeps red.
  • Records the winner as 0 for the red center or 1 for the blue center. These are not AprilTag numbers.
  • Saves the chosen center's distance in inches and its angle in degrees for the Square alignment and the telemetry.
  • Sets found to true when a complete center has been selected, which lets Square alignment steer toward it.

selectedId 0 means red center and 1 means blue center, not physical tag IDs. Each active TeleOp loop resets selection to -1 and selectedRange to 9999, then chooses the nearer complete center. Red is tested first and blue replaces it only if strictly nearer; equal ranges retain red. found becomes true only for an available selected pair. Holding Square does not lock an alliance across loops.

For example: Red 40 inches and blue 35 choose selectedId 1. On the next loop red 30 and blue 35 choose 0, even if Square is still held.

Think first

With red and blue both at 40 inches in a selecting scan, which wins?

Show Answer

Red, selectedId 0. Blue's strict less-than test cannot replace an equal range.

13Prepare drive outputs at zero

Actual Blocks for this section
Blocks for Prepare drive outputs at zero
Blocks to noticeHover, focus or tap a block to see what it does.
  • Sets which way positive power spins each drive motor. Front-left, back-left, and back-right are reversed and front-right is forward. Check these on the real robot.
  • Makes a motor resist turning when its power is zero instead of coasting. It does not hold an exact position or guarantee an instant stop.
  • Runs each motor directly from the power value without encoder speed control. A power request is not an exact wheel speed.
  • Sets all four drive motors to zero power during setup, so no movement is requested before START.
  • Requests that camera results be polled 100 times per second. This is only a request, not a guaranteed number of new frames.
  • Selects Limelight pipeline 0, the saved camera setup this program expects to detect AprilTags. The camera must really be configured that way.

Both left motors and back-right are REVERSE; front-right is FORWARD. All four use BRAKE and RUN_WITHOUT_ENCODER and start at zero. The setup also requests 100 Hz polling and pipeline 0. These device-specific settings are not proof of correct wheel motion, and a requested poll rate is not a guaranteed processed-frame rate.

For example: A 100 Hz poll request can read the same processed result repeatedly; it does not create 100 independent tag observations per second.

Think first

Is back-right FORWARD in this TeleOp source, as it is in AprilTagAuto?

Show Answer

No. TeleOp sets back-right REVERSE, so review each source's direction profile independently.

14Start vision before the INIT scan

Actual Blocks for this section
Blocks for Start vision before the INIT scan
Blocks to noticeHover, focus or tap a block to see what it does.
  • Starts the Limelight so it begins processing images, which lets the INIT scan see tags. Starting it does not prove the results are fresh.
  • Adds a line telling the driver that holding Square aligns to the calculated center. Telemetry only displays text and does not change robot behavior.

The source starts the Limelight after selecting pipeline 0 so INIT can inspect tags. Pipeline 0 must actually be configured for the expected AprilTags on this camera. The instructions mention fresh results, but scanTags does not validate their age or pipeline index; starting the camera is necessary, not sufficient for safe vision control.

For example: A pipeline 0 configured for color detection is not interchangeable with this lesson's AprilTag pipeline 0.

Think first

Does the number 0 mean the same detection task on every Limelight?

Show Answer

No. It names a camera configuration slot whose contents must be checked.

15Inspect individual tags before movement

Actual Blocks for this section
Blocks for Inspect individual tags before movement
Blocks to noticeHover, focus or tap a block to see what it does.
  • Repeats its blocks while the OpMode is initialized but START is not yet pressed, giving a live tag preview before driving.
  • Runs the custom scanTags block, which reads the camera and rebuilds every tag, sticker, and center value from the newest result.
  • Adds the eight red tag distances R1 through R8 to telemetry, each showing inches or the not-visible message.
  • Adds the red center distance to telemetry. It shows a number only when both red halves were seen, otherwise not available.
  • Lets the system do other background work briefly on each pass through the INIT loop.

INIT repeatedly scans and displays R1-R8 and the reconstructed red-center distance while setup's zero motor requests remain in place. Individual tags can be visible while the red center stays not available because the matching half is absent. This is a preview, not a motion authorization or a separate wall guard.

For example: Seeing R1 and R2 can fill two tag-distance rows but cannot make redCenterDistance available without one R5-R8 observation.

Think first

Can a visible R1 distance alone justify Square alignment to the red center?

Show Answer

No. Center construction requires an endpoint estimate from both red halves.

16Wait, then refresh selection every active loop

Actual Blocks for this section
Blocks for Wait, then refresh selection every active loop
Blocks to noticeHover, focus or tap a block to see what it does.
  • Pauses the program, with the motors at zero, until the driver presses START on the Driver Station.
  • Repeats the blocks inside again and again after START until the driver presses STOP.
  • Sets selecting to true at the top of every loop so the scan chooses a center fresh instead of keeping the last one.
  • Clears the chosen center to -1, meaning none yet. Later 0 means the red center and 1 means the blue center.
  • Sets the best distance so far to a huge 9999, so any complete center found this loop counts as nearer.
  • Runs scanTags each loop to refresh tag visibility, centers, and the chosen target. It does not check how old the camera result is.

waitForStart separates INIT from driving. Each active loop then clears the target choice and rescans, so the nearest complete center can change between loops. Joysticks are read after this scan. The source has no held-bumper deadman gate for vision turning.

For example: A blue center can win one loop and red the next if their computed ranges change order while Square remains held.

Think first

Does holding Square freeze selectedId until release?

Show Answer

No. Selection is restarted each active loop.

17Build the manual command first

Actual Blocks for this section
Blocks for Build the manual command first
Blocks to noticeHover, focus or tap a block to see what it does.
  • Flips the left-stick up/down reading, because FTC reports pushing up as negative, so pushing forward gives a positive forward value.
  • Uses the left stick's side-to-side reading directly as the sideways request. Right is positive and left is negative.
  • Uses the right stick's side-to-side reading directly as the turn request, with its sign kept.
  • True while the left bumper is held. Holding it lowers speed from 1 to 0.35 for manual driving only; it is not a toggle.
  • Adds the absolute values of forward, strafe, and turn so opposite signs cannot cancel, measuring the total manual demand.
  • Replaces a sum below 1 with 1, so small requests are not made larger and neutral sticks never divide by zero.

Manual driving uses the same signed inputs and normalization as Start: negate controller Y, retain left X and right X, choose speed 1 or held-bumper 0.35, and use max(1, sum of magnitudes). This branch calculates the manual request even when Square will override the outputs later.

For example: Full forward with LeftBumper held requests four manual powers of 0.35 before the Square branch runs.

Think first

Does the bumper's 0.35 automatically scale the later fixed Square-turn powers?

Show Answer

No. Square writes its own fixed powers after the manual calculation.

18Send manual powers before an override

Actual Blocks for this section
Blocks for Send manual powers before an override
Blocks to noticeHover, focus or tap a block to see what it does.
  • Sets the front-left motor power to speed * (forward + strafe + turn) / denominator.
  • Sets the front-right motor power to speed * (forward - strafe - turn) / denominator.
  • Sets the back-left motor power to speed * (forward - strafe + turn) / denominator.
  • Sets the back-right motor power to speed * (forward + strafe - turn) / denominator.
  • Divides each wheel's sum by the shared denominator, so large combined requests shrink equally and manual powers stay within -1 to +1.
  • Multiplies each wheel by speed, 1 normally or 0.35 while the left bumper is held. Square may overwrite the result afterward.

The four mecanum formulas send bounded manual commands. Square is checked afterward and can replace all four in the same loop. This ordering matters: a final zero Square decision overrides a forward joystick request; it does not imply the manual calculation never occurred. The source is not a single gated output stage.

For example: With forward 1 and Square held but no complete center, manual writes are followed by four zero writes; the final requests are zero.

Think first

Which command should the final motor Power telemetry show when an active Square branch writes zero?

Show Answer

The later zero request, not the earlier normalized joystick value.

19Override only while Square is held

Actual Blocks for this section
Blocks for Override only while Square is held
Blocks to noticeHover, focus or tap a block to see what it does.
  • Runs the alignment override only while the Square button is held. Letting go returns control to the joysticks on the next loop.
  • Checks that a complete red or blue center was selected this loop. If not, the else part writes zero to all four motors.
  • True when the center's angle error is within 2 degrees of zero, so the robot gets zero power instead of turning.
  • Writes fixed turning powers: for positive error FL and BL +0.18, FR -0.24, BR -0.18; negative error flips the signs. The bumper does not scale them.
  • Writes zero to all four motors, either when the center is within 2 degrees or when no complete center was found.

Held Square replaces joystick powers. With found true and |currentTx| <= 2 degrees, all four receive zero immediately; there is no five-check counter in this TeleOp. For positive error, FL/BL are +0.18, FR -0.24, BR -0.18; negative error reverses those signs. No complete center means zero. Releasing Square restores manual control next loop, even if the joystick is still held. The fixed turn powers are not bumper-scaled.

For example: At currentTx +3 degrees, final FL/FR/BL/BR requests are +0.18, -0.24, +0.18, -0.18. At exactly +2 degrees they are all 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.

Think first

If Square is released with forward still 1, will the robot remain in the alignment stop?

Show Answer

No. Manual driving resumes next loop; release the sticks too when a stop is intended.

20Read the four sticker-distance rows in their branch

Actual Blocks for this section
Blocks for Read the four sticker-distance rows in their branch
Blocks to noticeHover, focus or tap a block to see what it does.
  • Shows the distance in inches to the middle of the red scoring sticker (IDs 30-33), or not visible. Added only in the Square centered branch.
  • Shows the distance to the middle of the red audience sticker (IDs 34-37), or not visible. Added only in the Square centered branch.
  • Shows the distance to the middle of the blue audience sticker (IDs 38-41), or not visible. Added only in the Square centered branch.
  • Shows the distance to the middle of the blue scoring sticker (IDs 42-45), or not visible. Added only in the Square centered branch.

The rows refer to IDs 30-33 red scoring, 34-37 red audience, 38-41 blue audience, and 42-45 blue scoring. Each is a distance to its sticker's reconstructed middle, not to one tag or to the alliance midpoint. In the actual chain these four addData blocks are inside Square's found-and-centered branch, not unconditional live displays after START. A missing row is not the same as a fresh not visible value.

For example: While Square is turning at +3 degrees, this branch does not add the four rows. With found true and error +1 degree, it does.

Think first

Does seeing no cluster row while driving manually prove that the camera sees no cluster?

Show Answer

No. The source adds these rows only in the held-Square centered branch; inspect branch execution as well as detection.

21Separate raw input from final alignment output

Actual Blocks for this section
Blocks for Separate raw input from final alignment output
Blocks to noticeHover, focus or tap a block to see what it does.
  • Adds a Square align status row: CENTERED, turning to center, or need one visible tag from each half. It shows only while Square is held.
  • Shows the chosen center's angle error in degrees and its distance in inches. Added only when Square has found a center.
  • Shows the raw forward, strafe, turn, and speed values from the joysticks, before any Square override changes the final motor powers.
  • Reads each drive motor's current Power setting, the final request after any Square override. It is not measured wheel speed.
  • Sends all the rows added this loop to the Driver Station screen. It does not make the camera data any fresher.

Alignment status explains whether Square centered, turned, or lacked the matching halves. Command rows still report raw manual calculations, while motor Power rows report final requests after any override. Center error and distance are added only when Square has found a center. update sends the assembled display, not a freshness guarantee for its camera data.

For example: Forward command 1 and motor powers 0 can coexist when held Square finds a centered target. The rows describe different stages of the loop.

Think first

Which rows reveal what was finally requested when raw manual turn disagrees with alignment?

Show Answer

The four motor Power rows, interpreted with Square status; they still do not measure actual wheel speed.

22End both driving and camera polling

Actual Blocks for this section
Blocks for End both driving and camera polling
Blocks to noticeHover, focus or tap a block to see what it does.
  • After the active loop ends, writes zero power to all four drive motors. Zero power does not guarantee an instant stop.
  • Stops the Limelight camera so it no longer processes images once the driving loop has ended.

After the active loop exits, the source requests zero on every motor and stops the Limelight. Driver Station STOP ends the OpMode. Square release is not program termination and can resume manual motion. Do not treat camera loss handling, source enabled metadata, or an educational name as certification of an independent safety system.

For example: Use STOP to end a trial with an unexpected wheel sign; do not merely release Square while a joystick requests travel.

Think first

Does releasing Square also stop the Limelight and end the OpMode?

Show Answer

No. It only removes the alignment override; final camera cleanup occurs after loop exit.

Try it without a robot

Make the math make sense

Use a notebook or talk through your answer with a partner. You do not need a robot to predict what these blocks will do.

tag range (in) = sqrt(x*x + y*y + z*z) * 39.3701
Camera-space position is in meters. Include height y, and convert the 3D straight-line distance to inches.
d = offset (in) / 39.3701
Put a known strip offset in meters before adding it to the pose.
endpoint X = x + d*cos(yaw)*cos(pitch); Y = y + d*sin(yaw)*cos(pitch); Z = z - d*sin(pitch)
These are the actual source projections, using degree-based Blocks trig. Do not replace them with an assumed X/Z yaw formula. The physical pose-axis interpretation needs supervised verification.
center = (endpoint 4 + endpoint 5) / 2 on each axis
Average reconstructed endpoint coordinates, not tag ranges. One observation from each matching half is required.
center range = sqrt(X*X + Y*Y + Z*Z)*39.3701; center tx = atan2(X,Z)
Range includes all three axes. The Blocks atan2 sockets hold X-socket = center Z and Y-socket = center X, giving the signed horizontal angle in degrees.
manual D = max(1, |forward| + |strafe| + |turn|); speed = LeftBumper ? 0.35 : 1
This bounds manual mecanum powers, not the later fixed Square alignment outputs.
Square centered when found AND |currentTx| <= 2 degrees
One loop's center test selects zero power. This TeleOp has no five-frame settling counter or result-age test.
cluster d = clusterOffset / 39.3701
Use the same projection equations with the sticker-middle offset; endpoint offsets and sticker offsets have different destinations.

1. Reconstruct the two destinations

On paper take R1 at x = 0, y = 0, z = 1 m, yaw = pitch = 0. Calculate its sticker-center X using +6.5 inches and its R4 X using +13 inches. Then pair R4 (-0.20,0,1) with R5 (+0.40,0,1) and calculate the midpoint, range, and atan2 angle.

2. Trace the override and target choice

Write a final-power table for full forward with bumper held: Square released; Square held with found false; found true with tx +3; found true with tx +2; Square released again. Separately trace red/blue ranges 40/35, then 30/35, then 40/40. Does Square lock selectedId?

3. Audit what the sample actually guarantees

List the reset, null, matching-half, centered, and cleanup checks. Then list the missing age, distinct-frame, and wall checks. Draw where the four cluster telemetry blocks sit in the conditional tree and explain why no row is not proof of no detection.

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.

Full-program context

Explore the full Blocks program

One source program, in one column. Calls connect any named helper routines; they are not separate programs. Click a numbered blue comment to return to its explanation.

Full commented Blocks program
100%

Ask your supervisor before importing or running these Blocks. Viewing the program does not control the robot.

Section in context

Full Blocks program

The highlighted Blocks belong to this section. You can select another blue comment.

Check your understanding

Your turn

Choose an answer, then check your thinking. You can change an answer and try again.

Your answers stay on this page and reset when you reload. No cookies, account, or saved answers.

0 / 7 correct · 0 / 7 answered

0
0
Question 1Which visible pair can reconstruct a red center in one scan?

Question 2For offset d = +0.10 m, yaw 90 degrees, pitch 0, what does the written source add?

Question 3Square is held, found is true, and currentTx is +3 degrees. What final FL/FR/BL/BR powers are written?

Question 4In a selecting scan red and blue centers both have range 40 inches. Which selectedId remains?

Question 5What does resetting flags and retrieving a non-null latest result prove?

Question 6When does the actual chain add the four sticker-distance rows?

Question 7Square is released while the forward joystick remains held. What follows?

Reset clears every choice, explanation, and score.

Adult supervision · setup · safety

Supervisor notes

For supervisors: 90-minute teaching plan & robot setup

Before the robot is used

Safety: Learn identifies a teaching example only. Do not deploy or enable this lesson as competition-ready code. It has no result-age gate, distinct-frame validation, or wall guard, and manual powers are written before the Square override. Physical review must precede any separately authorized wheels-clear demonstration. Use an operator and supervisor at STOP, clear the mechanism, and isolate power for inspection. Releasing Square can resume manual driving.

Required hardware & dependencies

  • Four mecanum drive motors named front_left_drive, front_right_drive, back_left_drive, and back_right_drive; verify each configured name against its physical cable and wheel.
  • FTC Robot Controller, Driver Station, secure battery, and a notebook. Motor direction settings are specific to the source and mounting, not universal wiring instructions.
  • Limelight 3A configured as limelight, expected AprilTag pipeline 0, accurate tag sizes and camera setup.
  • Verified ID 30-45 target layout with -6.5/-2.75/+2.75/+6.5 inch sticker positions and matching halves; paired gamepad exposing Square and LeftBumper.

Source remains AprilTagTeleOp.blk. Dependencies are the FTC SDK's native Limelight 3A Blocks, device limelight, four exact motor names, a verified AprilTag pipeline 0, and the source's ID/offset layout. No helper ZIP is provided. Enabled metadata and a Learn label do not authorize physical operation; review freshness, coordinate conventions, wheel signs, and safety separately.

Robot setup checklist

  1. Inspect AprilTagTeleOp.blk using supported native FTC/ Limelight Blocks. Resolve missing device/API blocks before considering hardware work; no invented support bundle is required by this page.
  2. Verify pipeline contents, physical tag layout, camera pose-axis convention, and literal source projection signs. The term triangulated in source telemetry does not establish field localization accuracy.
  3. Review FL/BL/BR REVERSE, FR FORWARD, RUN_WITHOUT_ENCODER, and the +/-0.24 front-right alignment bias. Do not copy the autonomous direction profile here.
  4. Plan paper traces for stale results, missing halves, and Square release. Enabled metadata and a Learn label do not replace an independent freshness/safety assessment.

90-minute teaching sequence

  1. 0-15 min

    Map IDs, matching halves, sticker middles, and endpoint destinations.

    Look for: One tag from each matching half, not simply any two tags.

  2. 15-40 min

    Calculate signed endpoint corrections, literal trig projections, midpoint range, and bearing.

    Look for: Meter/inch consistency and source Y projection with sin(yaw).

  3. 40-60 min

    Trace manual power writes, Square overrides, and target reselection.

    Look for: Students preserve the stronger front-right command and distinguish held override from target lock.

  4. 60-90 min

    Audit telemetry nesting, missing freshness checks, and safety claims; complete quiz and exit ticket.

    Look for: No-row, not-visible, stale-data, and zero-command statements are not confused.

Observation notebook

Notebook: one scan's evidence and one loop's final requests
Visible IDs / result evidenceAvailable halvesSelected center / txSquareFinal FL / FR / BL / BR
30 and 31; age unverifiedRed first onlyNoneHeld0 / 0 / 0 / 0
30 and 37; worked poseBoth redRed / +3 degreesHeld0.18 / -0.24 / 0.18 / -0.18
Both centers; red = blue rangeBoth alliancesRed / +2 degreesHeld0 / 0 / 0 / 0

Also record raw manual input separately. Mark result age as unverified in this source, and note whether the cluster-display branch actually ran.

Troubleshooting · stop before investigating

Tags show ranges but no red center exists.
Check for at least one ID 30-33 AND one ID 34-37 in the same scan. Multiple tags from one sticker do not replace the other half.
Cluster rows disappear while manual driving.
Inspect the actual nesting: rows are added only in held-Square found-and-centered behavior. Do not invent a camera failure from absent rows.
Alignment changes alliance while Square remains held.
That follows per-loop reselection. Record red and blue ranges and the strict comparison; this sample has no held target lock.
A target pose or command sign looks wrong.
Keep the robot stopped. Verify camera-space axes, the literal yaw/pitch projection, motor mapping, and FR bias; do not patch signs blindly.
Display seems current but follows an old image.
A latest-result call is not a freshness guarantee. Review frame age and deduplication requirements separately; do not approve physical operation from this scan alone.

Exit ticket & assessment

  1. Explain why IDs 30 and 31 cannot make a red center.
  2. Calculate the source's correction at yaw 90 and pitch 0.
  3. Describe Square release and one missing safety check.

Assessment: Pass requires correct ID grouping, signed unit conversion, literal projections, selection ties, and final override powers. Students must also identify missing age validation and the conditional cluster rows; an educational label is never accepted as safety evidence.

Extension challenge: Sketch a non-deployed design for a single output stage with explicit result age and target-lock evidence. Separate proposed improvements from what the authentic Blocks currently do.

Teacher key · discuss after students predict

Two R1 corrections

At zero angles sticker X adds 6.5/39.3701, about 0.16510 m; R4 X adds 13/39.3701, about 0.33020 m. They have different destinations.

Midpoint practice

The supplied endpoints average to (0.10,0,1) m: range about 39.57 inches, bearing about +5.71 degrees. Averaging individual ranges is not equivalent.

Override table

Bumper-held full forward gives four 0.35 manual requests. Held Square with no center or tx +2 gives zeros; tx +3 gives 0.18,-0.24,0.18,-0.18. Releasing Square returns to manual 0.35.

Target and freshness

Range pairs 40/35, 30/35, 40/40 choose blue, red, red. Reset flags are scan-local, not a frame-age check. Cluster rows are conditional, not unconditional post-START telemetry.