# STEP-NC Compliant Intelligent CNC Milling Machine with an Open Architecture Controller
## 3 Software Development  
Numerical Control Kernal (NCK) was developed on a Raspberry Pi 3 B+ single-board computer, using C++ programming language. The HMI was developed with the aid of Qt. The user is facilitated with five operating modes, namely, Home, Manual, MDI, Run and Edit (Figure 6). \begin{table}
\begin{tabular}{l l} \hline
**Component** & **Details** \\ \hline Servo Motor & Brushed DC motor, KL34-180-90 \\ \hline Axis Drive & Gecko Drive G320X \\ \hline Encoder & CUI AMT102 \\ \hline Power supply & 80 VDC \\ \hline Controller & Raspberry Pi 3 Model B+ \\ \hline I/O Board & Arduino Mega 2560 \\ \hline Spindle Motor & Three Phase, 2.2 kW, AC Induction Motor, RTM-80 \\ \hline VFD & NowforEver E100 \\ \hline Current Sensor & CZH-LABS D-1020 \\ \hline \end{tabular}
\end{table} 
Table 2: Electrical components. Five main software modules (Figure 7) are incorporated in the NCK, namely, motion control modules, file read, interpolator module, ISO 14649 interpreter module, digital and analog input-output module and HMI module. Figure 6: Functions of operation modes. The ISO 14649 interpreter module begins by reading STEP-NC part21 file to the CNC controller. An open-source software developed by National Institute of Standards and Technology (NIST) is used to interpret the file. The interpreted and processed data are saved as a Canonical Machining Command (CMC) file [34]. Canonical commands are atomic instructions, which produce a tool motion or a logical action [35]. Data inside the CMC file are then extracted by the data extractor module. The data are sent to the interpolator module if a tool motion command is extracted. Otherwise, the extracted command is processed individually. The interpolator module accepts the linear motion commands STRAIGHT_TRAVERSE(), STRAIGHT_FEED() and the circular motion command ARC_FEED(). All the other canonical commands are directed to the logical action processing module. A machining trajectory is planned, according to the motion commands passed from the CMC file. The interpolator module controls the tool movement along the proper trajectory. Linear and circular interpolation is used to command the axis movement along its trajectory. To have a smooth movement of the machine, acceleration and deceleration should be imposed during the start and end of a block. Generally, there are two kinds of acceleration and deceleration control methods: control of acceleration/ deceleration after interpolation (ADCAI) and before interpolation (ADCBI) [36]. The path command errors cannot be eliminated in the ADCAI method, which limits its machining accuracy. In contrast, path command errors are eliminated in the ADCBI method, theoretically [37]. As such, the ADCBI method with a trapezoidal velocity profile is used in this development. A trapezoidal velocity profile is applied with preset acceleration and deceleration values to reach the commanded position by interpolation. The trapezoidal velocity profile is easy to implement, computationally less intensive, and thus recommended for low-speed, low-cost machines. There are two main methods to develop linear and circular interpolation algorithms. The first method is to keep a constant displacement with a varying interpolation period. The second method is the opposite of the first method, in that it keeps a constant interpolation period with varying displacement [38]. In this development, the first method of the interpolation algorithm is applied with constant displacement. Figure 7: Software modules. The linear interpolation algorithm is developed based on Equation (1). The controller is expected to drive from point \(\mathrm{P_{s}(X_{s},Y_{s})}\) to \(\mathrm{P_{e}(X_{e},Y_{e})}\) along a linear trajectory as shown in Figure 8. Consider two points on the line \(\mathrm{P_{n}(X_{n},Y_{n})}\) and \(\mathrm{P_{n+1}(X_{n+1},Y_{n+1})}\) placed \(\delta t\) distance away from each other. The interpolation interval \(\delta t\) is considered to be the constant displacement along the line.