CNC Milling Machine Simulation in Engineering Education

In this work an effective simulator for a CNC milling machine is presented. It has been developed in EMC2, a free Opens Source NC software running in Linux environment, developed by an international community. It can be installed on a common PC and is able to: control a CNC machine; read part programs; display the tool path; send instructions to the CNC machine for the cutting process. In this work a new feature has been implemented, which can both display a 3D model of the machine and simulate all the motions of the movable parts of a real 3 axis end milling machine. This simulator lets the users not only verify the toolpath but also detect any possible collision by using the very computer which controls the milling machine. This system is very efficient and easy to useas powerful tool inEngineering education.

INTRODUCTION Thanks to the development and wide diffusion of CNC machines, recently the highest quality and quantity standards have been reached as far as the machining processes are concerned. It is nowadays possible to produce very complex shapes by CNC machines; but they often require sophisticated CAM systems, skilled users and a number of time-consuming tests in order to obtain the best results. For these reasons, the simulation of the machining processes can be useful in both training sessions and preproduction phases.
Virtual Reality applications in the field of CNC machines are able to virtually display machining processes. This technique is showing a number of advantages:  Beginners, as students, can safely learn how to use and set machines up.  The virtual simulation of both complex and unsophisticated processes can help users to reduce production time and costs.  In a very short time different solutions and machine settings can be compared in order to adopt the best one.  Interferences and conflicts between mobile and fixed parts can be detected in order to remove them.
Simulation is therefore a tool able to analyze different machining strategies not only rapidly but also without any damage, risk, waste or breaks. Moreover, companies which use simulations are in a position to continuously analyze their procedures in order to optimize operations, lowering both costs and time, enhancing quality and saving materials.
Nevertheless, the use of new CNC machines requires either a specific training for beginner users or a skill upgrading for veteran workers; for this reason a lifelong training system is often strongly requested.
Commercial NC software are able to command machines and, sometimes, display the toolpath, but cannot simulate the machining process nor the machine motions. Today a number of simulators is available on the markettogether with graphic visualization systems embedded in CAM software -but they are very expensive and hard to be used: they need powerful PC and are not directly connected with NC machines. Moreover, it happens very frequently that it is quite impossible to install and use this kind of software on the machine's onboard computer running the NC; for this reason a more powerful computer is needed, with a consequent increase in costs. In this context, the promotion of CAM software diffusion results narrowed down, not only in craftsman shop floors but also in small companies, which both usually have friendly and low budget NC machines.
In this work a customisation of EMC2 (Enhanced Machine Control ver. 2) -an Open Source NC software running in Linux environment -is presented. It can be installed on a common PC, and is able to control a CNC machine. It is also very popular in a worldwide community of users and programmers, who constantly develop new features of it.
II. PROBLEM REVIEW Since a factory model simulator can run thousands of times faster than the real factory operations, managers would like to have a rapid, non-disruptive methodology in the aim of performing tests on a number of different manufacturing strategies. Improvements suggested by real operations could be tested without risk by using the simulation [1].
As Banerjee and Zetu [2] argues, supported by an appropriate computer-based reasoning and by decisionsupport tools, a virtual factory operating in control mode could be capable of a significant amount of self-diagnosis.
On the other hand, when new machinery -or more modern production systems -are introduced, a nonnegligible uncertainty is always generated, especially on the most of veteran workers. It is the responsibility of the factory manager to carefully manage these improvements, since an inappropriate worker updating could have a negative rebound on the application times [3].
Sometimes, it is impossible for an inexperienced operator to take charge not only of the complex equipments but also the excessive costs.

PAPER CNC MILLING MACHINE SIMULATION IN ENGINEERING EDUCATION
In 2000 Xhijie,Zhengxu andRay [4] investigated the possibility of developing a Virtual Environment (VE) for manufacturing simulation based on a database system which automatically manages both the VE data and the manufacturing data, relieving users from complicated data modeling and providing an easy-to-use interface, so that each user is able to construct and configure a specific VE.
Li, Zheng, Zheng, Wu and Liu [5] in 2003, presented an end milling process simulation and an optimization system: both of them were based on the solid models of a cutter, a workpiece with its blank (all of them created through the modeling functions of a commercial CAD/CAM system) and the cutting paths (generated by the CAM application of the same system).
Recently Pérez AcalandSanzLobera [6] have proposed the development of a NC milling machine -commonly used in the aeronautical industry -based on objectoriented programming.
Moreover, workers training is essential in order to use new machining tools, and there are new European educative policies which not only provide for these aspects but also highlight the need for continuous education [7].Several studies have shown that it is feasible to switch from such a traditional teaching approach as classroom lectures into an interactive lecturing and teaching approach: this has a positive influence on the student motivation [8].
In 2002 Fuhua, Lan, Vincent andChuan-Junet al. [9] have developed an architecture of Virtual Reality Training System -together with a knowledge modeling techniquein order to: a) overcome the difficulties arising from both the complexity of systems and the variety of knowledge; b) fill the gap between abstract tasks model and its detailed implementation.
Recently Terkowsky et al. [10] have proposed a prototype of an e-learning platform for the development, implementation,and delivery of educational and training programs in thefield of manufacturing engineering. The development of tele-operated experimentation and its provision to distance learners opens new dimensions of knowledge acquisition particularly where experiments are the core elements of learning III. EMC2 OPEN SOURCE ENVIRONMENT In this work the Open Source software EMC2 has been used, available at http://www.linuxcnc.org [11]. EMC2 can be installed and executed on a common PC running Linux. It can be connected via parallel port or other hardware interfaces (PCI/ISA boards like Mesa) and is able to control CNC milling machines, robots and other machines.
The EMC software has initially been developed by NIST (National Institute of Standards and Technology). It is an Open Source software, which can be used by everyone. Firstly developed for the Windows NT Real Time version, it was later conveyed on a Linux version with Real Time extensions, not only for economic reasons, but also because of the better stability and efficiency of the Linux operating system. At first, the aim of this project was to provide the USA Small and Medium-sized Enterprises with a low-price alternative to the traditional Numerical Controls. Its primary function was to work as a Personal Computer Numerical Control for traditional machines which have been converted into automatic ones. EMC, nevertheless, has caught the attention of a great amount of people, both programmers and nonprogrammers, and has grown up in the fertile co-operating environment of the Open Source software. The main difficulty which was found in installing the Real Time Linux extensions has been overcome by the second version of EMC (EMC2), which supplies the program on a CD containing the modified, functioning operating system. Nowadays these versions have evolved in the shape of a live-CD: a bootable CD-ROM which contains both the Real Time Operating System and the program. This way they can be used and tested on a common PC without being installed and without modifying the existing system.
It has already been said that the EMC2 is both an Open-Source and an Open Architecture software. The first feature allows it to be freely distributed with its own source code, so that the user will be able to study its internal configuration and modify it according to his own needs. The second feature, on the other hand, pertains to the real structure of the source code, which is modular and extendable. This way the user will be in a position to add, modify, update, improve or substitute parts of it in a quite easy way, with targeted interventions only on the section he is interested in. The developer can hence modify the source code, implementing such specific functions, as adding new codes matching his peculiar needs. This feature can be useful when complex shapes have to be machined. Today B-spline, NURBS and 3D faces are very common in a great number of everyday items: therefore companies have to frequently realize elegant, fashion and engaging objects using these complex curves.
As a matter of fact, it is well known that -even in the newest CAD/CAM systems -when the NURBS are used for the generation of the tool path, a part-program has to be created, containing instructions for either linear or circular paths. But this implies a number of undesired effects on the feed rate during the machining. Moreover, such a part-program is also composed of a huge number of lines, so that it is difficult for the user to manage it. In order to solve -at least in a measure -the aforesaid problems, the Open Source EMC2 Numerical Control source code has been modified [12], in a way that a specific G-Code can be added for a practical and efficient description of the B-Spline and NURBS curves on the plane. This way an interpolation of the curve can easily be made, allowing at the same time the operator to remarkably reduce the problems related to the feed rate.
As previously mentioned, EMC2 has a flexible open structure; it allows the user to adopt some tools and customize its configuration in order obtain new features; in this work the problem of displaying a 3D model of the working machine in real time has been faced. It has also been investigated how to perform the remote control of the machine in order to make its use possible from a different place [13].
With this software, the Authors have previously developeda network environment in order to allow users to access and use machines via Internet [14,15], in order to safely control and see the machining processes even if a dangerous process is running.
In this case the students are able to both safely and comfortably access via Web to machining labs in the University. In this way students can either write ISO codes or obtain a Part Program using CAM softwares,

PAPER CNC MILLING MACHINE SIMULATION IN ENGINEERING EDUCATION
simulate it on their PC at home and send it via Internet to the CNC machine. The Part Program can be used in scheduled sessions, when an operator loads the blank on the machine and stand over the process, while the student watch live the machining process thanks to one or more webcams.This environment has demonstrated a full effectiveness both in industrial and in educational applications.
IV. SYSTEM CONFIGURATION The basic EMC2 configuration is composed of a number of files and modules which can be customized. A few files includes the main configuration information, i.e.
 which graphic interface will be used  the path of part program  which files have to be used in order to perform some operations (tool change, for instance)  the number of controlled axis  maximum speed of the machine  the limits of machining In this work a small, low cost three axis milling machine, called RM MiniMill, has been used. A template configuration file describing this machine has been modified and customized in order to control it.
The latest EMC2 releases include Vismach, an application which is able to display a working machine. Different configurations are available and both robots and three or more axis milling machine can be simulated. This application has been modified and customised in order to display the adopted machine.Vismach is a Python-based component, able to put together in a proper order a number of 3D machine components, by moving them according with NC code movement instructions (G-code).

A. The Python language and the EMC2 environment
Python is an object oriented language, but it also allows traditional programming too. For this reason, Python can be considered as an hybrid language, similar to C++.
Traditional programming is based on data structures (lists, tuples, ...), functions and procedures. This way, a program is composed by modules which collect function groups; every function has access to one or more data groups.
Object oriented programming is an alternative way to decompose a software project: the fundamental unit is the object, not the operation (the procedure).
EMC2 allows to import specific components inside the graphic interface. It is possible to display a window showing the items what have been defined in the Python file.The main focus of this work is to implement a Python file able to virtually build and move all the part of a CNC mini milling machine.

B. Simulator development
The NC software customisation has been performed in three steps:  Creation of a .ini file, based on machine features.  Creation of a.hal file(Hardware Abstraction Layerhttp://wiki.linuxcnc.org/cgi-bin/wiki.pl?HAL), able to fit the software both to the machine and to the displaying system.  Creation of a software -written in Python languageperforming the import procedure of 3D CAD components. Vismach also allows programmers to upload the 3D model of each component of the CNC machine. Every component can be realized in a 3D CAD environment while the Python file allows users to put CNC machine components in a proper order.
Moreover, in its first section, all the libraries used to build the program are imported. Afterwards all the pins and hal needed to move the machine components are defined. The main section of the file defines all the items composing the machine.
For instance, the following instruction: toolholder=Translate([AsciiSTL("toolholder.stl"), 0, 0, -20) is able to load the 3D stl model of the tool holder and move it 20 mm far from the origin, following the negative direction of Z axis.
The same toolholder has been inserted into a collection called zslide together with the tool and the slide.
zslide=Collection ([tool,toolholder, slide] This way it is possible to move all the three components along the z axis. The following command line limit the tool movement only along the z axis. zslide = HalTranslate([zslide],c,"head",0,0,1) The following images (Fig. 1) show the comparison between real and simulated images of milling machine. V. TESTING ACTIVITIES In this section a number of test results will be displayed. The real machining process will be compared with two simulations, one performed by the implemented EMC2 version and the other performed by the simulator of a common commercial CAM software (EdgeCAM). The main difference between the two software is the cutting process simulation: EdgeCAM can simulate it, EMC2 at this moment cannot.
Nevertheless, due to the EMC2 Open Source architecture, it is possible to develop a new feature able to simulate the cutting process as well as commercial CAM software does.
The following pictures (Fig. 2, 3 and 4) are a few samples of machining processes, performed in the aim of verifying the real efficiency of the developed simulator. All the part programs have been compiled through Edge-CAM with 3D models from EdgeCAM Part Modeler. All the machining processes have been performed on 50x120x40 mm blanks by a 7.8 mm cylindrical mill The pictures have been captured by a webcam. A free software (fswebcam) is able to capture and manage pictures; moreover, it is able to command webcams via prompt line. For this reason a few executable files have been written and included within the part programs as specific M-functions.
This way, since the open architecture of EMC2 allows the user to execute automatic procedures, it has been possible to capture pictures in specific moments duringmachining processes, at the same points at different depths.
VI. CONCLUSIONS It is a common practice to verify the NC code before producing a piece by NC machines. It is possible to manually verify NC codes of simple parts, but in the majority of cases it can be a hard and time-consuming procedure. Moreover, skilled technicians are required to do that, while nowadays, small companies cannot afford expensive and time-consuming procedures due to worldwide competition.
Simulators are efficient tools for education and training activities. Just as flight simulators are fundamental for airplane pilots, the simulation of a machine tool based on Virtual Reality, allows users (employees or students) to address the real machines for the first time after gaining a deep knowledge of their functioning, characteristics and limits.
For these reasons the use of an efficient simulator is a good solution to verify, modify and optimize NC files before loading them in the machine and starting machining processes.

A. Sample 1
Real picture EMC2 simulation EdgeCAM simulation   In this work a simulator of both the whole NC machine and the tool path is presented. It allows users to perform a preliminary check of both the part program and the tool path; it also allows not only to predict NC machine behaviours before using it, but also to detect possible collisions between tools/mobile components and the clamping system/static parts of the machine.
A detailed and accurate comparison between two different simulation approaches has been performed. The first simulator is based on a free Open Source software, customised by the authors, embedded into the NC software and able to control the directly connected machine; the second one is EdgeCAM, a commercial CAM software. EdgeCAM offers a more detailed simulation, is able to display the whole machine, the workpiece and the toolpath, but is expensive and is not embedded in the NC software. Moreover, it requires a more powerful computer than the NC machines.
It should be noticed that EMC2 is an opportunity for students and researchers to investigate the whole structure of the software and thus to understand the principles on which a modern numerical control system is based; moreover, it allows users to freely modify the structure.
EMC2 has been successfully used as a numerical control system for a milling machine, proving great flexibility and adaptability thanks to its peculiar architecture.The new EMC2 features, such as the presented ones, have been developed using HAL, a powerful tool which allows users to integrate any special hardware with the software; as a matter of fact, it is able to control the machine-tool and to simultaneously show the virtual model, displaying the same behaviours of the real machine.
The main difference between commercial and free software is that EMC2 does not display the removal of material from the workpiece. This behaviour may discourage the use of Open Source solutions. However, since the source code is free and available on the Internet, it is possible for anyone to make further changes to the software. It is also possible that, in the future, this feature will be covered.
What, however, allows EMC2 to emerge against Edge-CAM is its ability to machine (and in the present work also to simulate) the so-called "complex curves", such as the B-Spline or NURBS.
Thanks to a previous development [12], which has enabled the implementation of new instructions for the execution of complex curves, EMC2 is able to define every kind of forms, from the analytical to the arbitrary one. Compared to the traditional method, it saves both part program's lines and time to execute it.
The natural evolution of the software will be an overcoming of the current limitation: at present EMC2 cannot display the chip removal, but only the tool path. This limitation does not absolutely affect the functionality of the application, which is a great help for designers and users in training (i.e. both users involved in the management of CNC controls and students from schools and universities).
Another advantage provided by the machine virtual simulation is shown when it becomes necessary to predict the behaviour of a production system in case of new operating conditions, such as adding new equipment or development of new types of parts. In this field, the VR could become the most usual and useful tool.