Research and Development of Sampled-data Interpolation Algorithm Software in CNC System Based on the Visual C++

Nowadays, sampled-data interpolation algorithm has been the core technology in modern CNC system, so there are more researches concerning description of the principle of the arc-interpolation and presentation of the flowchart of the arc sampled-data interpolation algorithm. With the development of virtual simulation system software, the coordinate of arc-center is a key question inferred and confirmed by formulas. Therefore, the method of affine transformation is presented to transform the coordinates of the arc or the spiral curve. In addition, some major and minor arc, the clockwise and counterclockwise arc of quadrants, spiral curve along with these sampled-data interpolation algorithm software will be displayed in CNC virtual simulation system based on the visual C++.


Introduction
CNC machine-tool is the key equipment in modern manufacturing industry, and CNC path control (interpolation) is the core principle of CNC machine-tool, which reveals the nature of CNC machining. In traditional CNC system, the interpolation algorithm can be divided into two categories: pulse incremental interpolation algorithm and sampled-data interpolation algorithm, both of which can be used to implement the interpolation of spatial line, spiral curve or arc, and some of algorithms can be used to implement the interpolation of spline or parabola. The principles and the subsequent improvement of these algorithms have been mature [1] . As we know, the interpolation algorithm is an implemented with hardware to meet the need of real-time [2] , however, with the development of the high-speed of computer software, the interpolation algorithm can be implemented by software to meet the real-time requirement. It is the hot topic of path control in CNC system, high-precision and highspeed of the interpolation algorithm and implemented are researched in many results [3][4][5] . However, there are few researches about CNC virtual simulation system, especially software development with using visual C++. In this thesis, the author attempts to elaborate the introduction of the principle of sampled-data interpolation algorithm and the establishment of the CNC virtual simulation software platform.
In the following sections, section two depicts the principle of the sampled-data interpolation algorithm for arc-interpolation; section three analyzes the key technology of soft-ware development; section four demonstrates examples of software development based on Visual C++ and section five offers a conclusion.

Principle of Sampled-data Interpolation Algorithm for Arc-interpolation
In order to meet the machining precision, the string or secant is used, instead of which curve to realize feed, namely linear approximating arc. The principle of inscribed linear is to describe the string between the arc and two sampling points and approximate the corresponding one. The A(X i-1 , Y i-1 ) and B(X i , Y i ) are supposed the two adjacent interpolation points of the arc, the linear AB values of the arc equal to L  , the formula is: (1) Where "F" means Feed, "Ts" means interpolation cycle. When the tool moves from A to B, the X axis coordinate increment values is a When the 1 The moving point coordinate is expressed as: In the formula (2) The formula of areaII: The formula of areaIII: The formula of areaIV: (8) By contrast, the formulas from (5) to (7), and the formulas from (6) to (8), Only through interpolation formula (5) of the area I and formula (6) of the area II are sufficient, the area III and the area IV can be achieved by conversion symbol mark S 1 . If considered further counterclockwise arcinterpolation, it's necessary to introduce another symbol mark S 2 to convert, so that the arc interpolation flowchart is shown in Fig.3 X>0?
In the Fig.3, the conditions of the endpoint is: Where the E i is the distance between the current inter-polation point (X i , Y i ) and its endpoint (X e , Y e ). When the moving point arrives at the end of the profile curve at once, and then the corresponding signs will be set in system, and process the next section contour.
The formula of interpolation error as follows: Where the "e r " is the maximum radial error-tolerance. If the maximum allowable radial error is e r ≤1μm, and the interpolation cycle is T s =8ms and the unit of feed speed is mm/min, these values are brought into the formula (10), and the feed speed F can be obtained as:

Circular Center Coordinate of Arc
In the 2-D coordinate system, the  value is confirmed by arc start point (x1, y1) and endpoint (x2, (15) However, the start point and the end point of the arc can't be presented accurately by the formula (15), there are 12 situations, which are shown in Fig.5. So, two variable cx and cy to denote in which side the center lies at the arc chord, the numbers "-1，0，1" are used for locating the positions.

Coordinate Transformation for Arc
The counterclockwise arc AB has been illustrated by four quadrants "3, 4, 1 and 2" in the XOY coordinate system, but the circular center of the arc was not in the coordinate origin "O". See Fig.6. The proposal of the coordinate trans-formation method solves this kind of the arc interpolation, the arc center is built in the new coordinate system XOY, every axis of which is parallel to the axis of XOY coordinate system, and the arc AB is divided into two parts that are respectively the arc AS and the arc SB. Taking the arc SB for example, the coordinates of the point S, B, C are defined as (x S , y S ), (x B , y B ), (x C , y C ) which in the XOY coordinate system, application of matrix formula (16), the coordinates of the point S (x S , y S ) and the point B (x B , y B ), which in the XOY coordinate system can be obtained as: (18) An arbitrary arc is interpolated by using coordinate transformation.

Affine Transformation for spiral curve
As shown in Fig.7, an arbitrary spiral curve should be interpolated in the space coordinate system of XOYZ, and one of the axes deviates from other two axes in XOYZ space coordinate system. There is a plane called as "P", which is perpendicular to the axis of spiral curve and going through the start point of the spiral curve. An arc is attainable by projecting the spiral curve onto the plane, then a coordinate system namely XOYZ, the center C of the plane P is the O, and the Z of which coincides with the axis of spiral curve, can be established, and the arc center is designated as its origin. Moreover, the positive direction of Z coincides with the spiral direction, and the X goes through the start point S. The normal vectors of X axis, Y axis and Z axis are defined as i , j , k respectively，which in the XOYZ space coordinate system. The normal vectors of X axis, Y axis and Z axis that in the XOYZ space coordinate system are defined as i  , j  , k respectively. Based on the theory of affine transformation [6] , with the function of affine trans-formation, O → C ( ) of the point C is (0, 0, 0) in the XOYZ space coordinate system, the affine transformation of the point E is as follow: The matrix formula is obtained as: Where the A is the matrix of affine transformation, and is also an orthogonal matrix. So, Therefore: The coordinate of the point E by transforming is: The arbitrary spatial curve can be transformed into one or more basic segments in XOYZ by using formula (23), and any arbitrary spatial curve is interpolated by using this theory of affine transformation.

Call for Basic Sub-modules of Interpolation
Taking a cylindrical spatial curve for example, the cylindrical spatial curves are projected onto the XOY plane, which are clockwise or counterclockwise arcs that are dotted arcs, these circular centers of which are placed in the origin of the plane XOY, and their start points are located in X. See Fig.8. The cylindrical spatial curve interpolation can be considered as an arc-interpolation in the plane XOY and Simultaneous Motion interpolation with Z-axis, along which the point from origin to positive direction. The flowchart of interpolation for cylindrical spatial curve is exhibited in Fig.9. The parameters that include end point and feed speed and pitch and direction of turning are initialized. Next, with respect to the dextral cylindrical spatial curve, after distinguishing its direction of turning, the DH1 of the "Basic Sub-module of Interpolation" is used to implement interpolation periodically form the start point which is in X. Whether the interpolation is finished or not, it has been estimated by the DH1 since the interpolation was terminated by itself if necessary. If the destination has been achieved, the interpolation would be ended. However, if the destination has not been reached yet, while the DH1 has been still exiting, the DH2 will be called as main program. By this way, the DH3 and the DH4 are called in turn. The DH1 is called again when the destination has not yet been reached but the curve of a lead has been finished and the current point returns to X. The case of levorotatory cylindrical spatial curve is similar to the dextral one, and the subprogram is called as follows: LH4→LH3→LH2→LH1→LH4→LH3→…… Fig.9 Interpolation subprograms for cylindrical Spiral curve in XOY.

Case Example
This period shows the examples of G02, G03 and different size step interpolation, which are shown in Fig.10  The interpolation of spatial curve is developed based on Visual C++, the interface of example validation is shown in Fig.11. Fig.11 Example of interpolation for spatial curve.

Conclusion
In this study, the software platform of arc-interpolation and the spatial curve interpolation are promoted by Visual C++ through introduction of the principle of sampled-data Interpolation Algorithm and preseting of the flowchart of arc-interpolation. Adopting the theory of coordinate transformation, any arbitrary arc could be interpolated in the 2-D plane, and arbitrary spatial curve could be transformed into more basic segments by using affine transformation. The establishment of basic sub-modules of interpolation is based on arc-interpolation that belongs to sampled-data Interpolation Algorithm. The thesis focuses on the development of the arc sampled-data inter-polation algorithm software, and attempts to build the CNC virtual simulation system, which can replace the real machine debugging. With the innovation of interpolation algorithm for CNC system, it will shorten development cycle and save development cost.