Optimization of the setup position of a workpiece for five-axis machining to reduce machining time

Five-axis machining is commonly used for complicated features due to its advantage of rotary movement. However, the rotary movement introduces nonlinear terms in the kinematic transform. The nonlinear terms are related to the distance between the cutter location (CL) data and the intersection of the two rotary axes. This research studied the possible setup positions after the toolpaths have been generated, and the objective was to determine the optimal setup position of a workpiece with minimal axial movements to reduce the machining time. We derived the kinematic transform for each type of five-axis machines, and then, defined an optimization problem that described the relationship between the workpiece setup position and the pseudo-distance of the axial movements. Eventually, an optimization algorithm was proposed to search for the optimal workpiece setup position within the machinable domain, which is already concerned with over-traveling and machine interference problems. In the end, we verified the optimal results with a case study with a channel feature, which was real cutting on a table-table type five-axis machine. The results show that we can save the axial movements up to 16.76% and the machining time up to 10.70% by setting up the part at the optimal position.


Background
In general, a five-axis machine is constructed with three linear axes and two rotary axes, with which the cutting tool can be tilted to cut free-form surfaces and avoid collision between the tool and the workpiece. In addition, the workpiece can be fabricated within minimum setup times, which can effectively reduce machining time including the time for planning multiple setups and making customized fixtures. Although the five-axis machining has the advantages mentioned above, it still requires operators to make many decisions, such as tool selection, tool orientation, and setup position, which may affect the machining efficiency.
Usually, engineers could directly generate the fiveaxis toolpaths for a part using CAM software. The toolpaths represent the tooltip position and the tool orientation, based on the workpiece coordinate system (WCS). Nevertheless, the machine only recognizes the position relative to the machine coordinate system (MCS). Thus, a transformation between the WCS and the MCS is necessary. During the process, the tool trajectory is complex due to the motion caused by the two rotary movements. Moreover, due to the varying distance between the tooltip position and the rotary center, different setup positions can cause different tool trajectories in MCS. In other words, machining efficiency can be improved by optimizing the setup position of a workpiece. Until now, the decision for a setup position still depends on the operator's experience. The experience cannot guarantee that the two major issues will not occur: one is the collision between the tool assembly and the machine components, and the other is overtraveling occurring on the linear axes. Additionally, little research on the relationship between the setup position and the machining efficiency has been made.

Literature review
In general, cutter location (CL) data is used to describe the toolpaths. The CL data have to be transformed to the NC code, which is based on the MCS, so that the machine can move accordingly. Thus, the kinematic transforms for five-axis machine structures are needed. Five-axis machine are commonly categorized into three types: head-head, head -table, and table-table, based on the location of the two rotary axes. Many researchers have studied kinematics of the machines using the homogeneous coordinate transformation matrices in Denavit-Hartenberg notation. 1 Lee and She 2 derived kinematics for a head-head type, a head-table type, and a table-table type. Jung et al. 3 developed a postprocessor for a table-table five-axis machine tool with A and C axes (TATC), and then proposed an algorithm to prevent interference in certain situations. She and Lee 4 and She and Chang 5 designed a generalized kinematic model, which combines the primary and the secondary rotary axes on both the spindle side and the table side. The generalized kinematic model can be applied to all types of five-axis machine tools. Sørby 6 derived forward and inverse kinematics for five-axis machine tools with non-orthogonal rotary axes B and C on the worktable. Yang and Altintas 7 used the screw theory to develop a generalized forward and inverse kinematic transform method, which models each kinematic element as a revolute joint or prismatic joint. The screw theory method can easily calculate the inverse kinematics with only the point and vector of each joint. Many researchers developed kinematic models containing nonlinear terms due to the involvement of two rotary axes. The nonlinear terms result in variations of distance equation within five-axis machining trajectories. The result of distance equation could be altered in two aspects, as discussed in the following. One is the orientation of the workpiece; the other is the position of the workpiece. However, the two factors are too complicated to be considered at the same time. Some researchers studied the effects of the orientation of a workpiece on planning the toolpath. Lee et al. 8 determined the optimal workpiece orientation by the minimum rotary movement. Hu et al. 9 determined the optimal setup by the largest intersection of the visibility maps. Some researchers studied the position of the workpiece after the toolpath had been defined. Anotaipaiboon et al. 10 studied the optimization problem of the workpiece position to minimize the kinematic errors caused by nonlinear tool trajectory. Tutunea-Fatan and Bhuiya 11 proposed a method to determine the nonlinear errors of the headhead type five-axis machine. Then, they compared the efficiency between the structures with different combinations of rotary axes, and found that the combination with vertical rotational axis tends to move more than with only horizontal rotational axes. Lin et al. 12 focused on the movement errors on a TATC type machine. Then, the optimal workpiece position was found by using particle swarm optimization in the machinable domain to minimize the nonlinear error caused by the rotary movement. The machinable domain was constructed as a cuboid field according to the travel of three linear axes of machine. Xu and Tang 13 considered energy efficiency on the movement of each axis. Then, they proposed an algorithm to find the optimal workpiece setup with minimum energy cost. Shaw and Ou 14 derived a transformation matrix on a TATC type machine to find the minimum movement on the X, Y, and Z axes. Then, he used a generic algorithm to search for the best position for the workpiece in a cuboid domain that formed with a limit of three linear axes. Pessoles et al. 15 defined the pseudo-distance as a sum of the maximum movement for the three linear axes along the toolpaths. He discretized the possible domain of a workpiece setup position, and then he computed the pseudo-distances for all the setup positions. Eventually, the optimal workpiece setup position was determined by finding the minimum pseudo-distance.

Objective
The research above studied about the machining distance of table-table type machines with AC type and BC type configurations. Nevertheless, the relationship between the workpiece position and the machining time is still unknown for different types of five-axis machines. The machining time is a complicated issue affected by system performance, including toolpath trajectory complexity, acceleration planning, and motor response. To simplify the problem, we considered the axial movement distance as a measure of the machining time and ignored all the other factors that may affect the machining time. In addition, over-traveling and interference problems between the tool assembly and the machine components have not been considered yet. In other words, the workpiece may not be completed due to over-traveling or interference problems. Therefore, the objective of this research was to determine the optimal setup position of a workpiece with minimal axial movements on a tool trajectory in a machinable domain, where the workpiece can be machined with one setup without problems including over-traveling of each axis or interference between the tool assembly and the machine components.

Statement of the optimization problem
Kinematics of a five-axis machine 16 In this section, we only derived the kinematic transform of A and C rotary axes for each type of the machines.  The relationship between the six coordinate systems in a TATC type, which means the fourth axis is an A axis, and the fifth axis is a C axis on a table-table type five-axis machine, can be illustrated in Figure 1  (1) TATC type Similarly, the relationship between each coordinate system of the head-table type and head-head type, or the HATC type and the HCHA type, five-axis machine can be illustrated in Figures 2 and 3, respectively. The transformation of these two types of machines can be derived by using the kinematic chain loop as well. The transformation matrices are defined as equations (3) to (6).
(2) HATC type (3) HCHA type Define the optimization problem of the workpiece position with axial movements The five-axis toolpath generated in CAM software usually consists of small linear segments. To keep the tooltip on the toolpath, we need to obtain the transformation matrices derived in section 2.1. As shown in Figure 4 Figure 4(c). Next, we derived the relationship between the offset d w and the total axial movements on the true trajectory, to determine the setup position with the shortest axial movements.
Because the linear and rotary movements in a single NC block would be completed simultaneously, we used the pseudo-distance instead of the linear distance to represent the total axial movements. Typically, the total pseudo-distance, 17 which will be called distance in the following, of the axial movements is determined as the root sum square of the movement in each axis, as shown in equation (7), in which l is defined as the total pseudo-distance of the whole trajectory, and l i is defined as the distance on segment i of the trajectory.   To find the pseudo-distance, first, we derived the 4 4 homogeneous transformation matrix T i and S i with different kinematics of machine with the rotary angles A and C according to the steps in section 2.1. The general form of the transformation matrices can be represented as equations (8) We can define an offset vector (p, q, r) as the movement from the original setup position. As shown in equation (11), the position of the start position of segment i can be transformed into the machine position with the offset of the setup position. Since the additional offset vector (p, q, r) is a 3 1 vector, we need to add an element 0 to make it a homogeneous coordinate.
Because the fourth element of homogeneous coordinate is used for homogeneous transformation only, we can reduce the vector p i ð Þ offset from 4 1 to 3 1, as shown in equation (12). Then the start and end positions of segment i can be transformed to the machine positions with the consideration of the offset of the setup position, as shown in equations (12) and (13).
Here we defined DX i , DY i , and DZ i as the following equation by subtracting equation (13) from equation (12), In addition, we defined DA i and DC i as the movements of two rotary axes in segment i, as shown in equations (15) and (16). Thus, the pseudo-distance of segment i, l i , can be calculated by using equation (17), with the consideration of the offset of the setup position.
As shown in equation (17), it is well-known that the Euclidean distance is a convex function. 18 In other words, the equation is a typical convex function, we called the distance function f . However, the domain of the distance function f , F, is different from the machinable domain which exists the offset vector (p, q, r), which is denoted by G. Thus, the mapping from F to G is needed. Since the rotary movements stay the same within the transformation from O W XYZ to O M XYZ, the terms DA i and DC i are constant. Therefore, the terms would not affect the convexity of the distance function. Thus, we can simplify the equation by eliminating the terms DA i and DC i from equation (17). The simplied vector is denoted by L i , Then we can redefine the distance function of segment i, l i Ã , which is the Euclidean norm of L i , The vector L i can be represented as equation (20) from equation (14) with an affine mapping, where R T iÀ1 and R T i are the rotary matrices in the transformation relative to the start position p iÀ1 and the end position p i , respectively. M is the matrix obtained by subtracting R T iÀ1 from R T i , which is a linear transformation in the machinable domain G. The vector d w is the offset vector (p, q, r) in G. N is a vector in the domain F. The distance function now is f :R 3 ! R, M 2 R 3 3 3 , and N 2 R 3 , then we can define the function g:R 3 ! R by which maps the distance function f from the domain F to the domain G. We can define u, v 2 R 3 in the domain of the function g. Then 8l 2 ½0, 1, The equation shows that the function g is a convex function as well. Then, the objective function, which is the total distance l Ã , can be represented as The objective function, l Ã , is a non-negative weighted sum of convex functions. We can define non-negative weights a, b ø 0 and g 1 , g 2 as convex function. Follow the definition of a convex function, 8l 2 ½0, 1, Then, 8l 2 ½0, 1, h(lu + (1 À l)v) = a Á g 1 (lu + (1 À l)v) + b Á g 2 (lu + (1 À l)v) ł a Á (lg 1 (u) + (1 À l)g 1 (v)) + b Á (lg 2 (u) where h = a Á g 1 + b Á g 2 , which can be proved as a convex function. With the proof above, the objective function, l Ã , is a convex function in machinable domain G. In other words, there exists a global minimum that is the same as the local minimum in the set of l n Ã with a spatial set of setup offset variables d w . The objective of the optimization problem is to determine the optimal setup position of the workpiece to minimize the total distance for the axial movements in the machinable domain, subject to the offset vector d w in the machinable domain G Next, we proposed an algorithm to search the optimal result within the constraint region of the machinable domain. 19 Method to determine the optimal setup position The objective function has been proven as a convex function, which means that the local minimum is the same as the global minimum in a dexel. Hence, we can use the gradient descent method to search for the minimum in the machinable domain for each dexel. 20 The machinable domain is the collection of all possible setup position without having problems including over travel limits of any linear axis and collision between the tool assembly and the machine components. However, the machinable domain is too complicated so that practically it can be described in discretized dexel, which is pixels on the XY plane with depth information in the Z-axis, as shown in Figure 5.
To ensure that the global minimum is selected within the machinable domain, we need to check each local minimum to obtain the global minimum. The local minimum is the minimum in each dexel. Nevertheless, there might exist certain minimal values that are the same as the global minimum. Thus, we proposed another criterion to select the global minimum from the same minimum values at different positions. The criterion is to choose the position closest to the center of the worktable in order to meet the common setting in industry. Eventually, the optimal workpiece setup position with the shortest distance of the axial movements can be obtained.
As a result of optimization, d opt refers to the shortest total axial movements with the workpiece in the optimal setup position. d org refers to the original distance of the workpiece in the original setup position. In general, the original setup position is set at the center of the pallet table. To compare d opt with d org , d R is defined in equation (28) as a percentage of reduced axial movements. Moreover, the optimized and original machining time t opt and t org are recorded in the case study. t R is defined as the percentage of the reduced machining time, as shown in equation (29).

Experimental environment
In this research, the toolpaths would be planned in NX software (Siemens, Germany) and then simulated on a TATC machine (Model Number UX300, Quaser, Taiwan), as shown in Figure 6(a), which is equipped with a Heidenhain iTNC530 controller. The specifications of the machine, including the travel limit (Table 1) and the offset data of the coordinate system (Table 2), were applied to calculate the optimal workpiece setup position. The offset data from O 5 XYZ to O w XYZ was set to zero because we coincided these two points with the setup setting on machine. The dimensions of the five-axis machine d M!4 th and d 4 th !5 th were measured by using the Heidenhain probe TS740 and the Heidenhain calibration sphere KKH100 with the CYCLE451 command built in the Heidenhain controller, as shown in Figure 6(b). After that, we machined the parts to obtain the cutting time for comparison among different workpiece setup positions.

Example of optimization program process
In this section, we would use a simple example to demonstrate the process of optimization. The example is a linear cutting toolpath. The CL data are shown as follows, FEDRAT/MMPM, 1000.0000 GOTO/0.000, 0.000, 0.000, 0.000, 0.000 GOTO/10.000, 20.000, 30.000, -40.000, 50.000 The start position (x 1 , y 1 , z 1 , A 1 , C 1 ) is (0, 0, 0, 08, 08), and the end position (x 2 , y 2 , z 2 , A 2 , C 2 ) is (10, 20, 30, À408, 508) defined in O W XYZ. The unit of the linear axes X, Y, and Z was millimeter, and that of the rotary axes A and C was degree. The length of the cutting toolpath d cut was 37.4166 mm, which was calculated as a root sum square distance from (0, 0, 0) to (10,20,30), The first step was to divide the toolpath into small segments with the interpolation time of the controller t ipt , which was 0.1 ms for the iTNC530 controller. Because the feed rate F in the CL data was 1000 mm/min, the interpolation distance d ipt was calculated as follow, Then we can extract the first segment of the cutting path by using r ipt , the ratio of the interpolation distance d ipt and the length of the cutting toolpath d cut . In this example, r ipt = d ipt =d cut = 0:0017=37:4166 = 4:5434 3 10 À5 : ð32Þ With the interpolation ratio r ipt , the interpolated lengths or angles can be calculated as (0:4543, 0:9087, 1:3630, À 1:81748, 2:27178) 3 10 À3 between the start position and the end position along the five axes of the machine tool.
Next, we focused on the interpolation segment between position A (0, 0, 0, 08, 08) and position B(0:4543, 0:9087, 1:3630, À 1:81748, 2:27178) 3 10 À3 . The transformation matrices related to both positions can be calculated as follows by using equations (1) and (2). Here we substitute coordinate of position A and B, the kinematics data in Table 2 into the transformation matrices, and the cutting tool we used is 100.125 mm measured from the spindle nose to the tooltip along the -Z direction.
(1:0061 3 10 À9 r + 2:5153 3 10 À9 p + 4:9864 3 10 À14 q À 5:7689 3 10 À8 ) 2l i ð38Þ With the numerical gradient g, we can calculate the optimal value r by using the gradient descent method in each dexel. For instance the dexel at x and y position (0, 0), the gradient is calculated by substitute p= q = 0 into equation (39). The range of r at the (0, 0) position was [4,425] along the Z-axis, which was obtained from the machinable domain as shown in Figure 7(a). The machinable domain is calculated by the algorithm we proposed. 19 Thus, the local minimum value can be obtained at 4 mm offset along the Z-axis on the dexel at (0, 0) position, as shown in Figure 7(b), where the relationship between the machining distance and the offset value is illustrated. After the optimization program computed the minimum for each dexel, the global minimum value was found at (10, À35) with the optimal offset value 4 mm along the Z-axis, which is the position of the minimum value shown in the contour plot of Figure 7(c).

Case study
A cuboid with a curved channel was used to demonstrate our study, as shown in Figure 8(a). The channel is altered from 30 mm to 28 mm in diameter along a spline curve. It can be machined from both sides at one-time setup on a five-axis machine tool. The origin of the workpiece was at the center of the bottom surface, which is coincided with the center of the worktable, as shown in Figure 8(b). The toolpath was planned to finish the channel from both sides with a 80 mm long, 10 mm in diameter ball-milling tool. The  total length of the tool assembly is 230 mm, as shown in Figure 9.
According to the workpiece's machinable domain, it was found that the workpiece must be raised 123 mm along the Z-axis from the orginial workpiece setup position, so that the workpiece is machinable. Figure 10 shows a contour plot of the total axial movements distance. The figure shows that the original setup position, the black ''o'' at (0, 0, 0), is not machinable. Within the constraint of the machinable domain, the modified setup position, the blue ''o'' at (0, 0, 123), gives the distance of 64653 units. However, we can find an optimal setup position, the orange ''o'' at (0, 90, 65), to reduce the distance. The global minimum of optimal setup position at (0, 90, 65) gives the shortest distance of 53,816 units.
Three parts with three different setup positions listed in Table 3 were machined, as illustrated in Figure 11. Because the part put at (0, 0, 0) is not machinable, we move the part to the modified setup position (0, 0, 123) to make it machinable, and the total axial movements was calculated as 64,653 units as listed in Table 3. The real machining time was 561 s. Then we set the part at the optimal setup position, and the total axial movements was calculated as 53,816 units, which was 16.76% less than the those for the part put at the   modified setup position. The machining time was 501 s, which was 10.70% less than that for the part put at the modified setup position. Because the total axial movements were very complicated, the reduction in distance was not very consistent with that in machining time.
Based on the results, it is demonstrated that the algorithm proposed can find the optimum setup position to reduce the machining time effectively.

Conclusion
In this paper, we derived the kinematics for each type of five-axis machine tools. Then, we used the general transformation matrix to derive the optimization equation and the gradient descent method to find the global minimum. A case is presented to verify the proposed method and the total axial movements were reduced by 16.76%, and the machining time was reduced by 10.70% if we set up the workpiece at the optimal position. The proposed method can substantially reduce the machining time for the five-axis machining, which is practically important to the machining industry.