Stage 01 · Lesson 08/12

Math for Robotics · Lesson 08

Frames & Reference Frames

Est. 35–45 min

Why

Why robots keep a family tree of frames

Concept

The big idea: parent / child frames and composition

  • Each frame has a parent (except the root).
  • An edge stores the transform from parent to child (or child to parent — pick a convention and stick to it).
  • Composition: T_world_tool = T_world_base · T_base_link · T_link_tool
  • In ROS this tree is often called TF. Same idea everywhere.

How it works

How it actually works, step by step

  1. Draw the tree

    Boxes for frames, arrows for parent→child.

  2. Label each edge

    Write θ and (tx,ty) or a small matrix for that relative pose.

  3. Multiply along the path

    From root to the frame you care about, multiply transforms in order.

  4. Apply to a point

    Once you have T_world_tool, the tool origin in world is T applied to (0,0).

Visual

Visualise it: robot pose as chained frames

Adjust the robot pose controls and watch how child frames ride along with their parents.

Interactive · Robot pose / transformation demo

Tip (x, y)

(152.1, 75.4)

Tip yaw

-5.0°

Simplification: planar 2R arm. Each joint adds a rotation; tip pose is the product of link transforms — the same idea as homogeneous chains on a 6DOF arm.

Worked example

Worked example: base → link → tool

Code lab

Code lab: compose three transforms

frame_tree.py · Python
"""Stage 1 L08 — chain three planar transforms: world ← base ← link1 ← tool."""
import math

def T(theta_deg, tx, ty):
    th = math.radians(theta_deg)
    c, s = math.cos(th), math.sin(th)
    return ((c, -s, tx), (s, c, ty), (0, 0, 1))

def mul(A, B):
    C = [[0]*3 for _ in range(3)]
    for i in range(3):
        for j in range(3):
            C[i][j] = A[i][0]*B[0][j] + A[i][1]*B[1][j] + A[i][2]*B[2][j]
    return C

def apply(M, x, y):
    return (M[0][0]*x + M[0][1]*y + M[0][2], M[1][0]*x + M[1][1]*y + M[1][2])

T_WB = T(0, 0.0, 0.0)       # base at world origin for this demo
T_BL = T(45, 0.12, 0.0)     # link1 frame: origin 12 cm along base x, then turned 45°
T_LT = T(0, 0.10, 0.0)      # tool: 10 cm along the (turned) link x

T_WT = mul(mul(T_WB, T_BL), T_LT)
tip = apply(T_WT, 0, 0)
print("T_world_tool tip at origin of tool frame:")
print(f"  ({tip[0]*100:.2f} cm, {tip[1]*100:.2f} cm)")
print("Chain rule: T_WT = T_WB · T_BL · T_LT")

Expected output

T_world_tool tip at origin of tool frame:
  (19.07 cm, 7.07 cm)
Chain rule: T_WT = T_WB · T_BL · T_LT

Real world

TF trees and measuring arms

Articulated 3D measuring arm with jointed segments.
A measuring arm is a physical frame tree: each joint is an edge. Software TF trees for robot arms look the same on a diagram.Photo: Brechmann-Guss · CC BY-SA 3.0 · Source: Wikimedia Commons · resized, converted to WebP
  • ROS tf2 / TF tree: map → odom → base_link → … → tool0
  • CAD assemblies: part frames nested under a root

Mistakes

Common mistakes and confusions

Hardware & safety

Hardware lab and safety notes

Your desk lamp (or the paper arm) is a perfect frame tree: {desk} → {base} → {arm1} → {arm2} → {bulb}. Each joint is one edge in the tree.

  • Stick small paper labels on each part of the lamp with the frame name.
  • Measure one edge: e.g. arm1 is 30 cm long and makes 60° with the base.
  • Robots in ROS 2 keep exactly this kind of tree in tf2, updated many times per second.

Debugging

Debugging: when it doesn’t work

Symptom → likely cause → fix
SymptomLikely causeFix
Tip lands in a strange placeMultiplied in the wrong orderFollow the path: T_WT = T_WB · T_BL · T_LT
A frame is “not found”Orphan frame with no parentEvery frame except the root needs exactly one parent
Two parents for one frameLoop in the treePick one parent; trees have no loops
Tip off by the link lengthTranslation added in the wrong frameEach translation is in its parent's frame
NoteChange one thing at a time. Most Stage 1 bugs are units (degrees vs radians, mm vs m), order of multiplication, or a frame that was never named.

Think

Think about it

Think

If you only know T_base_tool and T_world_base, how do you get T_world_tool?

Experiment

Try it in the lab: tree on paper

Experiment

Tree on paper

You will need

  • Paper
  • robot-pose interactive

Steps

  1. Sketch world → base → link1 → tool.
  2. Invent simple numbers for each edge.
  3. Compose on paper, then compare to the code lab pattern.

Interactive · Robot pose / transformation demo

Tip (x, y)

(152.1, 75.4)

Tip yaw

-5.0°

Simplification: planar 2R arm. Each joint adds a rotation; tip pose is the product of link transforms — the same idea as homogeneous chains on a 6DOF arm.

The tip only depends on the product along the path — intermediate names are bookkeeping.

Knowledge check

Check your understanding

Knowledge check

1. A frame tree edge stores…

2. T_world_tool is usually…

3. ROS often calls this tree…

4. Wrong multiply order typically…

Practice quiz

Loading practice quiz…

Mini assignment

Hands-on assignment

Mini assignment

Your TF sketch

Draw a TF-style tree for a desk lamp or a desk arm toy: name each frame and one relative transform on each edge.

Deliverables

  • Tree sketch
  • One numeric edge

Do this, step by step

  1. Draw the frame tree for your lamp or paper arm (boxes and arrows).
  2. Write one transform on each edge: angle and translation.
  3. Put your numbers into frame_tree.py (T_BL, T_LT) and run it.
  4. Measure the real tip with a ruler and compare.

Stuck? Hints, one at a time

NoteTry the task first. Read one hint, try again, and only then read the next one.
  1. Hint 1: Start at the root ({desk} or {world}) and go one step at a time to the tip.
  2. Hint 2: Each T(angle, tx, ty): translation in the parent frame, then turn the child by angle.
  3. Hint 3: With base at origin, link frame 12 cm along x turned 45°, tool 10 cm further: tip = (12 + 10·cos45°, 10·sin45°) ≈ (19.07, 7.07) cm.

Challenges (pick by level)

  • 🟢 Easy: Add a {camera} frame on the base to your tree.
  • 🟡 Medium: Change T_BL to 90° and predict the tip before running.
  • 🟠 Hard: Add a fourth transform (a gripper 5 cm long, turned −30°) and print every frame's origin.

Next step

Next, Lesson 9: Rotation looks closely at the R part of each edge. Related: real TF trees in Stage 10 — ROS 2.

Sources

Self-attested for now — keep artifacts in your lab notebook.

Complete

Today's goal

0 of 1 done today

0-day streak
Daily goal:lessons, quizzes or assignments a day

Mark this lesson complete when you have worked the experiment, knowledge check, and assignment (even roughly).

Stuck somewhere?

Ask a doubt about this lesson

Saved with this lesson's id and your email so we can reply. Privacy · or email contact@aihubstation.in