Graphical User Interface For The 3 Axis Cnc Milling Machine Computer Science Essay

Published: Last Edited:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

This paper details the design and development of a Graphical User Interface for the 3-Axis CNC Milling Machine, which was designed in-house for testing and research purposes at the University of the South Pacific. The 3-axis CNC Milling Machine used COM Port terminal software, TeraTerm to communicate with the electronics hardware via RS232 link. The GUI was developed using Microsoft® Visual Basic 2008 Integrated Development Environment. The end result is an interface that is user friendly and is capable of controlling various tasks of the Milling Machine. This paper aims to explain how simple components of Microsoft® Visual Basic 2008 has been used to design a Windows® based user interface which is capable of complete control of CNC milling machine.

Keywords: GUI, Serial Port, CNC, G Codes, STEP NC


Over the years a number of methods have been developed to control machine tools. The most widespread used throughout the industry is the G Code language for NC machine tools programming. It is based on the data model stipulated by ISO6983, and has been used for over 50 years [1]. G codes, however, limits the usage of today's fast evolving high-performance hardware [2].

The latest development in NC machine tools programming is ISO 14649 or STEP NC. It is a new standard for data transferring between CAD/CAM systems and CNC machines. It remedies the shortcomings of ISO 6983 by specifying the machining processes rather than machine toolmotion by means of ''Workingstep'', as the basic entity [1]

Whichever method of programming NC machine tools is used, it is always important to verify the program before doing actual testing. Verification of NC part programs using a PC is inexpensive compared to testing on model parts. Cutting simulation as a means of testing and verifying NC cutting paths has become an important part of modern machining [3]. With the latest advancements in PC technology and 3D graphics it is much easier to simulate NC cutting paths.

A common CNC executes G-code programs, which are generated as a result of planning and scheduling in CAM tools [4]. However an interface is required to send or execute NC part program to the CNC. The user interface is the communication Tool between the operator and the PC-based CNC drilling machine, via the computer screen [5]. The recent advancement in software development technology using Object Oriented Programming (OOP) has made it possible to create simple user interface with a sound communication link to control NC machines. In 2002 [5], a GUI was developed at the University of the South Pacific for a PC-Based computer numeric control drilling machine. The platform for the graphical user interface (GUI) was written in Borland's new rapid application product, C++ Builder®.

Gordon and Hillery [6] developed a Windows® based graphical user interface for their CNC cutting machine. The user interface communicated with the machine via RS232 serial link. The programming environment used was Borland C++ Builder 3, which allowed the visual development of the program interface. The user interface developed also had features for homing the three axes, editing of NC part program (G Codes) and also previewing the two dimensional cutter motion.

This paper mainly focuses on the design of the Graphical User Interface (GUI) for the 3-Axis CNC milling machine. The user interface has been designed in Microsoft® Visual Basic 2008 Integrated Development Environment (IDE). The features of the GUI are explained in detail.



The CNC Milling Machine was designed in-house at the School of Engineering and Physics (SEP) at the University of the South Pacific (USP), for testing and research purposes. It uses an absolute three dimensional coordinate system to create its tool path. It sequentially passes instructions which are in the form of three dimensional coordinates to the Milling Machine for controlling the tool, similar to how G Codes are used.

The operational framework of the CNC milling machine is shown in Figure 2.1. It consists of a dedicated PC running Graphical User Interface Software which is used to upload a text file containing X, Y and Z coordinates. It also has features to control the milling operations and to get a two dimensional cutter path preview. The software is linked to the electronics hardware via RS232 serial link.

Figure 2.1 Operational framework of the CNC Milling Machine

The current CNC Milling machine is only capable of linear interpolation (G01), in terms of G Codes, or moving linearly from one point in the three dimensional space to the next point. To mill different geometries other than straight lines the milling machine has to be given a number of coordinate points which can be used to approximate that particular geometry. For instance to mill a curve the milling machine needs to be given a set of points which lie on the curve. Similar method was used by Min-Yang Yang and Won-Pyo Hong [7] in their three dimensional linear interpolation algorithm.

The CNC Milling Machine uses an absolute three dimensional coordinate system (X, Y, and Z) for its tool path generation. The three dimensional coordinates are defined in a text file. Each of the three coordinates has three characters in the text file for instance the X coordinate '0' is defined as '000' in the text file. The Basic Length Unit (BLU) is in millimeters.

The electronics architecture of the CNC milling machine consisted of five PIC microcontrollers (PIC16F877) in a distributed architecture, with one master controller and several slave controllers. The master controller of the CNC Milling Machine consists of a PIC16F877 microcontroller which is responsible for coordinating and controlling the overall operations of the Machine. It is the central intelligence system of the CNC Milling Machine. It receives its commands from the user through a user interface and commands other co PIC16F877 Microcontrollers in a distributed architecture to carry out their respective tasks.

The mechanical hardware consists of three stepper motors which drive the three axis of the CNC Milling Machine. It also has a 24V DC Motor which is the spindle motor. The worktable consists of clamps to clamp the workpiece firmly on the worktable. For feedback, the machine constitutes of limit switches which control the limit of the worktable.


Until recently, the CNC machine was using COM port terminal software, TeraTerm, to communicate with Master Controller via RS232 link. The GUI was designed to provide a user friendly interface instead of typing coordinates in TeraTerm. The GUI was designed using Microsoft® Visual Basic 2008 and coded in BASIC (Beginners All purpose Symbolic Instruction Code). The overall design of the main form of the user interface is shown in Figure 3.1.

Figure 3.1 Main form of the GUI

It was decided to incorporate the following features in the GUI

Opening of text file which contains the coordinates.

Previewing of coordinate file (or tool path) in two dimensional X and Y axis

Communication with the CNC Machine via RS232 link

Milling control features such as homing, manual jog etc

Displaying coordinate file

3.1 File Input

The GUI contains a MenuStrip at the top of the main form on which there are three menus, File, Setup and Help. The File menu contains an Open menu which opens a file browser window as shown in Figure 3.1.1.

The software utilizes an OpenFileDialog control of Visual basic 2008 to prompt the user for the files path. It allowed the user to choose which text file to open in the program. The OpenFileDialog control contains the Filter property which was used to control the type of file to be opened in the program. The only extension allowed was the *.txt. The ShowDialog() method was used to display the Open Coordinate File dialog box on the screen. The FileName property was used to get the path specified by the user. The dialog box is shown in figure 3.1.1

Figure 3.1.1 Open Coordinate File dialog box

After getting the path from the user, the program used a FileOpen() function to open the file specified by the user. The end of file function, EOF() was used to iterate through the file until the no more coordinates are left. The LineInput() function was used get a line of coordinates into a string variable. This string variable was then extracted to get the X, Y and Z coordinates in a separate array. The array containing the X, Y and Z coordinate was then used later to generate two dimensional previews and to send to the CNC milling machine. Finally the FileClose() function closes the text file.

3.2 Tool Path Preview

The graphical user interface that is designed also contains a two dimensional preview feature which can be used to preview the path taken by the milling tool on the workpiece. The GUI uses the namespace to create tool path. The preview panel, as shown in figure 3.2.1, gives a two dimensional (X, Y) preview of the tool path which will be followed by the cutting tool. It is also to check and verify that the input text file does not contain errors.

A Preview command button is used to generate preview. This is activated only when a valid coordinate file is loaded. The GUI utilizes system.drawing namespace which includes class to draw the preview. The DrawLines() method was used to draw a series of lines according to the X and Y coordinates in the coordinate file.

Figure 3.2.1 Tool Path Preview control

The use of three-dimensional absolute coordinate system has made the previewing algorithm much easier since the preview is two dimensional (X, Y), the program utilizes these X and the Y coordinates to draw a preview of the shape in the preview panel.

Once the Preview command button is clicked, the btnPreview_Click event procedure gets the array containing the X and Y coordinates which was previously read from the text file. The procedure then used these coordinates as points to draw a series of lines using the DrawLines() method. Since absolute coordinates are used, the lines connect from the end point of the first X, Y coordinate to the start point of the next X, Y coordinate. In this way the path taken by the cutter is drawn by connecting the series of points.

3.3 Milling Controls

The GUI on the main form contained a group box with a number of command buttons for commanding the milling machine. The Home command button was used to command the milling machine to rapidly move to its home position.

Figure 3.3.1 Milling Control panel

The advantage of using a software interface to control the CNC Milling Machine is that it acts like a control panel of the CNC which resides on the PC. Several command buttons have been used on the main form to command the CNC Milling Machine to carry out various tasks. The Home command button is used to command the CNC Milling Machine to move to its home position. The milling control also contains a command button Start to run or to send the coordinates to the milling machine to start milling. The flowchart in figure 3.3.2 shows this.

Figure 3.3.2 Flowchart showing the start subroutine


The user interface for controlling the milling machine resides on a dedicated PC. Therefore there should be some means of communication between the software and the electronics hardware. A standard desktop personal computer consists of several communications ports. These include parallel port (LPT1), serial port (COM), PS/2 ports and Universal Serial Bus (USB) ports.

Serial port communications has been used to with the electronics hardware. The Serial port or RS232 has several port settings that need to be set. The advantage of this obsolete technology is that it best suits the application we are designing, and the amount of data that needs to be sent to and from the milling machine.

Figure 4.1 shows the dialog box that appears to the user when the user chooses Serial Port from the Setup Menu. On this dialogue box the user can choose the port settings. The reason for including this control is so that the application may work on different PC's. The default port setting is shown in figure 4.1.

Figure 4.1 Serial Port Configuration dialog box

The communications via RS232 was made possible using the system.IO.ports namespace, and the SerialPort class of Visual Basic 2008. The SerialPort class consisted of properties/attributes, methods and events which was used in the communication algorithm. The ReadExisting() method was used to read data from the PC's serial port receive buffer (Rx). The Write() method was used to send string data to the electronics of the CNC Milling Machine. The flowchart in figure 4.2 demonstrates how the communication to the milling machine is made when the user clicks ok on the dialog box in figure 4.1.

Figure 4.2 Flowchart showing the communication algorithm followed.


One problem faced during the development and testing of the GUI was run time errors or exceptions. Runtime errors or exceptions occur as a result of normal operating conditions [8]. For example errors when the GUI is trying to open a COM port which is being used by another program. The problem was overcome using structured error handling or the Try…Catch code block in Visual Basic. The GUI used message boxes to display appropriate messages to the users when an exception occurred and allowed the program to continue.

The preview part of the GUI was tested by opening a text file containing 165 X, Y, Z points. These points resembled a circle in two dimensional (X, Y) planes. The result is depicted in Figure 5.1 which shows the tool path generated on the preview panel.

Figure 5.1 Tool Path preview showing the preview of a circle

Furthermore, the same file was used to mill a circle on softwood with the following settings:

Feedrate - 75mm/min

Spindle Speed - 2500RPM

Cutting Tool Diameter - 5mm

The result is shown in Figure 5.2. The result shows that the Graphical User Interface made no errors while sequentially sending coordinates to the milling machine.

Figure 5.2 Output of the CNC Milling Machine


Based on the result in the previous section of this paper, it can be concluded that the GUI design was successful. The GUI was able to communicate with the electronics hardware of the CNC Milling Machine using RS232 serial link. The preview algorithm of the program also worked well. Finally the GUI was able to sequentially send (X, Y, and Z) coordinates representing cutter path in three dimensional space, to the CNC Milling machine.

However, a number of tasks can be carried out in the future to improve the performance of the GUI and to enhance the output of the CNC Milling Machine. One such include the implementation of the industry standard G Codes which is based on ISO6983 data model, instead of X, Y, Z coordinate file. The G Code programming is a standardized way of controlling cutter motion.

The CNC milling machine is capable of moving in steps as small as 1 tenth of a millimeter. Thus it is also recommended to improve the GUI so that it can cater for coordinates with one decimal point. The output of the CNC milling machine will improve drastically by having coordinates in mm to one decimal point.

Another improvement that can be implemented on the GUI is using an abort button to cancel or abort the operations of the CNC Milling Machine. This is a standard safety feature which exists on most industrial machines including CNC machines.