TL;DR
A coordinate frame is a reference for measuring position. It has an origin, which is a chosen point, and a set of axes that start at that origin and point in chosen directions. A point has coordinates only relative to some frame, so the same physical point gets different numbers in different frames. A robot uses many frames at once, one for the room, one for its base, one for each link and sensor, and it converts between them with rotations and shifts.
Builds on: Rotation Matrix · Leads to: Rigid Body Transformation, Visual SLAM
Where it's used
Robot arms. Each link of an arm has its own frame attached to it, so the joint motor only needs to know how one link sits relative to the link before it. To find where the gripper is in the room, the controller chains the frame of each link to the next. The chain of frames is the basis of forward kinematics, which computes the tool position from the joint angles.
Mobile robots and sensors. A lidar or camera mounted on a robot reports what it sees in its own frame. To build a map of the room, the software must move each reading into the world frame, using the robot's current pose. A wrong value for the sensor's mounting offset, which is a fixed transform between frames, shifts every reading by the same error.
Games and 3D software. A character's hand is positioned relative to its arm, the arm relative to the body, and the body relative to the scene. Each of these is a frame, and moving the body moves everything attached to it, without any of the child objects needing new numbers. Scene graphs in game engines store exactly this parent-child structure.
How it works
Take a two-dimensional world frame with its origin at , x pointing right and y pointing up. Place a second frame with its origin at in , and turn its axes 90 degrees counterclockwise. In , the x-axis points up in , and the y-axis points left in . Now trace one point through the two frames.
- Name the point in . The point is one unit along 's x-axis, so its coordinates in are . Check: this is the address of the point in the frame , nothing more.
- Turn the offset to the world directions. One unit along 's x-axis is one unit along 's y-axis after the 90 degree turn, so the offset in directions is . Check: the rotation maps to .
- Move the origin. 's origin sits at in , so add it: . Check: the point is 3 units right and 2 units up from 's origin.
- Read the same point in . The point has coordinates in and in . Both are correct, and they are two addresses for one place.
- Repeat for a second point. The point in is one unit along 's y-axis. Turning it gives in , and adding the origin gives . Check: both points sit exactly one unit from 's origin, so the frame has not stretched them.
The conversion is a turn followed by a shift:
flowchart LR P[point in B: 1, 0] --> R[turn by 90 degrees: 0, 1] R --> S[shift by origin: 3, 2] S --> W[point in W: 3, 2]
The math
A frame is a pair . The vector is the origin of , given in world coordinates. The matrix is a rotation matrix whose columns are the unit directions of 's axes, also in world coordinates. A frame is right-handed when its three axes follow the right-hand rule, and this lesson assumes right-handed frames throughout.
Step 2 in symbols: turning
In two dimensions, a rotation by angle counterclockwise is
For , and , so . Its first column, , is where the x-axis of points in , which is why step 2 gave that vector.
Step 3 in symbols: shifting
Let be the origin of in . A point with coordinates in has world coordinates
The rotation is applied first and the shift second. This order matters, and the common mistake section shows what goes wrong otherwise.
Step 4 in symbols: reading the example
Applying the formula to gives
Going back: from world to frame
Solve the formula for . Subtract the origin and multiply by the transpose of . The transpose is the inverse here because a rotation is an orthogonal matrix:
Stacking frames
With homogeneous coordinates, which add a 1 to each point, the turn and the shift become one Matrix , and . If frame is attached to frame with matrix , then . A chain of links is a product of matrices read right to left, which is why a robot can compute its gripper position by multiplying one matrix per joint.
Worked examples
Let frame have the same axes as , with its origin at . Take the point in .
- Turning does nothing, so the offset stays .
- Add the origin: .
- The point sits at in .
- Check: 's origin is 2 units to the right, and the point is one unit further right and one unit up from there, which gives .
Use the frames from the How it works section, where and . Find where the origin of sits in .
- The origin of has world coordinates .
- Subtract : .
- Multiply by : the first entry is , and the second is .
- So the origin of is at in .
- Check by going back: , and adding gives , the origin of .
A mobile robot stands at metres in a room, facing the same direction as the world y-axis, so its frame is turned 90 degrees counterclockwise. Its lidar sits 0.3 metres ahead of the robot's centre, so the lidar's origin in is . The lidar reports an obstacle 2.0 metres straight ahead of itself, which in the lidar frame is .
- Put the obstacle in by adding the lidar offset: .
- Turn into world directions with : .
- Add the robot position: .
- The obstacle is at metres in the room, 2.3 metres north of the robot.
Try it: the robot now turns to face the negative x-direction, so its rotation is 180 degrees. Where is the same obstacle in the room? Answer: , so , and adding gives .
Common mistakes and tradeoffs
It is tempting to think a frame is just a set of numbers. In fact a frame is a reference, an origin and a set of directions, and the numbers are only the address of a point in it. Confusing the two leads to code that stores coordinates without saying which frame they belong to, which is hard to debug later.
It is tempting to shift first and then rotate. In fact the rotation acts on the point's position within its own frame, before the frame is moved. Using the example from the worked section, adding to first gives , and turning that gives , which is the wrong place. Following the formula avoids this.
It is tempting to mix right-handed and left-handed conventions silently. In fact the sign of a rotation depends on the handedness, so a sensor that reports in one convention and a planner that assumes another will disagree in sign, and the error looks like a mirror image. Write the convention down in the code and check it at each boundary.
Use frames when a part of the system moves, or when a sensor is mounted at a fixed offset from the thing it measures. Do not add a frame for every object: a fixed table that never moves can be written in the room frame. The alternatives are to store one matrix per link and multiply them, which is the usual choice for a robot, or to store each pose as a position and a unit quaternion, which uses fewer numbers and avoids drift in the rotation matrix but is harder to read at a glance.
History
People located points with numbers long before robotics existed. René Descartes published the coordinate method in 1637 in La Géométrie, where a point is given by its distances along fixed lines. The idea that a robot's joints should each carry a frame came later. In 1955, Jacques Denavit and Richard Hartenberg published a convention for attaching a frame to each link of a linkage, so that the whole machine could be described by a short list of numbers per link. That convention, which is now called Denavit-Hartenberg parameters, made it practical to compute the position of an arm's tool from its joint angles, and it is still widely taught and used.
Recap
- A coordinate frame is an origin plus a set of directions, and the same point has different coordinates in different frames.
- Converting from a frame to the world is a turn by the frame's rotation followed by a shift by its origin, in that order.
- Converting back uses the transpose of the rotation, since a rotation's inverse is its transpose.
- Chains of frames multiply as matrices, which is how a robot computes the position of its tool.
- Next, read Rigid Body Transformation for how one turn and one shift are packed into a single matrix, and Visual SLAM for how a moving sensor's frames are used to build a map.
Check yourself
QuestionA frame B has its origin at (5, 0) in the world and no rotation. A point is at (2, 3) in B. Where is it in the world?Show answer
Since there is no rotation, the offset stays (2, 3). Adding the origin gives .
QuestionA frame is rotated 90 degrees counterclockwise and has its origin at (1, 1) in the world. Using , where is the point (2, 0) in B?Show answer
The rotation maps to . Adding the origin gives .
QuestionWhy does the order of turning and shifting matter? Give a case where doing it in the wrong order gives a different answer.Show answer
A turn is a linear map about the origin of the frame it acts in, and a shift moves that origin. Turning after shifting moves the point around the wrong center. With the frame at (3, 1) rotated 90 degrees and the point at (1, 0), turning first gives (3, 2), while shifting first then turning gives (-1, 4). The two differ, so the formula must apply the rotation first.
QuestionA lidar reports an obstacle at (1.0, 0) in its own frame. The lidar sits at (0, 0.2) in the robot frame, and the robot frame is at (2, 2) in the world with no rotation. Where is the obstacle in the world?Show answer
The obstacle in the robot frame is . With no rotation the world position is .