Transform Networks (TF Trees)
Once a robot has a base, a shoulder, an elbow, a wrist, a camera, and objects sitting on a table, keeping track of loose (x, y, θ) offsets by hand falls apart fast. You need a clean data structure that connects every frame together without creating contradictions.
Core ideas covered in this module
- Homogeneous transform matrices
- Directed TF trees & inversions
- 3D orientations & quaternions
Packing rotation and translation into one matrix
Instead of applying a rotation and then adding a translation vector as two separate steps, we can tuck both into a single 3×3 homogeneous matrix in 2D (or 4×4 in 3D). That trick lets us chain ten coordinate changes together simply by multiplying matrices in order.
Even better: because a rigid motion never squishes or stretches space, every transform matrix has a clean inverse that walks backward from child to parent.
Why a directed tree (and never a loop)
In systems like ROS (TF2), Drake, and MuJoCo, every frame has exactly one parent frame, forming a directed tree rooted at world. Why forbid loops? Imagine storing both world → camera and wrist → camera independently: the moment a joint angle updates slightly out of sync, the camera would disagree with itself on where it is.
With a tree, there is always one unique path between any two frames — say, from mug up to world and back down through the arm to camera.
Interactive lab
Transform Network Graph & Tabletop Inspector
Canvas / SVG· Live[ 0.92 -0.39 1.24 ] [ 0.39 0.92 -0.42 ] [ 0.00 0.00 1.00 ]
Stepping into 3D: why quaternions avoid gimbal lock
In 2D, orientation is a single angle θ, so things stay friendly. In 3D, engineers often visualize orientation using three sequential Euler angles (roll, pitch, yaw). They're great for humans to read, but they hide a nasty trap called gimbal lock: pitch a camera straight up 90°, and the roll and yaw axes align so you lose a degree of freedom and interpolation wobbles wildly.
That's why modern TF trees store 3D rotations internally as unit quaternions (four numbers representing an axis in 3D space plus a twist around it) or 3×3 rotation matrices. You can still print roll-pitch-yaw for debugging, while letting quaternions keep the math smooth everywhere.
Chaining and inverting across a TF tree
T_camera←mug = (T_wrist→camera)⁻¹ · (T_shoulder→wrist)⁻¹ · (T_base→shoulder)⁻¹ · (T_world→base)⁻¹ · T_world→table · T_table→mug
Climbing up toward the common ancestor uses inverse transforms (T⁻¹); walking down to the target frame uses forward transforms (T).
In the TF tree world → base → shoulder → wrist → camera, you want to find the position of the shoulder expressed in the camera's frame. How does the lookup walk the tree?
Whenever a real robot arm misses a grasp by 5 cm, the culprit is usually a stale TF static transform or a backwards parent/child order in a calibrated camera extrinsic.
Hands-On Python Notebook
03 · Homogeneous Matrices & TF Tree Lookup Lab
Implement make_se2(), invert_se2(), and a working TFTree class that chains forward and inverted edges between any two frames.
Try this on your own inside the notebook
- Attach a new gripper_tip child frame to wrist and query mug in gripper_tip
- Verify lookup(A, B) @ lookup(B, A) equals identity
In Google Colab, use File → Save a copy in Drive to keep your own edits and notes. Or download the files directly:
uvx marimo edit --sandbox notebooks/course-1/03_transform_networks_tf_trees.pyWrap up this module
Saved automatically in your browser profile so you can pick up right where you left off.