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.
The chain, from the front
the selected joint's own axes are drawnOne 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.jsEvery 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 getGlobalMatrixThe 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
- 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. - 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.
- Order matters.
movethenturnZthenturnYthenturnXgives "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. - 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?