ARM LAB / STUDY / LEVEL 2 OF 8

Frames and
the chain.

Turn the shoulder and the elbow, wrist and gripper all move, because they are built on top of the shoulder. Turn the elbow and only the wrist and gripper follow. The arm is a chain: each joint lives in its parent's frame. A frame is written as a 4×4 matrix, an identity card that says where I am and which way I face relative to my parent. Multiply the cards down the chain and you get where every joint is relative to the base. That is forward kinematics, and the scene engine does it for free. This page does it by hand with the scene's own cg.js and tables, so you can watch.

local matrixmove(xyz) · turnZ · turnY · turnX, angle added to the axis
→
global = parent × localrepeated from the base down the chain
→
column 3 = positionelements 12, 13, 14
→
getGlobalMatrix()the engine's loop that does exactly this

The chain, from the front

the selected joint's own axes are drawn
its x axisits y axisits z axis· the motor turns about the axis named in the table

One joint's identity card

local matrix: in the parent's frame

global matrix: in the base's frame = parent's global × local

Building a joint's matrix

armLab.js

Every frame, for every joint: reset, move to xyz, then the three turns of rpy, with the motor's angle added to the one that is its axis. Each call multiplies another matrix onto the node's own. Because the node is a child of its parent node, the engine multiplies the parent's matrix in front of it when it draws.


      

Reading a position back

armLab.js, and the engine's getGlobalMatrix

The engine walks up the parents and multiplies, which is the same loop this page runs downward. The scene takes elements 12–14 as the position, then converts into the scene's frame (level 4).


      
  // clay.js: the engine's version of this page's chain  this.getGlobalMatrix = () => {     let M = this.getMatrix();     for (let node = this._parent ; node ; node = node._parent)        M = cg.mMultiply(node.getMatrix(), M);   // parent in front, all the way to the root     return M;  }

What you should be able to explain

  1. Read a matrix by columns. Columns 1–3 are where the frame's x, y and z axes point; column 4 is where its origin is. The last row is always 0 0 0 1: it is there so that moving and turning can both be one multiplication.
  2. Local versus global. A joint's local matrix never changes except for its own angle: it is its placement in its parent. Its global matrix changes whenever any joint above it moves, because it is the product of everything above.
  3. Order matters. move then turnZ then turnY then turnX gives "turn the part in place by rpy, then put it at xyz". URDF defines rpy as roll about x first, then pitch, then yaw; the engine applies the last call first, so the code writes the turns in reverse.
  4. The engine does the chain. node[j.parent].add() made each joint a child of its parent once, at start-up. After that, setting six local matrices per frame is all the scene does; getGlobalMatrix() multiplies the chain when a position is needed.

Exercises: ① Select the elbow and turn only the shoulder: which of its two matrices changes, and which column of the global one? ② Select the gripper frame: it has no motor and no angle slider. Why does it still have a position that moves? ③ In the global matrix of shoulder_lift, which column points straight up (0, 0, 1)? What does that tell you about its axis?