-
Notifications
You must be signed in to change notification settings - Fork 37
Lesson 3: Orientation in Robotics ‐ Rotation Matrices
As we talked in the previous lesson, the configuration of the robot answers the question: where is the robot? In order to know where the robot is, we need to know the position and orientation of the robot's body frame {b} w.r.t some base (space) frame {s}:
The position and orientation of a robot in space can be represented by the position of the origin of the body frame expressed in the space frame coordinates and the directions of the coordinate axes of the body frame expressed in the space frame coordinates.
In this lesson, we want to talk about the robot's orientation and one of the ways that we can express this orientation. Before divining into more details, let's see some preliminary concepts that we will use when studying the robot's configuration.
A free vector is a geometric quantity and an arrow in n-dimensional flat space
A vector is a free vector expressed with its coordinates in a reference frame and length scale chosen for that space. In robotics, vectors are represented by an italic letter
A vector is dependent on the choice of the coordinate frame and length scale, whereas the underlying free vector is unchanged by the choice of the coordinate frame or the length scale. In other words, v is coordinate-free.
A free vector is coordinate-free, whereas a vector is dependent on the choice of the coordinate frames and length scale.
A vector can also represent a point p in the physical space. If we choose to give this physical space a reference frame and a length scale, the point is a vector from the origin of this reference frame to the point. It is then represented as an italic
A physical point p can have different representations relative to different coordinate frames.
In Robotics, frames are important. We use frames to represent the robot’s configurations, velocities, and forces causing the motion. Frames in robotics:
- have an origin
- consist of orthogonal x, y, and z coordinate axes:
A right-handed coordinate frame consists of x, y, and z coordinate axes. The index finger is in the x-direction, the middle finger is in the y-direction, and the thumb is in the z-direction.
- are right-handed, and this means that the cross product of the x and y axes is z, and so on:
- are stationery! This is from Newton’s laws that the reference frames are always considered to be inertial.
A positive rotation about an axis follows the right-hand rule. If you align your thumb with the axis of rotation, then the positive rotation is in the direction that the fingers curl:
right.hand.rule.mp4
To conclude this part, let’s see a simple demonstration of the positive rotations about the coordinate axes attached to a robot joint:
robot.motions.prelim.demo.positive.rotations.x.y.z.mp4
After these short preliminaries, let's go into detail about one of the ways to represent orientation in robotics.
As we saw at the beginning of this lesson, in order to know the configuration of a robot, we should know the position and orientation w.r.t to some base frame. One implicit way to express the orientation is using rotation matrices.
From the DOF lesson, we learned that a rigid body in space has 3 rotational DOFS. Therefore, we need three parameters to explicitly represent a rigid body’s orientation (rotations about the x, y, and z axes). One implicit way to represent the orientation of a rigid body is using 3×3 rotation matrices (note that this is one of the applications of the rotation matrix) to express the orientation of the body frame relative to the base frame. With the 9-dimensional space of the 3×3 rotation matrices subject to 6 constraints, we can implicitly represent the 3-dimensional space of orientations. In other words, of these 9 parameters, only 3 can be chosen independently. The reason that we opt for implicit representation is to take advantage of the algebraic calculations on matrices.
Suppose a robot in space as shown in the figure at the beginning of this lesson where {b} is the stationary body frame instantaneously attached to the moving body and {s} is the space or reference frame. We want a representation of the orientation of the robot in space.
The rotation matrix R can be defined as a representation of the body frame unit axes expressed in the base frame as:
The dot represents the dot product between the two vectors, and since the coordinate axes are of unit lengths, it represents the cosine of the angle between the two vectors.
Beginning of the Math Note:
Recall that if a and b are two vectors with known lengths and angle between them:
The dot product of two vectors is the multiplication of the length of the two vectors and cosine of the angle between the two vectors.
Then, the dot product of the two vectors can be expressed as the projection of one vector onto the other multiplied by the length of the other vector (in other words, it is the multiplication of the lengths of the two vectors and cosine of the angle between the two vectors):
End of the Math Note.
The nine numbers in this rotation matrix are subject to six constraints (so that we have 3 degrees of freedom). The constraints are:
- The unit norm constraint says that the columns of the rotation matrix R are unit vectors (because they are coordinate axes):
Note that ||.|| represents the norm of a vector.
- The orthogonality condition says that the column vectors of the rotation matrix are orthogonal to each other since they are coordinate axes, and thus the dot/inner product of any two column vectors is zero:
We can write these six constraints in a compact form as
As we discussed in the preliminaries, all frames in robotics are taken to be right-handed meaning that the cross product of the x and y axes is the z-axis (and so on). But the six constraints that we just discussed do not account for this since:
If we take the right-handed coordinate system, then the determinant of R will be calculated as:
This result comes from the fact that our frames are right-handed.
Beginning of math note:
We know from algebra that for a 3×3 matrix A defined by its columns as:
The determinant of A can be found by the following formula:
End of math note.
So, we can conclude that for a right-handed frame,
By definition, the group of rotation matrices is called the special orthogonal group SO(3), which is a set of all 3×3 real matrices R that satisfy
A subgroup of SO(3) is the set of 2×2 rotation matrices called the special orthogonal group SO(2) that consists of all 2×2 real matrices R satisfying
Suppose a toy car with its motion confined to the plane and two coordinate frames {s}, and {b} with their corresponding unit axes (a hat notation shows a unit vector):
A toy car on a plane with two coordinate frames {s} and {b} with the unit axes. The orientation of the toy car can be expressed by finding the orientation of the body fixed-frame with respect to the space frame {s}.
{b} is called a body frame since it is a fixed frame attached instantaneously to the moving body. Therefore, to find the orientation of the toy car, we should express the orientation of the body’s fixed-frame coordinates in the base frame coordinates. One way to represent the orientation of the body coordinates in terms of the base coordinates is, as we saw in this lesson, by using a rotation matrix:
The columns of this matrix are the coordinate axes of the {b} frame expressed in the coordinate axes of the {s} frame. And since both the base frame axes and the body frame axes are unit vectors, their dot product is the cosine of the angle between the vectors. Note that
Sets of rotation matrices SO(2) and SO(3) are groups and thus have properties of a mathematical group. In general, the SO(n) groups are called Lie groups. A mathematical group has a set of elements and an operation on two elements (this operation is matrix multiplication for SO(n)) such that for all
- The group has closure property and this means that the multiplication of the two matrices in the group also belongs to the group:
$R_1 R_2 \in SO(n)$ .
To show this for the SO(3), suppose that
And thus the product of two rotation matrices is also a rotation matrix.
- The group has associativity property:
$(R_1 R_2) R_3 = R_1 (R_2 R_3)$
Note that the multiplication of rotation matrices is associative but generally not commutative:
Where because of the case for planar rotations, we can write:
Thus with an easy calculation, we can see that RM = MR, and thus for the special case of the planar rotations, the multiplication of the rotation matrices commute. For example, if you rotate a coordinate frame attached instantaneously to a body confined to a plane first by 45 degrees and then by 30 degrees, the result is the same as when you rotate it first by 30 degrees and then by 45 degrees:
- There exists an identity element in SO(n) such that RI = IR = R.
Note that the identity matrix I can be viewed as a trivial example of a rotation matrix. Imagine this by visualizing the first frame aligned with the reference frame.
- There exists an inverse element
$R^{-1}$ in SO(n) such that$R R^{-1} = R^{-1} R = I$ .
For SO(3), we can say that the inverse of a rotation matrix R in SO(3) is also a rotation matrix, and
And thus the inverse of R is also a rotation matrix. Note that
Also, note that when a rotation matrix is applied to a vector to rotate it, this does not change the length of the vector. In other words: For any vector
Proof.
Where
A rotation matrix can be used for three different purposes that we will discuss in the coming paragraphs.
As we discussed earlier, a rotation matrix can be used to implicitly represent an orientation; in other words, it can be used to represent the orientation of the body frame relative to the base frame. In order to show this, I use an example that is adapted from the reference book “Modern Robotics: Mechanics, Planning, and Control” by Kevin Lynch and Frank Park.
Suppose we have three reference frames {s}, {b}, and {c} that represent the same space with different orientations:
One of the applications of a rotation matrix is to represent the orientation of one frame relative to another. Coordinate frames {s}, {b}, and {c} represent the same space with different orientations. The orientation of frames {b} and {c} relative to {s} can be represented by a rotation matrix. Point p has the same location in space but has different coordinates depending on the choice of coordinate frame. Note that the three reference frames have the same origin and only orientations are different. I showed them in different spots to make the presentation clear. In other words, the same space is drawn three times.
Coordinate frame {b} can be achieved by rotating the {s} frame by 90 degrees about the {s} frame’s z-axis, and frame {c} is achieved by rotating the {b} frame by -90 degrees about the {b} frame’s y-axis. Watch the short demonstration below to understand how these coordinate frames are achieved:
successive.rotations.coordinate.frames.mp4
Three coordinate frames {s}, {b}, and {c} representing the same space with different orientations. A rotation matrix is used to represent the orientation of one frame relative to another frame.
As we discussed, a rotation matrix can be used to represent the orientation of one frame relative to the base frame. Now, let’s see the rotation matrices representing the orientations of the {b} and {c} coordinate frames relative to the {s} frame. By writing the coordinate axes of the {b} and {c} frames in the {s} frame we can get:
It’s easy to note that the coordinate axes of the {s} frame in the for example {c} frame can be achieved by inverting (or transposing in the case of rotation matrices) the rotation matrix representing the orientation of the {c} frame relative to the {s} frame:
Note that because of the properties of a rotation matrix, the inverse of a rotation matrix is equal to the transpose of a rotation matrix.
Also, note that the point p has the same location in the space but has different representations depending on the choice of the coordinate frame:
One of the applications of a rotation matrix is to change the reference frame of a vector or a frame. Here, a rotation matrix is an operator that acts on a vector or a frame to change its reference frame. For example, to show the change of frame of reference for a coordinate frame, suppose that we have the rotation matrix representing the orientation of the {c} frame relative to the {b} frame as (frames are defined above):
The goal is to express the {c} frame in {s} frame coordinates instead of the {b} coordinates. To achieve this goal, we can use the rotation matrix
By pre-multiplying
A rotation matrix can also serve as an operator to change the frame of reference for a vector. For instance, suppose that we have
A rotation matrix can serve as an operator to change the reference frame in which a vector is expressed.
We want to express p in {s} frame coordinates. We can do this by pre-multiplying
Note that the subscript cancellation rule works here too.
Another application (and the final one) of a rotation matrix is to rotate a vector or a frame. Here again, a rotation matrix is an operator that acts on a vector or a frame to rotate it.
Consider the three coordinate axes {s}, {b}, and {c} described as in the above figure. As we saw before, {b} is achieved by rotating the {s} frame by 90 degrees about the z-axis of the {s} frame.
Pre-multiplying
This vector represents the rotated
A rotation matrix can act as an operator to rotate a vector. For example, in this simulation, you can see that by multiplying a vector by a rotation operator that can rotate 90 degrees about the z-axis, the vector is rotated in the same coordinate frame by 90 degrees.
Note that to rotate a vector
A rotation matrix can also be used to rotate a frame. Suppose that we have the rotation operator R that can rotate a frame by 90 degrees about the z-axis:
Now let’s see what happens to a frame if we pre-multiply or post-multiply it by this rotation operator. Note that the choice of the z-axis to be from which frame depends on the pre-multiplication or post-multiplication of the rotation matrix. Now suppose the {s} and {c} coordinate frames that we had before:
The {c} frame orientation will be different depending on whether the rotation matrix representing its orientation with respect to the base frame (
If we pre-multiply by the rotation operator R defined above, then the rotation axis is the z-axis of the first subscript, which is s so that the rotation is about the z-axis of the {s} coordinate frame:
Pre-multiplication of a rotation matrix representing the orientation of one frame with respect to another by a rotation operator defined above (a rotation operator that can rotate a vector or a frame by 90 degrees about the z-axis), rotates the frame about the z-axis of the coordinate frame related to the first letter of the subscript which is s.
If we post-multiply by the rotation operator R defined above, then the rotation axis is the z-axis of the second subscript, which is c so that the rotation is about the z-axis of the {c} coordinate frame:
Post-multiplication of a rotation matrix representing the orientation of one frame with respect to another by a rotation operator defined above (a rotation operator that can rotate a vector or a frame by 90 degrees about the z-axis), rotates the frame around the z-axis of the coordinate frame related to the second letter of the subscript which is c.
Generally speaking, if
-
Coordinate frame {b’} is the new frame after a rotation by
$\theta$ about$\hat{\omega}_s = \hat{\omega}$ , and this means that the rotation axis is considered to be in the fixed frame {s}:$R_{sb'} = R R_{sb}$ . -
Coordinate frame {b”} is the new frame after a rotation by
$\theta$ about$\hat{\omega}_b = \hat{\omega}$ , and this means that the rotation axis is in the body frame {b}:$R_{sb"} = R_{sb} R$ .
So, for the rotation operator
The multiplication of
Rotation Operators about the x, y, and z Axes
Now let’s find general forms of rotation operators representing the rotations about the x, y, and z axes by
The rotation operator representing the rotation about the x-axis by
Using the figure below:
We can find the rotation operator representing the rotation about the x-axis as:
With the same approach rotation operators representing the rotations about the y-axis and the z-axis can be found as:
and
Generally, the rotation about an arbitrary unit axis
by
Where:
We will see how to derive this rotation matrix in the coming lessons when talking about the exponential coordinates of rotation. For now, you can verify that it is correct by assuming
Visualize this rotation as the following figure:
The rotation about the arbitrary axis ῶ by θ.
Note that any
Now, let's finish up this lesson with an example.
Example: The Representation of the Orientation of the Elements in the Robot’s Workspace
Suppose that a camera and a gripper are attached to the end-effector of the industrial arm. The camera is used to observe the workpiece and position the end-effector in the right position, and the gripper is used to grip the workpiece. The overall system can be depicted in the figure below:
A camera is attached to the robot end-effector to observe the object and position the end-effector in the right position. Four reference frames are attached to different elements in the robot’s workspace, as shown in the figure. The orientation of one frame relative to the other can be implicitly represented by a rotation matrix. This example is adapted from the first textbook by Lynch et al.
Four frames are attached to different elements in the robot’s workspace, as shown above. {a} is the frame coincident with the space frame {s}, {b} is the gripper frame, {c} is the camera frame, and {d} is the workpiece frame.
The orientation of the workpiece frame relative to the base frame can be expressed by the rotation matrix
This means that the two frames have the same orientation.
The orientation of the workpiece frame relative to the camera frame can be calculated as follows:
Now suppose we have the rotation matrix representing the orientation of the camera frame relative to the gripper frame as:
To calculate the orientation of the gripper frame relative to the space frame
Note that we used the inverse of a rotation matrix equals its transpose and the subscript cancellation rule to calculate the result.
Let's see another example.
Example: Successive Rotations of a Point about the Coordinate Axes of the Base Frame
Suppose p is a point in space with coordinates relative to the space frame as
point p in space and the corresponding vector representation in {s} frame.
Now suppose that p is rotated about the fixed-frame x-axis by 30 degrees, then about the fixed-frame y-axis by 135 degrees, and finally about the fixed-frame z-axis by -120 degrees. The rotation matrix that rotated p to the new location can be expressed as (note the order in which the rotations are written):
These rotations can easily be calculated using the rotation operators about the coordinate axes provided above. Then the coordinates of the rotated point can be calculated as:
The rotated point can be visualized as:
Vector representation of the rotated point p after going through a rotation by 30 degree about the x-axis of the base frame, then a rotation by 135 degree about the y-axis of the base frame, and finally a rotation by -120 degree about the z-axis of the base frame.
- Modern Robotics: Mechanics, Planning, and Control by Frank Park and Kevin Lynch
- A Mathematical Introduction to Robotic Manipulation by Murray, Lee, and Sastry
- Cao, C.T., Do, V.P. and Lee, B.R., 2019. A novel indirect calibration approach for robot positioning error compensation based on neural network and hand-eye vision. Applied Sciences, 9(9), p.1940.
If you want to strengthen your math foundation, the following course is recommended (especially the Matrix Algebra for Engineers course):
Statistics is very important if you want to do a lot of Machine Learning:
Learn physics from the lectures below:
Especially go to playlists and start from Classical Mechanics. The textbook that he uses is Physics for Engineers by Ohanian.