CENTRO UNIVERSITÁRIO DE BARRA MANSA ACADEMIC PRO-RECTORY COMPUTER ENGINEERING COURSE

CONSTRUCTION AND SIMULATION OF A ROBOT ARM WITH OPENGL
By: Leniel Braz de Oliveira Macaferi Wellington Magalhães Leite

Barra Mansa May 16, 2007

CENTRO UNIVERSITÁRIO DE BARRA MANSA ACADEMIC PRO-RECTORY COMPUTER ENGINEERING COURSE

CONSTRUCTION AND SIMULATION OF A ROBOT ARM WITH OPENGL
By: Leniel Braz de Oliveira Macaferi Wellington Magalhães Leite

Paper presented to the Computer Engineering course at Centro Universitário de Barra Mansa, as a partial requisite to the obtention of the second grade in the Computer Graphics discipline, under prof. Ronaldo Dias Corrêa supervision.

Barra Mansa May 16, 2007

The OpenGL API specification tries to help us when we are programming the graphical details of a given project. construction and simulation of a given graphical project. With a simulation (virtual) model. Keywords: robot arm. what make us capable of foreseeing how a determined object will look like and how it will behave after its proper construction in the physical world. computer graphics . which is the most employed robot in the manufacturing industry and in areas that require a high precision rate. 3D simulation.ABSTRACT The importance of projects related to the field of Computer Graphics in simulations has been growing a lot during the last years. Therefore it brings to life the necessity of mastering the concepts and techniques inherent to the process of elaboration. In this article we’re showing the necessary steps and routines to the proper codification and simulation of a robotic arm in 3D. OpenGL. we can have a closer vision of the object of study in contrast with reality.

........................................Robot arm’s fist motion .TABLE OF FIGURES Figure 1 ..................Robot arm’s rotation in the base pivot ................Robot arm’s shoulder and elbow motion ...........................Motion of the robot arm’s base in the flat surface ......................... 23  Figure 7 ............................................................................................................... 25  ........................................ 20  Figure 4 ................................................... 22  Figure 6 .......................................................... 8  Figure 3 ..................................................................................Robot arm’s fingers motion ............... 7  Figure 2 .........Initial position of the robot arm .........Articulated robot arm .....................OpenGL logo ............ 21  Figure 5 ....................................... 24  Figure 8 .................................................................................

Robot arm keyboard and mouse bindings ................... 19  ........................LIST OF TABLES Table 1 ........................

....1 Provided files..4 Code conversion from C to C# ....................................................................................6 Complete source code ...............1 Objective .......................................................... 11  3 APPLICATION ....................2 Definition .............................................................................................5 The DrawRobotArm function ............................................................................................................3 Framework employed ........ 9  2.................. 7  1............................................................................................................. 11  2......................................................................................2................ 7  1.............................. 7  1.......................................................... 26  5 REFERENCES ............................. 7  2 DEVELOPMENT ......................................................... 9  2................................................................................2 OpenGL .............................................................................CONTENTS Page 1 INTRODUCTION ................................................................... 27  .2 Robot arm construction ..........................................1 Robot arm ............................................................................................................................................................................................................. 9  2........................................................................................................... 7  1......................................................................2....................................... 10  2.................................... 19  4 CONCLUSION ..................................................................... 10  2.......................................................................

using to that purpose final actuators. The robot arm can be built in a fix or mobile fashion (e.: with wheels) to be used in industries or in home (where it’s also called micro-arm). packaging. The interface consists in more than 250 different functions. which can be used to draw complex tridimensional scenes with simple primitives.1 Objective Our objective is to create a robot arm with claws that simulate the opening and closing motions. painting.g.2.7 1 INTRODUCTION 1.Articulated robot arm 1. 1. multiuse programmable manipulator with three or more pivots. It’s more autonomous than a simple mechanic arm and can be used to lift small parts with high precision and velocity.1 Robot arm A robotic arm can be classified as articulated and not articulated [1]. It’s generally used in tasks such as: welding. The model will be created in a virtual way through OpenGL programming. . Figure 1 . storage. reprogrammable.2 OpenGL OpenGL (Open Graphics Library) [2] is a standard specification that defines an API (Application Program Interface) that is multi-language and multi-platform and that enables the codification of applications that output computerized graphics in 2D and 3D.2 Definition 1.2. In the industrial field it’s defined by ISO (International Standards Organization) as an automatically controlled. assembling. product inspection and test.

Figure 2 .OpenGL logo . OpenGL is broadly used in CAD (Computer Aided Design). information visualization. scientific visualization.8 OpenGL was developed by Silicon Graphics Inc. flight simulation and video games development. (SGI) on 1992 and is popular in the gaming industry where it competes with the Direct3D in the Microsoft Windows platform. virtual reality.

Execute the file robot1. . which draws in the screen only a flat grey surface.exe.1 Provided files A file called robot. An advice that was given: read the third chapter of the book OpenGL RedBook so that we could have a better understanding to execute the construction of the robot arm. what also serves to verify the code library glut32. the display functions to all the parts of a robot arm and an executable file called robot1. hierarchical transformations.cpp. we build upon a homework elaborated by the professors of the department that is related to the topics of Computer Graphics in respect to graphics scenes. instantiation. This gave us the local coordinates of each part of the robot arm. . As a matter of fact.exe to determine how the parts must be connected and what transformations are necessary to support the control of the variables.2 Robot arm construction With the given files described in 2. the position and motion of the robot arm’s part must match the provided program.Chapel Hill campus. that is. The user interface that changes the variables’ control (as shown in the file robot1.exe) was already configured and our objective was to complement the display routine DrawRobotArm that wasn’t implemented.1 we executed the following steps to program (assemble) the robot arm as stated in the provided guide at [3]: . stack of matrices and OpenGL transformations. As a restriction: the output program must be equal to the provide program.cpp. . which contains the primitives to the construction of the robot arm. To accomplish that we used a stack of matrices from the OpenGL and other necessary transformations.9 2 DEVELOPMENT Our development started from the basic idea of a robot arm that we found at the site [3] of the Computer Science department from the University of North Caroline . that is.dll is necessary in the folder of the executable file.exe to see the final result of the robot arm.Visualize the executable robot1.Compile and execute the file robot. 2. .Draw the robot arm’s parts to determine the correct dimensions. 2. which contains the robot arm already constructed were initially provided.

4 Code conversion from C to C# As an extra motivation. . which provides to the .0 Express Edition to do so.10 2. we converted the C code to C# and we used the Microsoft C++ 2005 Express Edition and Microsoft Visual C# 9.3 Framework employed To elaborate this work we used the Tao framework [4]. 2.Net programmers (Microsoft) access to the common OpenGL code libraries.

0.GL_MODELVIEW). 0.glTranslatef(0. } 2.glRotatef(fingerAng1.4f. GL. 0.9TH TERM [http://www. 0). // // UBM COMPUTER ENGINEERING . DrawWrist(16).glTranslatef(0f.2f. GL. 0f. GL. 0f. 0f.5f. 90f).0f. GL.5 The DrawRobotArm function static void DrawRobotArm(int numSegs) { GL.glRotatef(baseSpin. 0.glPopMatrix(). -90f). // . 0).glRotatef(wristAng.glPushMatrix(). GL. 0f. DrawFingerBase(16).2f. GL.3f. DrawFingerTip(16).glTranslatef(0. 90f). baseTransZ). GL.glRotatef(fingerAng2. 0f).glRotatef(fingerAng2.glTranslatef(0f. 0f.glRotatef(fingerAng1. 90f).glTranslatef(0f. 0. 0f). 0). GL. DrawArmSegment(64). 0f). 360f.glMatrixMode(GL. 0f. 0f.glTranslatef(0. 0f.glRotatef(wristTwistAng. GL.0f.6 Complete source code // // Construction and Simulation of a Robot Arm with OpenGL // Copyright ©2007 Leniel Braz de Oliveira Macaferi & Wellington Magalhães Leite.ubm. GL. GL. 0. 0f.3f. GL. 0f.glTranslatef(baseTransX.glRotatef(elbowAng. DrawArmSegment(64). GL. 0. GL. 180f. GL. 90f). 0. 0.11 2. 0).glPushMatrix(). 0. 0f. GL. 0f. DrawFingerTip(16).br/] // This program sample was developed and turned in as a term paper for Computer Graphics // The source code is provided "as is" without warranty. GL.glPopMatrix(). DrawBase(64). 90f). DrawFingerBase(16). 0f).glRotatef(shoulderAng. GL. GL.glTranslatef(0f. -180f).5f. 0f). GL. 0f. 0f. GL.

1].0f * 3. 128 }. 128 }.glScalef(0. static float baseSpin = 0.cs.Forms. Ang += AngIncr) { Px[i] = (float)Math. 0.5f). 24 }. for (i = 1. static float wristAng = 90. static float shoulderAng = -10. GL. static float oldX.y. 68.5f. newY. // User interface global variables static bool leftButtonDown = false. static float fingerAng1 = 45.Cos(Ang).glTranslatef(0. Px[0] = 1. 0.z in [0. 119 }.edu/~dm/UNC/COMP236/Homeworks/hw1b/ System. static byte[] fingers = { 150. 0.glPushMatrix(). Py[i] = (float)Math. Y-axis is int i. i < numSegs.glMatrixMode(GL. static byte[] fingerJoints = { 128. newX.GL_MODELVIEW). static float fingerAng2 = -90. 128.5f. } GL. float AngIncr = (2.Windows. // Mouse stuff static void DrawUnitCylinder(int numSegs) up { // x. Py[0] = 0. using using using using namespace ComputerGraphics { /// <summary> /// Creates a robot arm /// </summary> class RobotArm { // Robot's arm controls static float baseTransX = -0. System.5f.1415927f) / (float)numSegs.Sin(Ang). static byte[] joints = { 0.5f). float[] Py = new float[numSegs]. GL. 0. i++.unc. GL. // Top . oldY. 128. Tao. 0. float Ang = AngIncr. static float baseTransZ = 0.5f. static float elbowAng = -120.12 // // The original code can be found at: http://www. // 0 // 1 // 2 // 3 // 4 // Robot's colors static byte[] arms = { 128. static int robotControl = 1. float[] Px = new float[numSegs].FreeGlut.5f. OpenGL. static float wristTwistAng = 10.

-1. GL. numSegs). 0f).glEnd(). Glut.5f. 1.GL_TRIANGLE_FAN). . 1. } static void DrawGroundPlane(int numSegs) { GL. GL. GL.glPushMatrix().glTranslatef(0. GL. 0. GL.7f). GL.7f. i < numSegs. } static void DrawUnitCone(int numSegs) // x. -1. GL.y. GL. 0. numSegs.glMatrixMode(GL. } GL. 1.z in [0.glutSolidCone(0.GL_QUAD_STRIP). 0f.GL_TRIANGLE_FAN). -Py[i]).glVertex3f(Px[i]. 0). -Py[i]). GL.5f.glVertex3f(Px[i]. for (i = 0.glVertex3f(Px[0]. 0.7f. GL. i++) { GL.1]. GL.glPopMatrix(). GL. 0). GL. -1. 0f. numSegs. -Py[i]). 1f. GL. 0. // Bottom GL.13 GL. GL. -1. i++) GL.glNormal3f(0. Glut.glMatrixMode(GL. GL.z in [0. 1f). 0f.glColor3f(0. i++) GL.glEnd().glVertex3f(Px[i].glNormal3f(0f. 0. GL.5f).glRotatef(-90.glVertex3f(0.glEnd().glVertex3f(Px[0]. GL.glBegin(GL. 0.5f. -Py[0]). GL. GL. apex is in +Y direction { GL.glNormal3f(Px[0]. i < numSegs.glutSolidSphere(0. 1.glNormal3f(Px[i].5f).5f. 0. GL. -Py[0]).glVertex3f(1f. 1f).glTranslatef(0.y.glBegin(GL.GL_MODELVIEW). 1. -Py[0]).glVertex3f(Px[i]. 0. // Sides GL. 1. 0). for (i = 0.glBegin(GL. -1.glVertex3f(1f. 0). -1f).1] { GL.GL_MODELVIEW).glVertex3f(0. -Py[0]). 1.glVertex3f(Px[0]. GL.glPopMatrix().glPushMatrix(). for (i = 0. i < numSegs. 0.glVertex3f(-1f.glBegin(GL. numSegs). -1. GL.5f. } static void DrawUnitSphere(int numSegs) // x.glVertex3f(Px[0]. Py[0]). Py[i]).GL_QUADS). GL. -Py[i]).glNormal3f(0. GL.glPopMatrix(). GL. 0). 1.

glPopMatrix(). 0.GL_MODELVIEW).glTranslatef(0.05f).glColor3ubv(joints). -0.glPopMatrix().glColor3ubv(arms).glMatrixMode(GL. DrawUnitCylinder(numSegs). 0.glPopMatrix().5f. 0. . DrawUnitCylinder(numSegs). GL. -0.glTranslatef(-0. 0. GL.025f. GL. GL.08f). GL.glMatrixMode(GL. GL.12f).1f. GL.glScalef(0.glPushMatrix().glTranslatef(0. GL. 0. 0). DrawUnitCylinder(numSegs). -0.glScalef(0. 0.glPopMatrix(). 1. 0.5f. DrawJoint(numSegs).glPushMatrix().08f. 0.glColor3ubv(fingers). 0.2f).glPopMatrix(). GL. DrawUnitCylinder(numSegs).glPushMatrix().glTranslatef(-0. GL. GL. 0.04f.GL_MODELVIEW).14 GL. GL.05f). 0. DrawUnitCylinder(numSegs). GL.5f.5f).04f). 0. GL.2f.15f.glPushMatrix(). GL. GL. 0). 0f. 0. GL.1f).1f. GL.glPopMatrix().05f. 0. GL.glTranslatef(-0. GL.05f.glEnd().GL_MODELVIEW). DrawJoint(numSegs). } static void DrawJoint(int numSegs) { GL. -0. GL.glRotatef(90. } static void DrawWrist(int numSegs) { GL. GL.glPushMatrix().5f. GL.1f). GL.glPushMatrix(). GL. 0.glColor3ubv(joints).4f. GL.4f.glPushMatrix(). GL.glTranslatef(-0. -0.glColor3ubv(arms).5f.glScalef(0. GL.glScalef(0.GL_MODELVIEW). -1f). GL.5f).glMatrixMode(GL.glScalef(0. GL. } static void DrawBase(int numSegs) { GL.glVertex3f(-1f.15f.2f.glTranslatef(-0. GL.glMatrixMode(GL.glPopMatrix(). GL. 0. GL. 0). 0. } static void DrawArmSegment(int numSegs) { GL. -0.

4f.25f. 0. -0. GL.5f. 0).glScalef(0.15 GL.glTranslatef(0.glColor3ubv(fingers).glPopMatrix().glTranslatef(0.glPushMatrix().glPopMatrix().glPushMatrix().3f. 0. 0). DrawArmSegment(64). -0.glScalef(0.glMatrixMode(GL.glRotatef(wristAng.0f.025f).5f. 0.05f). baseTransZ). GL. 0.glTranslatef(0. -0. 0f. 0f.glPushMatrix(). GL.5f).0f.025f. 0.glMatrixMode(GL. DrawBase(64). 0f). 0.05f.glTranslatef(-0. DrawUnitSphere(numSegs).glRotatef(elbowAng. 0. 180f.3f. GL.glTranslatef(baseTransX.5f). 360f. DrawWrist(16).glTranslatef(0.05f).GL_MODELVIEW). GL.glTranslatef(-0. DrawArmSegment(64). -0.glTranslatef(-0. GL. GL. GL.glPushMatrix(). GL. GL. GL.glColor3ubv(fingerJoints). DrawUnitCylinder(numSegs). DrawUnitSphere(numSegs).05f. 0f.2f. 0. 0. DrawUnitCone(numSegs). GL. 0. GL. 0. GL. GL. 90f). 90f).glColor3ubv(fingers).glScalef(0. 0. 0.glPopMatrix(). GL.glRotatef(shoulderAng.glPopMatrix().5f). GL. GL. 0).glScalef(0.5f.5f. } static void DrawFingerTip(int numSegs) { GL. GL.GL_MODELVIEW).12f).5f.glColor3ubv(fingerJoints). -0.glPushMatrix().5f. GL. } static void DrawFingerBase(int numSegs) { GL. } static void DrawRobotArm(int numSegs) { GL.glRotatef(wristTwistAng.glRotatef(baseSpin. GL. 0). 0. GL.glTranslatef(-0. 0f). 0f. GL. -0. GL. 0f.5f. 0).08f).08f. GL. GL. GL.12f. 0. 0f.08f. GL.glTranslatef(0.GL_MODELVIEW). 90f). 0. 0. .12f. 0. GL. GL.glMatrixMode(GL. GL.

0. GL. 0f. 0. 0f. 0f. GL.16 GL. 0f).glTranslatef(0f.glLoadIdentity(). h). } static void myIdle() { Glut. 2f. DrawFingerTip(16). 0f. 0. DrawRobotArm(16).glMatrixMode(GL.0f). 4f. w / h. GL. 0f).GL_PROJECTION). 0. 0f.gluPerspective(30. -90f).glClear(GL.glLoadIdentity().glPushMatrix().glutSwapBuffers().1. 0f.glMatrixMode(GL.2f. DrawFingerBase(16). 90f). 0f. -7. 0f).glRotatef(fingerAng2.5f. GL.glTranslatef(1. GL. GL. int x. GL. GL.glPopMatrix(). w.glRotatef(fingerAng2.glMatrixMode(GL. DrawGroundPlane(16).GL_COLOR_BUFFER_BIT | GL. 0. Glut. GL.3f. -180f).glTranslatef(0f. GL. 0f.glPopMatrix(). GL. GL.GL_MODELVIEW). 0. DrawFingerTip(16).glRotatef(fingerAng1. GL. 0f.glViewport(0.glutPostRedisplay(). 0f. int h) { GL. 90f). int y) { char c = (char)Key.GL_MODELVIEW). GLU. if (c >= '1' && c <= '5') .GL_DEPTH_BUFFER_BIT). GLU.glLoadIdentity().glTranslatef(0f. } static void myReshape(int w.glRotatef(fingerAng1.3f. DrawFingerBase(16). GL.0f.glTranslatef(0f. 0. } static void KeyboardFunc(byte Key. 10). 0f). 0f.gluLookAt(0f. GL.5f. 0.2f. 1f. GL. 0). } static void myDisplay() { GL. GL.

if (leftButtonDown) switch (robotControl) { case 0: baseTransX += RelX. Glut. case 4: fingerAng1 += RelY * 90.oldX) / Glut. 512).glutInitWindowPosition(180. newX = x. . Glut. int state. GL. baseTransZ += RelY.glutGetWindow(). }. if (Key == 27) Application.GL_COLOR_MATERIAL).oldY) / Glut.glutInitDisplayMode(Glut. case 1: baseSpin += RelX * 180.GLUT_LEFT_BUTTON) leftButtonDown = !leftButtonDown. break.GLUT_WINDOW_HEIGHT). break. break.glutGet(Glut.glutInit(). } // ESC static void MouseFunc(int button.'1'. oldY = newY. newY = y. float RelY = (newY .GL_LIGHTING). } static void MotionFunc(int x. elbowAng += RelX * 90. case 2: shoulderAng += RelY * -90.GLUT_WINDOW_WIDTH). Glut. break. case 3: wristAng += RelY * -180. int y) { newX = x.GL_LIGHT0). int x. wristTwistAng += RelX * 180. int y) { oldX = newX. GL.Exit().17 robotControl = c . break.glEnable(GL.glutGet(Glut. fingerAng2 += RelX * 180.GLUT_RGB | Glut. } [STAThread] public static void Main(string[] args) { Glut. float RelX = (newX .GLUT_DEPTH).glEnable(GL.glutInitWindowSize(512.glEnable(GL.GLUT_DOUBLE | Glut. if (button == Glut. newY = y.glutCreateWindow("The Robot Arm"). Glut. GL. Glut. 100).

Glut. Glut. Glut.glutIdleFunc(myIdle).glEnable(GL.GL_CULL_FACE).GL_DEPTH_TEST).glutMotionFunc(MotionFunc). Glut. GL.glutMainLoop().glutReshapeFunc(myReshape).blogspot.glutKeyboardFunc(KeyboardFunc).com/2008/02/robot-arm-with-opengl-in-csharp. Glut.glEnable(GL.glEnable(GL.18 GL. GL.glutMouseFunc(MouseFunc).GL_NORMALIZE).glutDisplayFunc(myDisplay). Glut. } } } You can get a copy of the source code and executables at: http://lenielmacaferi. Glut.html .

The robot arm’s motion occurs according to the following table: Key Motion with mouse support 1 Moves the base in the flat surface 2 Rotates the arm in 360º 3 Moves the shoulder and the elbow 4 Moves the fist 5 Moves the fingers Table 1 . . the elbow. the shoulder.19 3 APPLICATION The robot arm that we implemented operates with the keyboard and mouse support. the fist and the fingers.Robot arm keyboard and mouse bindings The following are some screenshots of the robot arm according to the user’s accomplished operation. Pressing the keys from 1 to 5 we have the control of the different parts of the robot arm that are: the base.

Initial position of the robot arm .20 Figure 3 .

Motion of the robot arm’s base in the flat surface .21 Figure 4 .

Robot arm’s rotation in the base pivot .22 Figure 5 .

Robot arm’s shoulder and elbow motion .23 Figure 6 .

Robot arm’s fist motion .24 Figure 7 .

25 Figure 8 .Robot arm’s fingers motion .

26 4 CONCLUSION We acquired knowledge about terms. The virtual simulation is an excellent way of avoiding unnecessary outgoings and at the same time enables the designer architect to improve his work. concepts and questions related to the subject what make us capable of working with the commands of the OpenGL language and consequently we are prepared to elaborate 3D graphical projects of the more diverse types. . All that said. hierarchical transformations. we conclude that the study of such concepts is of great value in the Computer Engineering course. This paper gave us a satisfactory view of graphics scenes. instantiations. stack of matrices and OpenGL transformations.

[5] Industrial robot. <http://science. 2007. Available at <http://en.org/wiki/OpenGL>. 2006. Accessed May 18. Brian.27 5 REFERENCES [1] Robot arm. 2007. 2007. 2007.edu/~dm/UNC/COMP236/Homeworks/hw1b/>. [6] Harris.cs.org/wiki/Industrial_robot>. Available at <http://en. COMP-236 . 2007.wikipedia. [2] OpenGL. Accessed May 18. Accessed May 18. Howstuffworks. January 08.wikipedia.wikipedia. Available at <http://en.unc. Tom.howstuffworks. part b.org/wiki/Robot_arm>. [3] Manocha. Available at <http://www. Accessed May 18. Dinesh and Salomon.com/>.com/robot2. Accessed May 18. How a Robot Arm works. Available at . [4] The Tao Framework. Available at <http://taoframework.Homework 1.htm>. Accessed May 18. The Robot Arm. 2007.

Sign up to vote on this title
UsefulNot useful