21
-12 Robotics and Automation Handbook
21.4.1 Graphical Animation
There are a number of different ways to visually display robot motion. In this section, we will focus on
where to begin if we wish to develop a package similar to the systems covered in the previous section. Many
of these packages exploit the OpenGL interface. OpenGL was originally developed by Silicon Graphics, Inc.
(SGI) as a multi-purpose, platform-independent graphical API. OpenGL is a collection of approximately
150 distinct commands that you can use to specify objects and operations needed to produce interactive
three-dimensional applications. To provide a starting point, note that OpenGL is based on object oriented
programming, C++. To efficiently develop a robot simulation package, you develop a set of classes that can
constructsimple objects such as spheres, cylinders, rectangles, andwhatever basic objects you need to define
a robot. OpenGL uses a number of vector and matrix operations to define objects in three-dimensional
space. As a simple example, the following function would draw a cube.
Void DrawCube(float x, float y, float z)
{
glPushMatrix();
glTranslatef(x,y,z);
glBegin(GL\_POLYGON);
glVertex3f(0.0f, 0.0f, 0.0f); // top face
glVertex3f(0.0f, 0.0f, -1.0f);
glVertex3f(-1.0f, 0.0f, -1.0f);
glVertex3f(-1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f); // front face
glVertex3f(-1.0f, 0.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f(0.0f, -1.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f); // right face
glVertex3f(0.0f, -1.0f, 0.0f);
glVertex3f(0.0f, -1.0f, -1.0f);
glVertex3f(0.0f, 0.0f, -1.0f);
glVertex3f(-1.0f, 0.0f, 0.0f); // left face
glVertex3f(-1.0f, 0.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f); // bottom face
glVertex3f(0.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f); // back face
glVertex3f(-1.0f, 0.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(0.0f, -1.0f, -1.0f);
glEnd();
glPopMatrix();
}
OpenGL uses what is called a matrix stack to construct complicated models of many simple objects. In
the case of the cube, the function first gets the most recent coordinate frame, possibly pushed onto the
stack prior to this function call. Then the function glTranslate() performs a translation on the coordinate
frame. Likewise there are functions such as glRotate() and glScale() that provide the ability to rotate and
scale the object. The glBegin() and glEnd() functions provide bounds on the definition of the verticies,
defined by the glVertex3f() function, of the object.
Your robot will consist of a number of these primitives, thus the motivation for object-oriented pro-
gramming. Animation of motion will require the coordination of these primitives. It is now clear that a
visual robot simulation program requires a combination of programming for animation (using utilities
such as OpenGL) and an understanding of robot kinematics. There are a number of references, includ-
ing this handbook, that provide excellent guidelines for writing the algorithms necessary for providing