Transform Tutorial
Background
The specification of the location of an object in three dimensional space implies specifying its position and its orientation (also called attitude) with respect to a reference position and orientation.Three-dimensional coordinate frame transformations are widely used in robotics to specify locations of objects. Detailed descriptions of coordinate frame transformations are found in a number of introductory robotics textbooks. CLARAty has a number of C++ software classes for representing and operating on coordinate transforms. We provide an overview of the use of the CLARAty transform module here.
The axes of a coordinate frame are typically labeled X, Y and Z and are arranged as shown on the figure below. To specify location of an object, it is convenient to also specify a local coordinate frame attached to a fixed location on the object. The specification of the object's location can then be precisely stated as the location of its local coordinate frame with respect to the reference coordinate frame. To facilitate the discussion, we will give labels to the different coordinate frames. So, for example, we call the local coordinate frame C2 and the reference coordinate frame C0. A convenient approach to represent the general transformation of a coordinateframe from C0 to C2 is to partition the transformation into its pure translation and pure rotation components. The location of the object is obtained by a pure translation of the coordinate frame C0to C1 followed by a pure rotation of C1 to C2.
Pure translations in three dimensional space are represented by three dimensional vectors. The three elements of the vector are used to represent the components of the translation along the X, Y and Z axes of the coordinate frame respectively. In the figure above, the green vector drawn from the origin of coordinate frame C0 to the origin of coordinate frameC1 represents the translation.
The specification of orientation is more complex. The figure above illustrates the problem. The origins of the two coordinate frames C1and C2 are co-incident but the frames are in different orientations. The problem is to specify the orientation of C2 with respect to C1.The blue curved arrows show how the X, Y and Z axes must simultaneously rotate (while satisfying the constraint that they are attached to a rigid body) to transform the orientation of the coordinate frame from C1 to C2. A number of conventions and numerical constructs have been developed to represent this change in orientation. Most introductory robotics textbooks describe in detail the approaches used to represent rotation transformations. CLARAty provides two alternatives for specifying orientations: three-by-three orthonormal rotation matrices and quaternions.
The combination of a translation vector and a rotation matrix or a quaternion gives us a quantity that can represent general three dimensional transformations. CLARAty provides a number of options to represent general transformations. The CLARAty classes used for representing threedimensional transformations are listed below.
CLARAty Transform Classes
| CLARAty Class | Filename | Module | Brief Description |
| Point | point_t.h | point | Point is used to represent 3-D points and 3-D vectors. When used to represent 3-D vectors, the 3 elements of Point correspond to the X, Y and Z axes translation components of the vector. Operators are provided for performing simple vector math operations. |
| RMatrix | rotation_matrix.h | transform | RMatrix is used to represent 3x3 rotation matrices. RMatrix provides constructors for easily converting a number of alternative Euler-parameter and quaternion representations of rotation into a rotation matrix, extracting equivalent Euler-parameters or quaternion from a rotation matrix and performing a number of other operations on rotation matrices. |
| Quaternion | quaternion.h | transform | Quaternion provides an alternative to rotation matrices for representing rotation transformations. Operators are provided for performing a number of useful quaternion math operations and for converting to and from rotation matrices. |
| Trans | trans.h | transform | Trans is a template class that allows the user to configure it to be composed of a Point and either an RMatrix or a Quaternion. In addition to constructors provided for creating a general transform representation from vector and rotation transform parameters, Trans has operators for performing a number of transform operations like rotating about specified axes, translating along specified axes, and setting and retrieving transformation parameters. |
| HTrans | htrans.h | transform | HTrans is composed of a Point and an RMatrix. It is derived from Trans and has additional operations that have been maintained for backward compatibility with earlier versions of HTrans. |
| QTrans | qtrans.h | transform | QTrans is composed of a Point and a Quaternion. It is derived from Trans and also has additional operations that are relevant for its quaternion component. |
| Transform |
transform.h |
transform |
Transform is typedef-ed in transform.h to be one of the four possible general transform types in CLARAty. This allows users to use Transform as a class without needing to know what the underlying implementation is. |
Using CLARAty Transform Classes
A demonstration, contained in a file demo
Create a Point and compute its distance from another Point
double distance_P1_P2 = p1.distance_from(Point<double>(2.0, 3.0, 4.0));
Create an RMatrix using roll, pitch yaw parameters then extract the roll, pitch, yaw parameters from the RMatrix
// Extract the RPY angles from the rotation matrix
double r, p, y;
rpy.get_rpy_angles(r, p, y);
Create a Quaternion and convert it into an RMatrix.
RMatrix<double> q2rm = q1.quaternion_to_rotation_matrix();
Create a Trans with RMatrix then apply a rotate transform then a translate transform to it.
// Rotate thisTrans by the reverse of rpy then translate by the
// reverse of p1
Trans<double,RMatrix<double> > trm2 =
trm1.rotate(rpy.transpose()).translate(Point<double>(-1.0, -2.0, -3.0));
Create a Trans with Quaternion then apply a rotate transform then a translate transform to it.
// Rotate this trans by the reverse of q1 then translate by the
// reverse of p1
Trans<double,Quaternion<double> > tq2 =
tq1.rotate(q1.reverse()).translate(Point<double>(-1.0, -2.0, -3.0));
We can perform similar operations with HTrans
// Rotate this Trans by the reverse of rpy then translate by the
// reverse of p1
HTrans<double> h2 =
h1.rotate(rpy.transpose()).translate(Point<double>(-1.0, -2.0, -3.0));
And QTrans
// Rotate this QTrans by the reverse of q1 then translate by the
// reverse of p1
QTrans<double> qt2 =
qt1.rotate(q1.reverse()).translate(Point<double>(-1.0, -2.0, -3.0));
Many more functions are available in the CLARAty transform classes. The user is encouraged to review the header files and the demo and utest files within the transform module to see how these classes can be used.