Design and Implementation of a Stereo Vision System on an Innovative 6DOF Single-Edge Machining Device for Tool Tip Localization and Path Correction †

In the current meso cutting technology industry, the demand for more advanced, accurate and cheaper devices capable of creating a wide range surfaces and geometries is rising. To fulfill this demand, an alternative single point cutting device with 6 degrees of freedom (6DOF) was developed. Its main advantage compared to milling has been the need for simpler cutting tools that require an easier development. To obtain accurate and precise geometries, the tool tip must be monitored to compensate its position and make the proper corrections on the computer numerical control (CNC). For this, a stereo vision system was carried out as a different approach to the modern available technologies in the industry. In this paper, the artificial intelligence technologies required for implementing such vision system are explored and discussed. The vision system was compared with commercial measurement software Dino Capture, and a dedicated metrological microscope system TESA V-200GL. Experimental analysis were carried out and results were measured in terms of accuracy. The proposed vision system yielded an error equal to ±3 µm in the measurement.


Introduction
When it comes to the meso cutting machining industry, milling is the preferred choice due to its wide study and exploration [1]. It is used from the manufacturing of biochips [2] to fuel cell plates [3]. However, the high operating costs and the limitations in the tool geometries and dimensions, add additional manufacturing challenges [4]. Current studies on the topic explore the improvement of the models [5], the evaluation of the surface roughness of the tool or pieces [6], and the proper selection of optimal parameters [7].
Based on cutting process modelling [8,9], a new single point cutting model has been developed. To take full advantage of this model, a 6 degrees of freedom (6DOF) machine capable of tangentially aligning the tool to the velocity path, as illustrated in Figure 1, has been developed. This system has proved to be an acceptable substitute of milling due to the competitive geometries and shapes that is able to reproduce.
aligning the tool to the velocity path, as illustrated in Figure 1, has been developed. This system has proved to be an acceptable substitute of milling due to the competitive geometries and shapes that is able to reproduce. One of the key components studied in the current works is to monitor the tool in order to establish when it should be replaced to keep good quality standards in the machined pieces. Some are based on indirect measurements, which model the wear of the tool by measuring other variables such as cutting forces [10], vibrations [11] and electrode's profile [12]. Whereas other works measure the wear resistance of various tool structural parameters [13]. Other works are based on direct measures, which means that they measure the wear of the tool without using intermediate variables.
New approaches use machine vision to estimate the tool wear, mainly from bottom view images of the milling tool [14][15][16]. They proved to be able to successfully locate the workpiece references [17], along with the cutting edges of the employed tools [18,19].
In contrast to tool wear monitoring, fewer amount of works in the bulk of literature focus on the correct localization of the tool tip. One of the requirements to achieve an accurate geometry of the machined pieces is to provide a good monitoring system of the device. It should be able to precisely find the tool tip. The tool tip location is measured on the axis that orientates the tool along the path. Usually, this is a relative measure to the center of the C axis when the rotation is produced on the Z axis. Most of the computer numerical control (CNC) systems, such as FAGOR 8070 used in this paper, calculate the distance with respect to the central axis. Frequently, due to the nature of the manufacturing processes and the tool wear, the tool tip is not aligned to the central axis. Therefore, a correction of the distance estimation needs to be considered in order to produce reliable measures. Pérez et al. [20] used cutting forces to estimate the tip localization. Xuewei et al. [21] made use of the tool deflections to correct the tip path, whereas Singh and Dvivedi [22], and Yu et al. [23] used machine vision techniques with the same purpose.
To locate the tool tip on the 6DOF device, different technologies were analyzed, each varying in accuracy and costs. Given the dimensional restrictions of the device, and the required budget, the system must be compact, modular and low cost. With this in mind, a vision system implemented in a Personal Computer (PC) was preferred [24]. The flexibility, low costs and expandability are desired characteristics of such systems to obtain the pursued results. One of the key components studied in the current works is to monitor the tool in order to establish when it should be replaced to keep good quality standards in the machined pieces. Some are based on indirect measurements, which model the wear of the tool by measuring other variables such as cutting forces [10], vibrations [11] and electrode's profile [12]. Whereas other works measure the wear resistance of various tool structural parameters [13]. Other works are based on direct measures, which means that they measure the wear of the tool without using intermediate variables. New approaches use machine vision to estimate the tool wear, mainly from bottom view images of the milling tool [14][15][16]. They proved to be able to successfully locate the workpiece references [17], along with the cutting edges of the employed tools [18,19].
In contrast to tool wear monitoring, fewer amount of works in the bulk of literature focus on the correct localization of the tool tip. One of the requirements to achieve an accurate geometry of the machined pieces is to provide a good monitoring system of the device. It should be able to precisely find the tool tip. The tool tip location is measured on the axis that orientates the tool along the path. Usually, this is a relative measure to the center of the C axis when the rotation is produced on the Z axis. Most of the computer numerical control (CNC) systems, such as FAGOR 8070 used in this paper, calculate the distance with respect to the central axis. Frequently, due to the nature of the manufacturing processes and the tool wear, the tool tip is not aligned to the central axis. Therefore, a correction of the distance estimation needs to be considered in order to produce reliable measures. Pérez et al. [20] used cutting forces to estimate the tip localization. Xuewei et al. [21] made use of the tool deflections to correct the tip path, whereas Singh and Dvivedi [22], and Yu et al. [23] used machine vision techniques with the same purpose.
To locate the tool tip on the 6DOF device, different technologies were analyzed, each varying in accuracy and costs. Given the dimensional restrictions of the device, and the required budget, the system must be compact, modular and low cost. With this in mind, a vision system implemented in a Personal Computer (PC) was preferred [24]. The flexibility, low costs and expandability are desired characteristics of such systems to obtain the pursued results.

Description of the 6DOF Single-Edge Machining Device
For the proposed single-edge cutting process, it is crucial to obtain a user-friendly system with high precision. For this, a 6DOF device was designed and developed, able to fully position a single-edged tool in translations and rotations [25], Figure 2 illustrates the configuration of the 6DOF hybrid single-edge cutting device. A parallel mechanism constituted of three parallel-revolute-spherical configuration (3PRS) is used to position the tool head in the desired orientation and with a XY-Stage compensates for the parasitic movements of the tool, a C axis rotates the tool on its longitudinal axis to maintain the orientation of the cutting edge at the same time as maximizing the working space. Then, the axes controlled by the CNC Fagor 8070© are Z1, Z2, Z3, X, Y, C. The machine tool has a force measuring system in the 3PRS tool head made up of 4 KISTLER triaxial sensors and in the XY-Stage a KISTLER 9256C1 dynamometer. All these elements in conjunction with a stereo vision system monitor the cutting process. The information obtained from the vision system is crucial to make the proper corrections on the CNC code.

Description of the 6DOF Single-Edge Machining Device
For the proposed single-edge cutting process, it is crucial to obtain a user-friendly system with high precision. For this, a 6DOF device was designed and developed, able to fully position a single-edged tool in translations and rotations [25], Figure 2 illustrates the configuration of the 6DOF hybrid single-edge cutting device. A parallel mechanism constituted of three parallel-revolute-spherical configuration (3PRS) is used to position the tool head in the desired orientation and with a XY-Stage compensates for the parasitic movements of the tool, a C axis rotates the tool on its longitudinal axis to maintain the orientation of the cutting edge at the same time as maximizing the working space . Then, the axes controlled by the CNC Fagor 8070© are  ,  , , , , . The machine tool has a force measuring system in the 3PRS tool head made up of 4 KISTLER triaxial sensors and in the XY-Stage a KISTLER 9256C1 dynamometer. All these elements in conjunction with a stereo vision system monitor the cutting process. The information obtained from the vision system is crucial to make the proper corrections on the CNC code.

Inverse Kinematics of the 6DOF Machine Tool
To analyze the inverse kinematics of the 6DOF machine tool three different frames are defined. One on the base , other in the XY-Stage and finally, in the cutting tool tip end as is shown in Figure 3. The goal of these calculations is to define the position of the tool-tip = at every time during the machining process ( Figure 1).

Inverse Kinematics of the 6DOF Machine Tool
To analyze the inverse kinematics of the 6DOF machine tool three different frames are defined. One on the base R b x 1 y 1 z 1 , other in the XY-Stage R w x 2 y 2 z 2 and finally, in the cutting tool tip end R ct x 3 y 3 z 3 as is shown in Figure 3. The goal of these calculations is to define the position of the tool-tip P = P x P y P z α β γ T at every time during the machining process ( Figure 1).

Description of the 6DOF Single-Edge Machining Device
For the proposed single-edge cutting process, it is crucial to obtain a user-friendly system with high precision. For this, a 6DOF device was designed and developed, able to fully position a single-edged tool in translations and rotations [25], Figure 2 illustrates the configuration of the 6DOF hybrid single-edge cutting device. A parallel mechanism constituted of three parallel-revolute-spherical configuration (3PRS) is used to position the tool head in the desired orientation and with a XY-Stage compensates for the parasitic movements of the tool, a C axis rotates the tool on its longitudinal axis to maintain the orientation of the cutting edge at the same time as maximizing the working space . Then, the axes controlled by the CNC Fagor 8070© are  ,  , , , , . The machine tool has a force measuring system in the 3PRS tool head made up of 4 KISTLER triaxial sensors and in the XY-Stage a KISTLER 9256C1 dynamometer. All these elements in conjunction with a stereo vision system monitor the cutting process. The information obtained from the vision system is crucial to make the proper corrections on the CNC code.

Inverse Kinematics of the 6DOF Machine Tool
To analyze the inverse kinematics of the 6DOF machine tool three different frames are defined. One on the base , other in the XY-Stage and finally, in the cutting tool tip end as is shown in Figure 3. The goal of these calculations is to define the position of the tool-tip = at every time during the machining process ( Figure 1).  Since the mechanism has two main devices, a parallel mechanism and a XY-Stage, it is necessary to relate their movements using a rotation matrix, R = R z 1 x 1 y 1 = R y 1 (β) R x 1 (α) R z 1 (γ) [26]. The XY-Stage is a serial mechanism, then its movement is directly related to the actuation in X and Y axes. On the other hand, the parallel mechanism does not actuate directly over their 3DOF. The actuation is performed on the Z1, Z2 and Z3 axes ( Figure 4) and results in two rotations and one translation [27]. Finally, the C axis must rotate to positioning the cutting tool tip in the trajectory and to compensate the rotational parasitic motion of the 3PRS mechanism. All computations are realized relative to the fixed frame in the granite base. Since the mechanism has two main devices, a parallel mechanism and a XY-Stage, it is necessary to relate their movements using a rotation matrix, = = [26]. The XY-Stage is a serial mechanism, then its movement is directly related to the actuation in and axes. On the other hand, the parallel mechanism does not actuate directly over their 3DOF. The actuation is performed on the , and axes ( Figure 4) and results in two rotations and one translation [27]. Finally, the axis must rotate to positioning the cutting tool tip in the trajectory and to compensate the rotational parasitic motion of the 3PRS mechanism. All computations are realized relative to the fixed frame in the granite base. The Euler angles and are the rotational DOFs that relates the frame to in the axes x and y. These movements induce a rotational parasitic motion γ in z axis which is defined by Equation (1) and two additional parasitic motions in x (Equations (2)) and y (Equation (3)), corresponding to the translation of the tool tip position [28]. Where, * and * correspond to the * and * . The , and actuations to the input positions , and of the cutting path are expressed by Equation (4) [29]: The Euler angles α and β are the rotational DOFs that relates the frame R ct to R b in the axes x and y. These movements induce a rotational parasitic motion γ b in z axis which is defined by Equation (1) and two additional parasitic motions in x (Equations (2)) and y (Equation (3)), corresponding to the translation of the tool tip position o 3 [28]. Where, c( * ) and s( * ) correspond to the cos( * ) and sin( * ). The Z1, Z2 and Z3 actuations to the input positions α, β and P z of the P cutting path are expressed by Equation (4) [29]: where S i = S i x S i y S i z and R i = R i x R i y R i z are the positions vectors of the spherical and rotational joints respectively in the general reference frame R b . The geometrical parameters to the device are shown in Table 1. The rotation of the C axis considering the rotational parasitic motion γ b and the positioning of the cutting tool to the angle γ is obtained from Equation (5). Thus, the movements of the driven axes of the machine tool X and Y considering the translational parasitic motion and the positioning of the cutting tool in P x and P y are obtained by Equations (6) and (7). Z1, Z2, Z3 and C are expressed by Equations (4) and (5).
To define the actual position of the cutting edge, it is necessary to measure the deviation of the tool tip in the R ct frame relative to the z 3 axis. The measured values that allows to correct the tool-tip position are ∆ x , ∆ y and ∆θ which correspond with the offset in x 3 , y 3 and the angular position around z 3 respectively.
Thus, the machine tool has the following mechanical specifications: Each linear axis, X, Y, Z1, Z2 and Z3 has a maximum feed of 10.000 mm/min and the C axis has maximum velocity of 120 rpm. The maximum reachable Euler angles of the tool head α and β are ±30 • , the travels of the X and Y axis are 100 mm and for Z1, Z2 and Z3 are 190 mm. The stiffness of the device has an anisotropic behaviour because given the nature of the parallel mechanism, the minimum stiffnesses are 1.1 × 10 4 N/mm for X and Y axis and 6.2 × 10 4 N/mm. The maximum stiffnesses are 1.41 × 10 4 N/mm for X and Y axis and 6.7 × 10 4 N/mm. The maximum workpiece size depends of the cutting tool length with an average workpiece size of 80 × 80 × 100 mm, within this space it is possible to fully reach the full potential of the orientation and positioning of the tool. The mode shapes of the parallel mechanism are 15 between 16 and 61 Hz [30] that characterizes the main vertical, horizontal and rotational motions.
A set of preliminary tests were performed in order to evaluate the precision of the machine. The device, made of parts, worked correctly. Very different geometries were obtained, and the integration of the ISO code in CAD/CAM environments by means of the FAGOR CNC controller alleviated the translation of the CAD drawings into machining paths. Figure 5 presents some examples of the machined pieces after performing preliminary geometric tests. where = and = are the positions vectors of the spherical and rotational joints respectively in the general reference frame . The geometrical parameters to the device are shown in Table 1. The rotation of the axis considering the rotational parasitic motion and the positioning of the cutting tool to the angle is obtained from Equation (5). Thus, the movements of the driven axes of the machine tool and considering the translational parasitic motion and the positioning of the cutting tool in and are obtained by Equations (6) and (7). , , and are expressed by Equations (4) and (5).
To define the actual position of the cutting edge, it is necessary to measure the deviation of the tool tip in the frame relative to the axis. The measured values that allows to correct the tool-tip position are , and which correspond with the offset in , and the angular position around respectively. Thus, the machine tool has the following mechanical specifications: Each linear axis, , , , and has a maximum feed of 10.000 mm/min and the C axis has maximum velocity of 120 rpm. The maximum reachable Euler angles of the tool head and are 30°, the travels of the and axis are 100 mm and for , and are 190 mm. The stiffness of the device has an anisotropic behaviour because given the nature of the parallel mechanism, the minimum stiffnesses are 1.1 10 N/mm for and axis and 6.2 10 N/mm. The maximum stiffnesses are 1.41 10 N/mm for and axis and 6.7 10 N/mm. The maximum workpiece size depends of the cutting tool length with an average workpiece size of 80 80 100 mm, within this space it is possible to fully reach the full potential of the orientation and positioning of the tool. The mode shapes of the parallel mechanism are 15 between 16 and 61 Hz [30] that characterizes the main vertical, horizontal and rotational motions.
A set of preliminary tests were performed in order to evaluate the precision of the machine. The device, made of parts, worked correctly. Very different geometries were obtained, and the integration of the ISO code in CAD/CAM environments by means of the FAGOR CNC controller alleviated the translation of the CAD drawings into machining paths. Figure 5 presents some examples of the machined pieces after performing preliminary geometric tests.

Materials
The hardware for the stereo vision system was selected based on the principles of such configurations [31]. A stereo camera configuration was chosen as an array of two DinoLite AM7515MZT cameras with an optical zoom of 273×, a resolution of 5 Megapixels and a 1.3 ratio. The lenses of these cameras were designed for measuring purposes and are able to obtain clear un-deformed images. DinoCapture is software that comes with the cameras and is able to measure geometries in images after a manual procedure. Our own vision system was designed by means of the vision toolbox of Matlab. The dimensions of the device allow configuring a diverse range of arrangements of the cameras depending on the geometries that need to be machined and the accessories used. The cameras need to be placed in a perpendicular position, one in the plane XZ and the other in the plane YZ. Figure 6 illustrates the designed CAD vision system and the real vision system that was implemented on the device. As a highlight, the design of the vision system is modular, which allows making different arrangements of the elements in the device. Integrated LEDs are provided with the cameras, which are used for illumination purposes. Nevertheless, if the conditions of the machining or the materials of the pieces need a different illumination, other light sources can be added to the device due to its modularity.

Materials
The hardware for the stereo vision system was selected based on the principles of such configurations [31]. A stereo camera configuration was chosen as an array of two DinoLite AM7515MZT cameras with an optical zoom of 273×, a resolution of 5 Megapixels and a 1.3 ratio. The lenses of these cameras were designed for measuring purposes and are able to obtain clear un-deformed images. DinoCapture is software that comes with the cameras and is able to measure geometries in images after a manual procedure. Our own vision system was designed by means of the vision toolbox of Matlab. The dimensions of the device allow configuring a diverse range of arrangements of the cameras depending on the geometries that need to be machined and the accessories used. The cameras need to be placed in a perpendicular position, one in the plane XZ and the other in the plane YZ. Figure 6 illustrates the designed CAD vision system and the real vision system that was implemented on the device. As a highlight, the design of the vision system is modular, which allows making different arrangements of the elements in the device. Integrated LEDs are provided with the cameras, which are used for illumination purposes. Nevertheless, if the conditions of the machining or the materials of the pieces need a different illumination, other light sources can be added to the device due to its modularity.

Schema of the Stereo Vision System
The stereo vision system was mounted on the device as an accessory, it is integrated on the 6DOF tool head and can be removed or expanded depending on the process. The image processing and the computations of the vision system for tool tip localization and path correction were calculated using Matlab on a PC. Once the computations are made, the information is sent to the FAGOR 8070 CNC controller, and with the delta obtained from the offset of the tool tip, a correction is calculated and applied to the tool path. This process is repeated so the stereo vision system is able to track the tool tip, then the bed can be moved away. Figure 7 shows an illustration about the image capturing of the tool tip, get the position of the tool tip, compute the error and correct it and displace the tool properly. Figure 8 shows the general flow diagram of the stereo vision system, which consists of 4 basic stages, program Inputs, image treatment, tool edge and tip localization, and calculations. The program inputs stage consists on gathering data such as the tool diameter and the images captured by the cameras. The image treatment stage transforms the captured images to graphic processing unit (GPU) arrays to take advantage of the 3D acceleration card of the PC, then the images histogram is normalized and turned into gray scale images, a Gaussian filter is applied and then turned into negative images (color inverted), isolated pixels are filled, and the images are turned into binary arrays. On the tool edge and tip localization stage the algorithm scans both sides of the tool to find its edges (using a technique based on canny edge detection), a calculation is made to draw and extend the central axis of the tool, with this data the algorithm scans for a convergence on the tool tip, the obtained coordinates are stored. The final calculation stage consists of the use of

Schema of the Stereo Vision System
The stereo vision system was mounted on the device as an accessory, it is integrated on the 6DOF tool head and can be removed or expanded depending on the process. The image processing and the computations of the vision system for tool tip localization and path correction were calculated using Matlab on a PC. Once the computations are made, the information is sent to the FAGOR 8070 CNC controller, and with the delta obtained from the offset of the tool tip, a correction is calculated and applied to the tool path. This process is repeated so the stereo vision system is able to track the tool tip, then the bed can be moved away. Figure 7 shows an illustration about the image capturing of the tool tip, get the position of the tool tip, compute the error and correct it and displace the tool properly. Figure 8 shows the general flow diagram of the stereo vision system, which consists of 4 basic stages, program Inputs, image treatment, tool edge and tip localization, and calculations. The program inputs stage consists on gathering data such as the tool diameter and the images captured by the cameras. The image treatment stage transforms the captured images to graphic processing unit (GPU) arrays to take advantage of the 3D acceleration card of the PC, then the images histogram is normalized and turned into gray scale images, a Gaussian filter is applied and then turned into negative images (color inverted), isolated pixels are filled, and the images are turned into binary arrays. On the tool edge and tip localization stage the algorithm scans both sides of the tool to find its edges (using a technique based on canny edge detection), a calculation is made to draw and extend the central axis of the tool, with this data the algorithm scans for a convergence on the tool tip, the obtained coordinates are stored. The final calculation stage consists of the use of the data obtained in previous stages to calculate the relation of millimeters per pixel and by orthogonal projection of the coordinates of the tool tip the distance of the tool tip relative to the axis of tool is obtained, then the data is presented on the PC monitor overlayered on the original images obtained by the cameras. the data obtained in previous stages to calculate the relation of millimeters per pixel and by orthogonal projection of the coordinates of the tool tip the distance of the tool tip relative to the axis of tool is obtained, then the data is presented on the PC monitor overlayered on the original images obtained by the cameras.

Image Acquisition
The acquired color pictures were captured at a resolution of 1280 × 960 pixels, following a dual camera arrangement based on stereo vision systems [32]. A schematic of the estimation of the tool tip using the stereo vision system is shown in Figure 9. Such systems are very practical for precisely finding the location of a point in a three-dimensional space using a triangulation calculation, after an appropriate calibration of the cameras, which is critical [33]. The location of the tool tip was computed in this way. The diameter and axis of the tool were considered as reference point for both cameras. This affects directly the accuracy of the vision system. the data obtained in previous stages to calculate the relation of millimeters per pixel and by orthogonal projection of the coordinates of the tool tip the distance of the tool tip relative to the axis of tool is obtained, then the data is presented on the PC monitor overlayered on the original images obtained by the cameras.

Image Acquisition
The acquired color pictures were captured at a resolution of 1280 × 960 pixels, following a dual camera arrangement based on stereo vision systems [32]. A schematic of the estimation of the tool tip using the stereo vision system is shown in Figure 9. Such systems are very practical for precisely finding the location of a point in a three-dimensional space using a triangulation calculation, after an appropriate calibration of the cameras, which is critical [33]. The location of the tool tip was computed in this way. The diameter and axis of the tool were considered as reference point for both cameras. This affects directly the accuracy of the vision system.

Image Acquisition
The acquired color pictures were captured at a resolution of 1280 × 960 pixels, following a dual camera arrangement based on stereo vision systems [32]. A schematic of the estimation of the tool tip using the stereo vision system is shown in Figure 9. Such systems are very practical for precisely finding the location of a point in a three-dimensional space using a triangulation calculation, after an appropriate calibration of the cameras, which is critical [33]. The location of the tool tip was computed in this way. The diameter and axis of the tool were considered as reference point for both cameras. This affects directly the accuracy of the vision system.

Tool Localization
Both cameras take an image of the tool on the planes XZ and YX (which represents the and of the machine), the images must be properly processed to obtain the information that is required. An intelligent processing of the visual information based on vision sensors system is applied. Matlab image processing toolbox was chosen due to the variety of image processing methods implemented and the flexibility of its programming language when creating new algorithms [34]. The selection of these techniques will have a great impact on the accuracy of the obtained dimensions [35]. The images are preprocessed by first converting them into grayscale and then normalizing them to stretch the contrast of the images. This reduces the errors that can be produced by the light source (in this case the integrated LEDs of the DinoLite cameras), which have a direct effect on the segmentation of the image. A poor segmentation will result in a bad identification of the object, that is, the cutting tool. Finally, the image is color inverted, black to white and vice versa.
Then, the inverse image is thresholded [36] and converted into a binary image in which a logical one indicates a pixel that belongs to the tool whereas a logical zero indicates otherwise. The tool body is metallic and cylindrical, which can cause reflections on the tool surface. This issue may lead to defaults in the binarizing process, and thus, on the tool tip localization. In this case, isolated black pixels that actually belonged to the tool were found. Gaussian filters and filling tools were used to alleviate this undesired effect. Even though the reflections vary from images and poses, the conceived algorithm became robust against reflections.

Alignment of the Tool with Respect to the Cameras
Once the tool is located, the next step is to localize the central axis of the tool body. The two long edges of the tool body are found and defined with two segments or vectors. Then, the parallel vector placed in the middle position of the two is geometrically interpolated. Extra guide lines are calculated to ease the alignment of the camera in relation to the pose of the tool body, as shown in Figure 10. Special mechanical supports were designed so the guide lines are also aligned to the device, and with this, two Regions of Interest (ROI) are defined [37], the tool body and the tool tip.
The two edges of the tool body and the real dimension in millimeters of the tool diameter are used to estimate the pixels per millimeter ratio. The parallel mid-segment is lengthened to a straight line to better visualize the central axis of the tool body. The tool tip localization will focus on the area surrounding the automatically located mid-line of the tool body.

Tool Localization
Both cameras take an image of the tool on the planes XZ and YX (which represents the x 3 z 3 and y 3 z 3 of the machine), the images must be properly processed to obtain the information that is required. An intelligent processing of the visual information based on vision sensors system is applied. Matlab image processing toolbox was chosen due to the variety of image processing methods implemented and the flexibility of its programming language when creating new algorithms [34]. The selection of these techniques will have a great impact on the accuracy of the obtained dimensions [35]. The images are preprocessed by first converting them into grayscale and then normalizing them to stretch the contrast of the images. This reduces the errors that can be produced by the light source (in this case the integrated LEDs of the DinoLite cameras), which have a direct effect on the segmentation of the image. A poor segmentation will result in a bad identification of the object, that is, the cutting tool. Finally, the image is color inverted, black to white and vice versa.
Then, the inverse image is thresholded [36] and converted into a binary image in which a logical one indicates a pixel that belongs to the tool whereas a logical zero indicates otherwise. The tool body is metallic and cylindrical, which can cause reflections on the tool surface. This issue may lead to defaults in the binarizing process, and thus, on the tool tip localization. In this case, isolated black pixels that actually belonged to the tool were found. Gaussian filters and filling tools were used to alleviate this undesired effect. Even though the reflections vary from images and poses, the conceived algorithm became robust against reflections.

Alignment of the Tool with Respect to the Cameras
Once the tool is located, the next step is to localize the central axis of the tool body. The two long edges of the tool body are found and defined with two segments or vectors. Then, the parallel vector placed in the middle position of the two is geometrically interpolated. Extra guide lines are calculated to ease the alignment of the camera in relation to the pose of the tool body, as shown in Figure 10. Special mechanical supports were designed so the guide lines are also aligned to the device, and with this, two Regions of Interest (ROI) are defined [37], the tool body and the tool tip.
The two edges of the tool body and the real dimension in millimeters of the tool diameter are used to estimate the pixels per millimeter ratio. The parallel mid-segment is lengthened to a straight line to better visualize the central axis of the tool body. The tool tip localization will focus on the area surrounding the automatically located mid-line of the tool body.

Tool Tip Localization
The first step of the tool tip localization consists of acquiring the tool diameter as an input variable. The algorithm is designed to find the tool body. Again, as the device only admits cylindrical tool body shapes, this will be the reference point for the subsequent calculations.
Once the tool body is identified, the next step is the localization of the tool tip. The tool tip can be considered as a corner in image processing. Harris and Stephens [38] algorithm was used to find the tool tip. This method combines corner and edge detectors based on the local auto-correlation function, and it is applied to the binary image. Figure 11 shows different snapshots of different stages of the image processing and tool tip localization. Once the tool tip is located, the coordinates of the tool tip position are kept in two different variables, one for each camera. These coordinates on the image are measured in pixels. Then, the coordinates of the tool tip are projected on the reference mid-line. Therefore, the distance between the tool tip and the central axis of the tool body can be measured in pixels. Finally, the pixel measurements are transformed into millimeters using the previously obtained ratio.

Tool Tip Localization
The first step of the tool tip localization consists of acquiring the tool diameter as an input variable. The algorithm is designed to find the tool body. Again, as the device only admits cylindrical tool body shapes, this will be the reference point for the subsequent calculations.
Once the tool body is identified, the next step is the localization of the tool tip. The tool tip can be considered as a corner in image processing. Harris and Stephens [38] algorithm was used to find the tool tip. This method combines corner and edge detectors based on the local auto-correlation function, and it is applied to the binary image. Figure 11 shows different snapshots of different stages of the image processing and tool tip localization.

Tool Tip Localization
The first step of the tool tip localization consists of acquiring the tool diameter as an input variable. The algorithm is designed to find the tool body. Again, as the device only admits cylindrical tool body shapes, this will be the reference point for the subsequent calculations.
Once the tool body is identified, the next step is the localization of the tool tip. The tool tip can be considered as a corner in image processing. Harris and Stephens [38] algorithm was used to find the tool tip. This method combines corner and edge detectors based on the local auto-correlation function, and it is applied to the binary image. Figure 11 shows different snapshots of different stages of the image processing and tool tip localization. Once the tool tip is located, the coordinates of the tool tip position are kept in two different variables, one for each camera. These coordinates on the image are measured in pixels. Then, the coordinates of the tool tip are projected on the reference mid-line. Therefore, the distance between the tool tip and the central axis of the tool body can be measured in pixels. Finally, the pixel measurements are transformed into millimeters using the previously obtained ratio. Once the tool tip is located, the coordinates of the tool tip position are kept in two different variables, one for each camera. These coordinates on the image are measured in pixels. Then, the coordinates of the tool tip are projected on the reference mid-line. Therefore, the distance between the tool tip and the central axis of the tool body can be measured in pixels. Finally, the pixel measurements are transformed into millimeters using the previously obtained ratio.

Path Correction
By default, the configuration of the machine tool considers as initial position of the tool tip on the origin of a coordinate system R ct . However, given the variety of the single edge tool geometries, the real position of the tool tip is not aligned to this reference frame, as shown in Figure 12, and can vary significantly.

Path Correction
By default, the configuration of the machine tool considers as initial position of the tool tip on the origin of a coordinate system . However, given the variety of the single edge tool geometries, the real position of the tool tip is not aligned to this reference frame, as shown in Figure 12, and can vary significantly. To make the proper corrections on each of the axis of the device it is necessary to measure the relative deviation to the tool planes in an initial position on the axis. These values are determined as , and , Equation (8), and are represented in Figure 13. To keep the cutting edge tangent to the trajectory during the cutting process, it is necessary to correct the displacements generated by the movement of the tool tip when the axis rotates according to Equations (11) and (12). These displacements correspond to the movements of a circle of radius , the real position of the cutting edge , where is the sum of the angular parasitic motion of the 3PRS mechanism and the actuation of the axis, Equation (9).  Applying the rotation matrix = = a relation between the orientation of the tool and the general coordinate reference system is obtained [39], and with it the values of the correction on the work planes of the device , Equation (13). To make the proper corrections on each of the axis of the device it is necessary to measure the relative deviation to the tool planes R ct in an initial position on the C axis. These values are determined as ∆ x , ∆ y and ∆θ, Equation (8), and are represented in Figure 13. To keep the cutting edge tangent to the trajectory P during the cutting process, it is necessary to correct the displacements generated by the movement of the tool tip when the C axis rotates according to Equations (11) and (12). These displacements correspond to the movements of a circle of radius r ∆ , the real position of the cutting edge φ, where γ is the sum of the angular parasitic motion of the 3PRS mechanism and the actuation of the C axis, Equation (9).

Path Correction
By default, the configuration of the machine tool considers as initial position of the tool tip on the origin of a coordinate system . However, given the variety of the single edge tool geometries, the real position of the tool tip is not aligned to this reference frame, as shown in Figure 12, and can vary significantly. To make the proper corrections on each of the axis of the device it is necessary to measure the relative deviation to the tool planes in an initial position on the axis. These values are determined as , and , Equation (8), and are represented in Figure 13. To keep the cutting edge tangent to the trajectory during the cutting process, it is necessary to correct the displacements generated by the movement of the tool tip when the axis rotates according to Equations (11) and (12). These displacements correspond to the movements of a circle of radius , the real position of the cutting edge , where is the sum of the angular parasitic motion of the 3PRS mechanism and the actuation of the axis, Equation (9).  Applying the rotation matrix = = a relation between the orientation of the tool and the general coordinate reference system is obtained [39], and with it the values of the correction on the work planes of the device , Equation (13). Applying the rotation matrix R = R z 1 x 1 y 1 = R y 1 (β) R x 1 (α) R z 1 (γ) a relation between the orientation of the tool and the general coordinate reference system is obtained [39], and with it the values of the correction on the work planes of the device x 1 y 1 z 1 , Equation (13). (13) As a final step, the obtained values act as a correction of the theoretical values from the programmed toolpath for each of the axis of the device [28] with Equations (14)- (16). Where X, Y and Zi are the actuations when ∆ x and ∆ y are 0 mm from Equations (4), (6) and (7).

Results
In this section, the validation of the vision system performance and its efficiency is presented. For this, the results yielded with the proposed system are related with two different measuring systems: TESA V-200GL and DinoCapture.
TESA V-200GL is a dedicated metrological microscope system. This system provides the coordinates with respect to the central axis of the tool body. The displacement in x axis relative to the measuring system indicates the distance to the tool tip, YZ = 3.016 mm and XZ = 0.017 mm. These measurements are the base line to compare the capabilities of the vision system.
Forty-five images per tool plane, YZ and XZ which represent in the machine the y 3 z 3 and x 3 z 3 planes, were taken. The proposed method was used to automatically obtain the tool tip measures with respect to the central axis of the tool body. The same measurement was obtained with DinoCapture, the software included with the cameras. Two examples of such comparisons are shown in Figure 14.
As a final step, the obtained values act as a correction of the theoretical values from the programmed toolpath for each of the axis of the device [28] with Equations (14)- (16). Where , and are the actuations when and are 0 mm from Equations (4), (6) and (7).

Results
In this section, the validation of the vision system performance and its efficiency is presented. For this, the results yielded with the proposed system are related with two different measuring systems: TESA V-200GL and DinoCapture.
TESA V-200GL is a dedicated metrological microscope system. This system provides the coordinates with respect to the central axis of the tool body. The displacement in x axis relative to the measuring system indicates the distance to the tool tip, YZ = 3.016 mm and XZ = 0.017 mm. These measurements are the base line to compare the capabilities of the vision system.
Forty-five images per tool plane, YZ and XZ which represent in the machine the and planes, were taken. The proposed method was used to automatically obtain the tool tip measures with respect to the central axis of the tool body. The same measurement was obtained with DinoCapture, the software included with the cameras. Two examples of such comparisons are shown in Figure 14. The designed stereo vision system obtained = 3.0169 mm and = 0.0146 mm, while the DinoCapture software achieved = 3.013 mm and = 0.015 mm. Thus, both systems obtained similar results. Mind that the results achieved with the TESAV-200GL were considered as the base line. The differences between the base line measurement and the measurement from the vision system are gathered in Table 2. The errors yielded by the proposed stereo vision system are lower when the tool tip is located further away to the tool axis and , whereas the are significantly higher when it is placed close to the axis. Nevertheless, the accuracy of the proposed system is acceptable for any position of the tool tip. The designed stereo vision system obtained y 3 z 3 = 3.0169 mm and x 3 z 3 = 0.0146 mm, while the DinoCapture software achieved y 3 z 3 = 3.013 mm and x 3 z 3 = 0.015 mm. Thus, both systems obtained similar results. Mind that the results achieved with the TESAV-200GL were considered as the base line. The differences between the base line measurement and the measurement from the vision system are gathered in Table 2. The errors yielded by the proposed stereo vision system are lower when the tool tip is located further away to the tool axis y 3 z 3 and x 3 z 3 , whereas the are significantly higher when it is placed close to the x 3 z 3 axis. Nevertheless, the accuracy of the proposed system is acceptable for any position of the tool tip. Table 2. Distance errors (mm) for the acquired images, YZ camera (y 3 z 3 ) and XZ camera (x 3 z 3 ). The range of error for the proposed stereo vision system and the DinoCapture software was around ±3 µm. However, DinoCapture software has a great drawback with respect to the proposed system, it needs to be manually calibrated through point and click maneuvers, whereas the proposed system is fully automatic. Figure 15 shows box plots for the measurements of the images captured by the vision system, and it is noticeable that the results were achieved with high confidence rate. The error is produced by lighting conditions, in this case, the integrated camera LEDs (4000 lumens in the tool tip area).  The range of error for the proposed stereo vision system and the DinoCapture software was around ±3 µm. However, DinoCapture software has a great drawback with respect to the proposed system, it needs to be manually calibrated through point and click maneuvers, whereas the proposed system is fully automatic. Figure 15 shows box plots for the measurements of the images captured by the vision system, and it is noticeable that the results were achieved with high confidence rate. The error is produced by lighting conditions, in this case, the integrated camera LEDs (4000 lumens in the tool tip area). Since any deviation of the tool tip will give as a result a variation on forces and momentums on the tool head of the device, four triaxial sensors have been used on the tool head to make an indirect validation. A linear cutting path using the measured tool and a depth of cut of 0.04 mm is made. The forces and momentums of the process are obtained, as shown in Figure 16. Since any deviation of the tool tip will give as a result a variation on forces and momentums on the tool head of the device, four triaxial sensors have been used on the tool head to make an indirect validation. A linear cutting path using the measured tool and a depth of cut of 0.04 mm is made. The forces and momentums of the process are obtained, as shown in Figure 16. As it can be seen, this is a good indication of the reliability of the stereo vision system for tool tip localization and proves that the device correctly operates with reliable accuracy. To validate the tool path correction, two paths are programmed and tested in the CNC, as shown in Figure 17. The paths consist of a circle of different radius and a spline with two different radii, using both, the tool correction and without it. The obtained paths are measured and compared with the ones programmed.  This calculation is compared with the mean value obtained from the momentum sensors M = −0.3278 0.2241 0.0113 Nm. As it can be seen, this is a good indication of the reliability of the stereo vision system for tool tip localization and proves that the device correctly operates with reliable accuracy. To validate the tool path correction, two paths are programmed and tested in the CNC, as shown in Figure 17. The paths consist of a circle of different radius and a spline with two different radii, using both, the tool correction and without it. The obtained paths are measured and compared with the ones programmed. As it can be seen, this is a good indication of the reliability of the stereo vision system for tool tip localization and proves that the device correctly operates with reliable accuracy. To validate the tool path correction, two paths are programmed and tested in the CNC, as shown in Figure 17. The paths consist of a circle of different radius and a spline with two different radii, using both, the tool correction and without it. The obtained paths are measured and compared with the ones programmed.  The tool tip is obtained with the vision system, a ∆ x = 0.0188 mm and a ∆ y = 1.2361 mm are obtained. Using this data, a spline is programmed with an arch radius of 3 mm followed by a 2.5 mm radius arch, the path is machined on a test workpiece of Aluminium 7075-T6 and using a tungsten single-edge cutting tool in an orthogonal configuration. The path without correction ( Figure 18A) shows a clear deviation in the target measure of both arches. It can also be noticed a defect where the two arches link, this is due to the interpolation of the CNC to match the desired path. However, since the tip of the tool is not aligned with its central axis, the tool tip cuts along a non-desired place. The path with the correction enabled ( Figure 18B) has a high accuracy following the programmed path, and it does not have the defect observed on the path without correction. The programs for the cutting paths of Figure 18 are shown in Appendix A.1. The tool tip is obtained with the vision system, a Δ = 0.0188 mm and a Δ = 1.2361 mm are obtained. Using this data, a spline is programmed with an arch radius of 3 mm followed by a 2.5 mm radius arch, the path is machined on a test workpiece of Aluminium 7075-T6 and using a tungsten single-edge cutting tool in an orthogonal configuration. The path without correction ( Figure 18A) shows a clear deviation in the target measure of both arches. It can also be noticed a defect where the two arches link, this is due to the interpolation of the CNC to match the desired path. However, since the tip of the tool is not aligned with its central axis, the tool tip cuts along a non-desired place. The path with the correction enabled ( Figure 18B) has a high accuracy following the programmed path, and it does not have the defect observed on the path without correction. The programs for the cutting paths of Figure 18 are shown in Appendix A.1. The circular paths show a similar behavior, the error between the programmed path and the real one is notorious. In Figure 19, a circular path of 0.5 mm of radius is programmed, circle A uses the correction of the tool tip, circle B uses no correction. Whereas the programmed path is the same, overlaid with a blue dashed line in Figure 17, the error of positioning given the default point of reference of the axis of the tool creates an offset on dimensions and positioning. The programs for the cutting paths of Figure 19 are shown in Appendix A.2.  The circular paths show a similar behavior, the error between the programmed path and the real one is notorious. In Figure 19, a circular path of 0.5 mm of radius is programmed, circle A uses the correction of the tool tip, circle B uses no correction. Whereas the programmed path is the same, overlaid with a blue dashed line in Figure 17, the error of positioning given the default point of reference of the axis of the tool creates an offset on dimensions and positioning. The programs for the cutting paths of Figure 19 are shown in Appendix A.2. The tool tip is obtained with the vision system, a Δ = 0.0188 mm and a Δ = 1.2361 mm are obtained. Using this data, a spline is programmed with an arch radius of 3 mm followed by a 2.5 mm radius arch, the path is machined on a test workpiece of Aluminium 7075-T6 and using a tungsten single-edge cutting tool in an orthogonal configuration. The path without correction ( Figure 18A) shows a clear deviation in the target measure of both arches. It can also be noticed a defect where the two arches link, this is due to the interpolation of the CNC to match the desired path. However, since the tip of the tool is not aligned with its central axis, the tool tip cuts along a non-desired place. The path with the correction enabled ( Figure 18B) has a high accuracy following the programmed path, and it does not have the defect observed on the path without correction. The programs for the cutting paths of Figure 18 are shown in Appendix A.1. The circular paths show a similar behavior, the error between the programmed path and the real one is notorious. In Figure 19, a circular path of 0.5 mm of radius is programmed, circle A uses the correction of the tool tip, circle B uses no correction. Whereas the programmed path is the same, overlaid with a blue dashed line in Figure 17, the error of positioning given the default point of reference of the axis of the tool creates an offset on dimensions and positioning. The programs for the cutting paths of Figure 19 are shown in Appendix A.2.

Discussion
In this work, a stereo vision system was designed and programmed to precisely localize the tool tip and reliably estimate the path corrections for a 6DOF single point machining device. Experimental results proved that the proposed system fulfills the accuracy range of both standard software to measure geometries provided by market cameras, DinoCapture, and dedicated metrological microscope systems, TESA V-200GL. Vision systems based on artificial intelligence are becoming a crucial application to monitor, inspect and control machines and systems in the industry. Many applications benefit from machine vision systems, which recently became low-cost and provide fast computational capacities [40]. Vision systems in micro and meso machining processes faces a promising future, the creation of both sensors and lenses capable of delivering a clear undeformed image is essential to achieve precise and accurate measurements and results. In future works, other light sources will be evaluated; given the reflective nature of metals, the contour of the tool can be affected if the light conditions are inadequate [41].

Conclusions
The proposed stereo vision system is an effective strategy for the localization of the tool tip in the machining processes. The error was delimited in a range of ±3 µm, which is comparable to commercial software and dedicated metrological microscope systems but makes up a completely automatic solution. The integrated LEDs on the cameras were used as light sources to illuminate the metallic tool. Even though results were satisfactory, other light sources can be studied in future works. Also, in future works, reference images of the tool bodies can be taken and the calculation of measurements can be tested by means of a cascade algorithm. The implementation in a 6DOF single-edge cutting machine was a success, showing that the tool tip path correction is viable in such paths. The system can create accurate cutting paths, which leads to more reliable cutting geometries.