Based 3D Simulator for Computer Numerical Control

download Based 3D Simulator for Computer Numerical Control

of 3

description

Based 3D Simulator for Computer Numerical Control

Transcript of Based 3D Simulator for Computer Numerical Control

  • Development of OpenGL Based 3D Simulator for Computer Numerical Control

    Zongmin Chen School of computer and information Science

    Shanghai University of Electric Power Shanghai, China

    e-mail: [email protected]

    AbstractPC-based open architecture control systems (OAC) become the major trend in CNC control system development. This paper focuses on the development of a complete 3D simulator for an OAC system to verify a G-code file before sending it to a CNC machine to avoid risks of damaging expensive work pieces, breaking tools and fixtures or even crashing a CNC machine because of some programming error, it also can display the tool path in real-time mode when machining to make the user have better experience. In order to achieve the best performance, OpenGL application programming interface (API) for rendering and 3D visualization of tool path was adopted. Regular expression is used for faster G-code parsing. The programming platform is Visual Studio 2008.

    Keywords OpenGL, 3D simulator, G-code, G-code Parsing, Regular Expression, OAC,CNC

    I. INTRODUCTION Computer Numerical Control (CNC) technology has

    been playing an important role in the manufacturing industry since it was first developed in early 1950s [1].These CNC machine tools are very useful to machine the parts with complicated shapes in the industries such as aerospace, automobile.The computers used in conventional CNC control systems are specially designed for the CNC control purpose only. Each CNC control system has its own software and hardware structure, so it is a black box to the outside users. In the past ten years, due to dramatic increase in the capacity, improvement of the reliability and decrease of the cost of PCs, PC-based open architecture control systems (OAC) become the major trend in CNC control system development [2]. According to the IEEE, an open system provides capabilities that enabled properly implemented applications to run on a variety of platforms from multiple vendors, interoperate with other system applications and present a consistent style of interaction with the user (IEEE 1003.0).PC-based open control systems have many advantages than a conventional CNC system in Interoperability, portability, flexibility. Additionally, by means of the plentiful resources of the PCs, an Open CNC Systems can implement many functions, such as real-time 3D simulation, than a conventional CNC system does. This paper focuses on the development of a 3D simulator for an open architecture control system to verify a G-code file before sending it to a CNC machine to cut a part or to display a tool path in real-time mode when machining.

    II. SYSTEM REQUIREMENT AND RELATED TECHNIQUES

    To meet the industrial needs, the objectives of this design are: 3-D simulation and view manipulation Faster G-code parsing Multiple viewports

    A. Regular expression Basically, line segments are used to make up of the 3D

    tool path. So dots information that forms every line segment must be calculated first, this information was extracted from the G-code blocks. G-code parsing is the first job need to do. Regular expressions are perfect for the job of breaking the file into blocks and then breaking the blocks into individual words.

    G-code is a plain ASCII text file made up of lines or "blocks" as they are sometimes called. Each line has a number of words that begin with a letter and is always followed by a number. For example: G01 X10 Y20 Z-3. CNC programs can have callable procedures as well. These procedures or "sub programs" have a specific beginning and end label.

    G-code supports human readable comments, so the expression match needed to distinguish between comments and actual G-code words. Comments are usually between parentheses. For example, (REMOVE CLAMP). The comments can also span multiple lines. This match looks like this:

    \([^\(\)]*\)|[/\*].*\n|\n|[A-Z][-+]?[0-9]*\.?[0-9]* The first part of the match will match a comment or a

    newline. The second part will match a letter followed by a number. In code, the match string is constructed based on what the user specifies as a comment character. Once the match strings are set we parse the file. [3]

    B. 3D Graphics Engine In this design, we utilize the OpenGL engine for

    rendering and 3D visualization of tool-cuts. OpenGL is the most widely accepted cross-platform API for rendering computer generated images. Its simplicity as a programming library allows the OpenGL application developer to quickly develop applications capable of rendering complex images containing lighting effects, texture mapping, atmospheric effects, and anti-aliasing, among other techniques. [4]

    OpenGL is supported on every major operating system, it works with every major windowing system, and it is callable

    2010 International Conference on Artificial Intelligence and Computational Intelligence

    978-0-7695-4225-6/10 $26.00 2010 IEEEDOI 10.1109/AICI.2010.305

    319

    2010 International Conference on Artificial Intelligence and Computational Intelligence

    978-0-7695-4225-6/10 $26.00 2010 IEEEDOI 10.1109/AICI.2010.305

    319

  • from most programming languages. It offers complete independence from network protocols and topologies. All OpenGL applications produce consistent visual display results on any OpenGL API-compliant hardware, regardless of operating system or windowing system.

    C. System Description and Design In order to achieve the function of 3D simulation both in

    simulation mode before cutting and in real-time mode when machining, the design is divided into three parts: G-code loading and parsing, data transform, tool path plotting and processing. The data flow diagram of the system is shown in Fig 1. Figure 2 shows the structural diagram in preliminary design phase.

    Figure 1 Data flow diagram of the system

    Figure 2: The structural diagram in preliminary design phase

    III. DETAILED DESIGN Although every CNC controller may have its own G-

    code format, the most basic part of G-code is the same. The first step we need to do is the pre-processing for the G-code file. First filter out the comments and spaces in a line, get the valid part of the G-code. Then syntax analysis and logical analysis is made line by line, messages will be shown when error found. Further information regarding the locations and types of error will be given as well. [4]The second step is to extract the keywords from the G-code lines. Every line of G-code composed of strings separated by a space, and each string made up of a letter follows by a number. These letters and numbers are extracted and stored into an object of user defined class named mGcode class. The G-code data is stored into the objects of mGcode class line by line in sequence and formed an object array. In order to display the three-dimensional scenes properly in a given area, it is important to select the right scaling. The data stored in the

    object array is processed by multiplying a zooming factor according to the view area.

    A. User Defined Classes and Controls mGcode: this is a user defined class which is used to

    create objects that stored the data that extracted from G-code, including the function number of the G-code, tool number, the value of X,Y,Z,I,J,K, the angle of a arc, the radius of a arc etc. Figure 2 shows the structure of this class.

    namespace Gcode_Parsing // declare the class which used to store the G-code data of a block

    { class Gcode { private char letter; //the first letter of private string number;//function number of Gcode private string Tnumber;//Tool number private float x, y, z, i, j, k;// the cooridinate of

    point ,the center cooridinate of arc private float ar;//the angle of arc private float r;//radius of arc public int isI, isJ, isX, isY, isZ, isAr, isR, isF, isT;//if

    Match the G-code public char setLetter { set { letter=value; } } public string setNumber { set { number = value; } } } } OpenGLBase: this is a user defined control which is

    inherited from control class CsGl.OpenG.OpenGLControl, used to draw the graphics in 3D mode, add new member variables, member functions and constructors, keyboard and mouse response methods are also defined in this control. Form redrawing method OnSizeChanged(),initialization method GLContext() were rewrote. Graph drawing is performed through executing glDraw() method, which is called automatically by OnPaint().

    B. G-code Processing and Rendering There are only small parts of all the G-code dealing with

    motion control. They are linear interpolation code (G00, G01); circular interpolation code (G02, G03); absolute distance mode (G90) or incremental distance mode code (G91); inch system selection (G20) and millimeter selection code (G21). [5]

    The circular interpolation code (G02, G03) are the most complex in these G-code.G02 and G03 are mainly the same except the direction of the arc.[6]

    For a certain arc, first, we divided it into many small

    equivalent segments according to the length of the arc. The start point and end point of a small arc is the start point and end point of the line segment. Then we can calculate the coordinate of the start point and the end point using the formulas below:

    sin(A+B) = sinA * cosB + cosA * sinB cos(A+B) = cosA * cosB - sinA * sinB

    320320

  • Figure 3: The structural diagram in preliminary design phase

    Finally, we can easily draw the line segments that form

    the 3D graphics by calling the draw line methods.

    Figure 4: The flow chart in detailed design phase

    IV. CONCLUSIONS AND FUTURE WORK We have developed 3D G-Code simulation software

    capable of simulating the tool trajectory for the open architecture control system. The software provides a 3D graphical environment to manipulate (rotation, zooming) in four viewports. The performance of software has been

    proven through successful demonstration of interpreting a variety of CNC G-codes and delivering related functions. This 3D simulator shows the achievement of all features expected.

    Figure 5: G-code program simulation Line Selection for the G-code is a useful feature we plan

    to add in the next development. This feature can be describe as: if the mouse is near enough to a line that we have previously drawn, it could be identified by drawing it in a thicker pen, and given the content in a pop up window. This is helpful for the programmers when try to find the errors in a G-code file.

    [1] J.Francis Reintjes. Numerical Control Making a New

    Technology. Oxford University Press, New York, 1991. [2] S. Hong, K. H. Choi, J. G. Kim and S. Lee. A PC-based open robot

    control system: PC-ORC, Robotics and Computer Integrated Manufacturing, vol.17, pp.355-365, 2001.

    [3] Jason Titcomb CNC Graphical Backplotter. www.codeproject.com. [4] Dave Shreiner. Performance OpenGL: Platform Independent

    Techniques. April 27, 200.1 [5] SHANSHAN CHEN, B.E. GRAPHICAL SIMULATION

    SOFTWARE FOR THE TOOL PATH WITHIN AN INTEGRATED CAD/CAM/CNC ENVIRONMENT Submitted to the Graduate Faculty of Texas Tech University in Partial Fulfillment of the Requirements for the Degree of MASTER OF SCIENCE IN INDUSTRIAL ENGINEERING p21.

    [6] ZHAO Dong-lin, FANG Kai, QIAN Wei, ZHOU Ping Design and realization of NC code explaining. Industrial Automation Vol 28 Issue 1 2006-01 PP.43.

    321321