Homogeneous Coordinates and Forward Kinematics

If you’re still following along after reading our last post, you’ll now have gotten the hang of what a frame of reference is, and how we can rotate and translate them relative to one another. Transforming one frame of reference to another is called a rigid body transformation.

But most motion in the real world consists of a combination of rotations and translations. How can we represent this kind of motion easily and efficiently? Well, it turns out that it’s not as hard as you might think.

There is a theory in kinematics that states that it is always possible to transform one reference frame to another, regardless of relative position and orientation, by a single rotation, followed by a translation .

This is easy to see when you consider that I can align any two frames of reference with one rotation, and then place them on top of each other with a translation.

inertial_frames

So, if I have two arbitrarily positioned reference frames A and B, and I want to transform a vector from A to B, all I need to do is find the rotation and translation that maps these two frames:

R_{OO'} \vec{x}_O +\vec{t}_{OO'}= \vec{x}_{O'}

This is extremely useful for our work in understanding how robotic arms, as we’ll soon see.

Homogenous Coordinates

This ability to map reference frames to each other is very useful, but it requires two distinct operations: Rotation, then translation. This means that we require a rotation matrix and a translation vector for every two reference frames that we want to relate.

Wouldn’t it be great if we could instead define a single matrix that completely represents the relationship between two reference frames? Well it turns out that we can, but to in order to do this, we need to change the kind of coordinates that we use to describe points in space.

Homogeneous coordinates are the new coordinates that we need to use, and they look exactly like our regular Cartesian coordinates, except that they have an extra 1 at the bottom:

\begin{bmatrix} 5 \\ 7 \\ 9 \\ 1 \end{bmatrix}

Why did we add the extra 1? Because it allows us to compose our rotation matrix and our translation vector into one, 4×4 matrix that represents both the rotation and the translation:

T = \begin{bmatrix} R_{00} & R_{01} & R_{22} & t_{0} \\ R_{10} & R_{11} & R_{22} & t_{1} \\ R_{20} & R_{11} & R_{22} & t_{2} \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}

We can now use this with our homogenous vectors to completely represent transformations between frames of reference:

\begin{bmatrix} R_{00} & R_{01} & R_{22} & t_{0} \\ R_{10} & R_{11} & R_{22} & t_{1} \\ R_{20} & R_{11} & R_{22} & t_{2} \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \begin{bmatrix} x_{0} \\ x_{1} \\ x_{2} \\ 1 \end{bmatrix} = \begin{bmatrix} x_{0}\prime \\ x_{1}\prime \\ x_{2}\prime \\ 1 \end{bmatrix}

Remember the x\prime symbol represents the vector in the transformed coordinate frame.

Here is an example below, using the homogenous translation vector above, combined with a rotation matrix about the Z-axis:

T = \begin{bmatrix} \cos(\theta) & -\sin(\theta) & 0 & 5 \\ \sin(\theta) & \cos(\theta) & 0 & 7 \\ 0 & 0 & 1 & 9 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}

The 1 allows us to treat the last column of the homogenous transformation matrix as a simple vector addition, which is the translation between the two frames.

With this small change, we can now represent the relationship between two reference frames with a single 4×4 matrix.

Chaining Rigid Body Transformations

Suppose we have three reference frames, A, B and C. Using our new homogenous representation, let’s define two 4×4 rigid body transformation matrices: TAB and TBC. TAB maps vectors from reference frame A into frame B, and similarly, TBC maps vectors from reference frame B to frame C.

A question you might ask is: Given that I know a vector in frame A, can I transform it to frame C?

The answer is yes, we just need to chain our transformations:

T_{BC} T_{AB} \vec{x}_A = \vec{x}_C

This operation first maps our frame A vector to frame B, then maps the new calculated frame B vector to frame C using TBC. Even better, we can do this for arbitrarily long chains:

T_{DE} T_{CD} T_{BC} T_{AB} \vec{x}_A = \vec{x}_E

This will be the foundation for our next section.

Forward Kinematics

Forward kinematics is essentially the question: Given that I know all of the joint angles of my robotic arm, what position is the end-effector in?

It will be useful to explain forward kinematics with an example. Take the robotic arm in a plane below:

three-link-annotated

We will walk you through solving the forward kinematics of this arm in 2D (just the plane). Remember, a robotic arm is a series of links, connected by joints, and each link has it’s own reference frame. Here we see a robotic arm with three links, and three joints.

It will be actually be useful to define and label our four reference frames here:

  • The 0 frame (green), or the global reference frame. Often, this is just a reference frame that is attached to the base of the robot, or a table the robot sits on.
  • The 1 frame (red), attached to the base of the first link (represented by L1 link)
  • The 2 frame (blue), attached to the base of the second link (represented by L2 link)
  • The 3 frame (cyan), or the end-effector frame, attached to the base of the third link (represented by L3 link)

three-link-annotated_coordinate_frames

To start, let’s look at what a rotation matrix looks like in 2D:

\begin{bmatrix} \cos(\theta) & -\sin(\theta) \\ \sin(\theta) & \cos(\theta) \\ \end{bmatrix}

This matrix describes a rotation of a vector by an angle \theta in 2D. For each of our 3 joints, we can use it to describe the rotation of each link by it’s respective joint:

R_{01} = \begin{bmatrix} \cos(\theta_1) & -\sin(\theta_1) \\ \sin(\theta_1) & \cos(\theta_1) \\ \end{bmatrix}

R_{12} = \begin{bmatrix} \cos(\theta_2) & -\sin(\theta_2) \\ \sin(\theta_2) & \cos(\theta_2) \\ \end{bmatrix}

R_{23} = \begin{bmatrix} \cos(\theta_3) & -\sin(\theta_3) \\ \sin(\theta_3) & \cos(\theta_3) \\ \end{bmatrix}

Once we have rotated our initial reference frame, we must translate along the length of the next link to superimpose it on the next link’s reference frame. However, remember that we’ve rotated our reference frame, so to translate it we’ll need to calculate the translation vector from the rotated frame:

T = -R \begin{bmatrix} L \\ 0 \\ \end{bmatrix} = \begin{bmatrix} -L\cos(\theta) \\ -L\sin(\theta) \\ \end{bmatrix}

Remember, we are going to use homogeneous coordinates to allow us to represent the rotation and subsequent translation in one matrix:

T_{01} = \begin{bmatrix} \cos(\theta_1) & -\sin(\theta_1) & 0 \\ \sin(\theta_1) & \cos(\theta_1) & 0 \\ 0 & 0 & 1 \\ \end{bmatrix}

T_{12} = \begin{bmatrix} \cos(\theta_2) & -\sin(\theta_2) &-L_1\cos(\theta_2) \\ \sin(\theta_2) & \cos(\theta_2) & -L_1\sin(\theta_2) \\ 0 & 0 & 1 \\ \end{bmatrix}

T_{23} = \begin{bmatrix} \cos(\theta_3) & -\sin(\theta_3) & -L_2\cos(\theta_3) \\ \sin(\theta_3) & \cos(\theta_3) & -L_2\sin(\theta_3) \\ 0 & 0 & 1 \\ \end{bmatrix}

And that’s it! We can see what position our end-effector is now in by taking our joint angles, plugging them into our transformation matrices, and calculating. Just pick a vector in the global reference frame (the 0 frame) and feed it into the calculation to get the vector in the end-effector frame (the 3 frame):

T_{23} T_{12} T_{01} \vec{x}_0 = \vec{x}_3

Next steps

Forward kinematics are a little more complicated in 3D, but are essentially the same. In our next post, we’ll work through the forward kinematics of a 3D robotic arm.

Advertisement

Describing Rigid Body Motion in Space

2000px-rigid_body_attached_frame-svg
What we’ll discuss in this post: A rigid body get’s it’s own reference frame b, relative to another reference frame a

In this blog post, we’ll be learning some math tools that will allow us to easily describe how rigid bodies (e.g. solid objects or arbitrary shape) move in Cartesian space.

This will be very important to our future task of programming a robotic arm, because in order to understand how the end-effector of our robot will move, we’ll need to understand how moving the joints of our robot arm causes the links (which are rigid bodies) to move in space.

If you are still a little rusty on your linear algebra, check out this quick refresher post I wrote that should get you back on your feet and ready to digest the rest of this post.

The problem is actually a little harder than this, because the joints and links of our arm are connected in a chain. To describe the motion of any link in the chain, we also need to incorporate the fact that there may be several joints and links before it in the chain. So describing the motion of a link further along the chain also requires us to factor in several prior joints and links. This is the topic for our next post, where we talk about forward kinematics for robotic arms.

Frames of Reference

If you remember back to our Cartesian coordinate system, we had a few basic objects that needed to be in place before we could assign coordinates to different points in space. We needed the origin, and the axis’. With these two things, we could then define any point in space using just three numbers: The x-coordinate, the y-coordinate, and the z-coordinate.

1000px-coord_planes_color-svg
Our cartesian coordinate system

But where exactly is the origin? And how do we know which way the axis’ should point? Is there a marker somewhere on the earth that says: “This is the origin, and here are the axis’.

1_small

Of course not! There is no “absolute origin”, just like there is no “center” of the universe. We can place our coordinate system anywhere that we want, and start measuring coordinates from there. We could assign the origin to the top of the Eiffel tower, or in the pilot’s seat of an airplane that is traveling near the speed of sound, or on the wheel of a moving bus. This assignment of a coordinate system to a particular place and orientation is called a frame of reference.

For instance, when you walk around your house and observe things, you see everything from your frame of reference, the origin of which is pinned to the front of your face, with the x-axis looking outward and the z-axis pointing up.

In this way, all frames of reference are relative, meaning that the only way to describe the position and orientation of one frame of reference is by comparing it to another.

And we can define many frames of reference, not just one. And this is the key to describing how rigid bodies move. We describe the location and orientation of each rigid body by assigning it it’s own frame of reference.

frame_of_reference
Our two dolls, each a rigid body, is assigned a reference frame: The blue doll is assigned the O1 frame, and the brown doll the O2 frame

Each rigid body is pinned to the origin of it’s respective frame of reference, and is static in its own frame.

By assigning a frame of reference for each rigid body in this way, we can accurately describe how objects move in space, and more importantly, their positions and orientations relative to each other.

22oly6

Don’t worry, we’re going to walk through a few examples to show you how we’ll do this.

Translation: A Simple Rigid Body Motion

Imagine two frames of reference, O and O’ (pronouned “O prime”). Let O represent the initial position of the rigid body, and O’ will represent the position of the rigid body after the translation.

2000px-Frames_of_reference_in_relative_motion.svg
Here is a diagram of a pure translation of reference frame O’ along the x-axis

Translating a rigid body is the simplest kind of motion. All that it requires is a displacement vector, which describes the location of frame O’ relative to the initial frame, frame O’.

\vec{t} = \begin{bmatrix}3 \\ 5 \\ -1 \end{bmatrix}

We usually represent a translation vector with subscripts to tell us what reference frames we are translating from and to.

\vec{t}_{OO'} = \begin{bmatrix}3 \\ 5 \\ -1 \end{bmatrix}

To describe any point in frame A in the translated frame B, we would just add the translation vector to it:

\vec{x}_{O} +\vec{t}_{OO'} = \vec{x}_{O'}

So for instance, let’s define our rigid body object to be a cube, with 6 points (one point for each corner) in reference frame O. We can see what our cube would look like in the translated frame O’ by adding the translation vector, \vec{t}_{OO'} to all six points.

Rotation

Rotating a rigid body is the other kind of motion that a body can undergo. Assuming we have an object that undergoes a pure rotation (no translation), we can again define two reference frames: O is the initial reference frame of the object, O’ is after the rotation.

2000px-rotation_cartesian_coordinates_about_z_axis-svg
In this figure, we are rotating around the z-axis

In the diagram above, the black lines represent the initial reference frame O, and the green lines represent the rotated reference frame O’.

We can define a 3 X 3 rotation matrix, R_{OO'} to show how any point in reference frame O would look like if we rotated it into reference frame O’:

R_{OO'} \vec{x}_O = \vec{x}_{O'}

So for instance, if we define our rigid body object to be a cube, with 6 points in reference frame O, we can multiply those points by R_{OO'} to see what the cube would look like in the rotated reference frame O’.

Generalizing Motion: Rotation and Translation

In the real world, we rarely move by pure translation or pure rotation. Usually we move by both rotating and translating, like when we drive our car and turn left or right.

In the next blog post, we’ll be discussing a technique that we can use to describe this kind of complex motion very simply, and along the way we’ll explain how this relates to our robot arm.

Introduction to Cartesian Coordinates, Vectors and Transformation Matrices

2000px-coord_system_ca_0-svg

Welcome to Cartesian coordinate space! We’ll be spending a lot of time here, and because it’s so important to building, developing and programming robotic arms, we’ll need to get comfortable working with it to describe how things exist and move (specifically, chains of rigid bodies) within it.

First, a Disclaimer

There is nothing special about Cartesian space. It’s just a mathematical model to help us describe real space (i.e. the space that you are living in right now) in a more specific and workable way. There are lots of other kinds of mathematical spaces that are used to describe real-space, but Cartesian space is the easiest for our purposes here. It’s just a tool!

The Origin and the Axis’

In a Cartesian coordinate system, there two very important things to understand: The origin and the axis’.

The axis’ (pronounced “axe-ees”) are the three lines labeled X, Y and Z that you see in the image above. The z-axis is the line that runs up-down. The y-axis runs east-west, and the x-axis runs north-south.

The origin is the place in the image labeled O where these three axis’ intersect, which is right in the middle of the space.

Given these things, we can identify any point in space by just 3 numbers:

  • How far up or down it is from the origin. This is called the z-coordinate
  • How far east or west it is from the origin. This is called the y-coordinate
  • How far north or south it is from the origin. This is called the x-coordinate

Vectors: How to Describe Points in Space

To make things nice and compact, we’ve developed a handy notation for describing these three coordinates in a Cartesian coordinate system, called vectors. A vector is just a one-dimensional array of these three coordinates, and looks like this:

\begin{bmatrix} 5 \\ 7 \\ 9 \end{bmatrix}

The top number represents the x-coordinate, the second the y-coordinate, and the bottom number is the z-coordinate. In the case of the vector above, this point is 5 units past the origin on the x-axis, 7 units past the origin along the y-axis, and 9 units past the origin on the z-axis.

We call the position of a number in a vector the index to help identify which number in a vector we are talking about. The number at index 1 is the first number, the number at index 2 is the second number, and so on.

You can visualize the location of this (or any) point by using this simple technique:

  • Imagine you are standing at the origin.
  • Walk 5 units up the x-axis, then stop.
  • Now walk 7 units up the y-axis, then stop again.
  • Finally walk 9 units up the z-axis. You’re now at the point that the vector describes!

Again, a vector like this represents a point in our Cartesian space, and is usually visualized as an arrow or line:

2000px-3d_vector-svg

In the image above, the a arrow represents a vector, where the ax line represents the x-coordinate for the vector (and similarly for ay and az).

Vectors are usually denoted by lowercase, bold letters like a or lowercase letters with an arrow on top \vec{a}.

Translation: Moving points from A to B

Let’s say that you have a vector a which describes a point in our Cartesian space, and you’d like move it a little bit up to describe a point that is 5 units higher on the z-axis. Changing a vector to describe a new point that is a fixed distance away in a particular direction is called translation.

It’s very easy to translate a vector, because it just requires us to add two vectors:

\begin{bmatrix} 5 \\ 7 \\ 9 \end{bmatrix} +\begin{bmatrix} 0 \\ 0 \\ 5 \end{bmatrix} =\begin{bmatrix} 5 \\ 7 \\ 14 \end{bmatrix}

Adding two vectors is done horizontally: Add all the top numbers together to produce the resultant top number, add all the middle numbers to produce the resultant output number, etc.

Intuitively, you can imagine that you are standing at the point described by the first vector, and now the second vector begins at this point. If you follow that vector to it’s end, you’ll arrive at the sum. The image below illustrates this in the plane:

vector_addition

Similarly, you could move the same vector to describe a point that is 5 units lower on the z-axis by instead subtracting this displacement vector.

Matrices: How to Transform Vectors

So far, we’ve described the coordinate system, how we can represent points in space, and how we can add and subtract vectors to effectively translate them. But what if we want to do something more interesting with a point, like rotate it around the z-axis?

This is where matrices come in handy. In a Cartesian coordinate system, a matrix usually represents a transformation on a vector like:

  • Rotating the vector around an axis
  • Scaling it to be bigger or smaller
  • Mirroring it across a plane

A matrix is just a two-dimensional array, and looks like this:

 A = \begin{bmatrix} \frac{5}{6} & \frac{1}{6} & 0 \\[0.3em] \frac{5}{6} & 0 & \frac{1}{6} \\[0.3em] 0 & \frac{5}{6} & \frac{1}{6} \end{bmatrix}

Usually capital letters are used to denote that a variable is a matrix

There is a special matrix called the Identity Matrix (Often denoted as I) that does absolutely nothing but spit out the original vector when applied to a vector. It is just a matrix that has all ones going down the center of the matrix diagonally, and zeroes elsewhere:

 I = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}

Using a Matrix to Transform a Vector

To transform a vector, we multiply the vector by the matrix to produce the transformed vector:

\begin{bmatrix} 1 & 1 & 3 \\ 4 & 1 & 2 \\ 6 & 1 & 1 \end{bmatrix} \cdot \begin{bmatrix} 2 \\ 3 \\ 2 \end{bmatrix} = \begin{bmatrix} 11 \\ 15 \\ 17 \end{bmatrix}

The dot in the equation above represents matrix multiplication. Matrix multiplication can be tricky at first, but with a little practice it becomes second nature. I won’t go into the details here, but this video by Khan Academy does a much better job of explaining it than I ever could. Watch it a few times and try it out yourself to really get the hang of it.

Matrix Inverses: The “Reverse” Transformation

Sometimes, we have a matrix that represents a certain transformation of a vector, but we would like to know what matrix we would need to “undo” that transformation. The answer, luckily, is simple: The inverse of the transformation matrix.

The inverse of a matrix is another matrix that, when multiplied by the original matrix, produces the identity matrix:

A \cdot A^{-1} = I

In this equation, A-1 represents the inverse of the matrix A. So for example, if A represented a rotation of 45 degrees around the z-axis, A-1 would represent a rotation of -45 degrees around the z-axis.

Applying Multiple Transformations to a Vector

Oftentimes, we want to apply several transformations to a vector in a particular order. Suppose we want to apply the transformation matrix A to a vector first, then apply the transformation matrix B to the result of this, and furthermore apply C to that result.

To do this, we multiply the vector by the three matrices:

C \cdot B \cdot A \cdot \vec{x} = \vec{y}

Usually we omit the dot in-between the matrices and vectors, and the dot is then implied:

C B A \vec{x} = \vec{y}

As you can see, to ensure that we multiply in the correct order, by arrange the matrices from right-to-left. So for the above equation, we would first multiply x by A, then multiple the result of that by B, and the result of that by C. In this way we have applied the A, B and C transformation matrices in the correct order.

Next steps

And that it’s! You now know enough to be officially dangerous. There is certainly much more to be learned regarding vector spaces like this one, but for the purposes of learning about things like rigid body motion in space, this is enough for now.

Now that you’ve completed this lesson, be sure to check out our store for lots of cool robotic applications for your new knowledge!

A Gentle Introduction to Robotic Arms

If you are reading this post, you’ve taken the first step on a very rewarding journey towards being a roboticist! Whether you’re interested in actually automating something, or just interested in playing around, this blog will take you from your first baby steps in understanding of what robotic arms are and how they work, to some more advanced concepts in the field like motion planning, grasping, and visual servoing.

After reading this, if you are interested in building/buying a robot arm to tinker with yourself, you should check-out our robotic arm store.

While we won’t get into the nitty-gritty in this post, at some point you’ll need to have some basic maths to follow along. At least a basic knowledge of linear algebra, trigonometry and basic calculus will be needed. If you feel like you might need a little refresher on these topics, Khan Academy is a fantastic (and free) resource for learning everything you need to know to become a world-class roboticist.

What is a robotic arm?

A robotic arm is a kind of open kinematic-chain, which is really just a collection of links and joints.

three-link-annotated

Usually at the end of this chain is a tool of some kind, like a gripper or a welder or a drill. This is called the end-effector.

One great example of links and joints is your own human arm. The links in your arm are the bones, and the joints are the connections between the bones: Your elbow, your shoulder, your wrist., etc.

A link can be any shape and size, so long as it is one solid, rigid object. Joints generally come in one of two varieties:

Revolute joints are the joints that you are most familiar with. They are equivalent to a hinge: They rotate just one way. A door hinge or a wheel is a great example of a revolute joint. Revolute joints have an axis that describes which way they rotate:

2000px-revolute_joint-svg

Your elbow is another good example of a revolute joint.

Prismatic or linear joints are less common, but are useful when linear and not rotational motion is desired. Linear joints slide along a line, like a drawer slide or a telescope.

200px-prismatic_joint-svg

By serially combining links with joints that are oriented along different axis’, you can produce all kinds of different kinds of robotic arms, each more suited to some tasks than others.

And that’s it – In theory, robotic arms are very simple. But put several simple things together and things get complicated very quickly…

Some common robotic arms

Just to give you and intuitive sense of what we’re talking about here, lets look at a few common designs of robotic arms that you’ll see in a lot of places:

Articulated Robot

kuka_robot_for_flat_glas_handling

An articulated robotic arm is the kind of robot arm that you’re probably most familiar with. These arms can have anywhere from 3 to 7 joints. All of the joints are revolute, and they are the most dexterous kind of robotic arm. These arms are usually used in applications like spot-welding or painting, where the end-effector must be in very specific positions and orientations.

SCARA Robot

kuka_industrial_robot_kr10_scara

A SCARA arm is a special arm that excels at working in a plane. It’s great for pick-and-place tasks (like picking things up off of a conveyor belt). SCARA arms are relatively fast, and are precise enough to do detailed electronics or medical testing work. All revolute and linear joints on a SCARA robot point in the Z-direction.

Gantry Arm (Tower Crane)

Tower Gantry Bridge Construction Crane Shipyard

A gantry arm is a simple arm where all of the joints but the base are linear. One linear joint moves the load up and down, another linear joint moves it outwards and inwards. A revolute joint at the base turns the arm. These arms are used for heavy lifting, like the tower crane that you see here.

Delta Robot

rostock-delta-robot-3d-printer-1

A delta robot is actually a closed kinematic chain, and so is not technically a robotic arm. However it is popular enough that I thought it warranted a mention here. Delta robots control the position and orientation of their end-effector by moving three attached links. By connecting the end effector to three links instead of one, delta robots can move very fast, with minimal error.

Sneak Peek at Rigid Body Motion and Kinematics

Now that you understand what a robot arm is, I can tell you now that most of the work of building and programming a robotic arm successfully is understanding how the arm end-effector moves, when the joints move in different ways. 

To get there, though, we’ll first need to equip you with some very important mathematical tools for understanding how we describe the motion of rigid bodies in space. This will be the subject of the next blog post, in which we’ll show you how to represent the motion of rigid bodies using some basic linear algebra.

If you liked this post, don’t forget to check out our store for all things related to robot arms and to subscribe!