Reverse Engineering and Read Mechanical Gauges with Machine Vision
kent@confluencerd.com
+1 (515) 864-1694
Find the dimensions (position and size) of each hole in a plate mounted in the vise of a milling machine.
Use a camera and machine vision to identity holes and drive LinuxCNC to probe each hole with a Haimer 3D Sensor. A second camera reads the mechanical gauge of the Haimer 3D Sensor, emulating an electronic probe. This setup could be used for reverse engineering a part or verifying machining operations. Software is written in Python, uses OpenCV, and is available on GitHub. A video demonstration is available.
It’s common to have a part without drawings that needs modifications, duplication, or to which a new part must be mounted. Measurements must be taken of the key features and the part recreated in CAD. Measurements can be done with hand tools, and symmetries in the part may make measurement quicker. Automation should make the process quicker and less error prone.
Automation hole dimensions is implemented with two cameras and software driving probing operations of a CNC milling machine. To test the method, holes with known dimensions are added to a plate and compared to the measurements.
A camera attached to the milling machine and stares at the plate along the z-axis. After the upper-left corner and top of the plate are touched off, camera alignment can be corrected, including rotation and squareness. The plate is assumed to be rectangular, and corners of the plate are selected in the image. The selected points are used to warp the image and correct image distortions related to camera alignment. After warping, the dimensions (width and height) of the plate are entered. The software then estimates position and diameter each hole on the plate.
Warping of the image to correct camera alignment is implemented with an affine transformation is meant to improve estimations of a reasonably mounted camera. While a surprising amount of misalignment can be tolerated, it’s recommended to make a reasonable attempt at squaring the camera. If the camera could be made perfect, not requiring the warping, this step could be eliminated. However, having warping step allows the camera to be quickly mounted and removed, attached to the milling machine head using magnets. Related to the warping, by entering the plate dimensions, there’s no need to know the height of the camera. Entering the plate dimensions, with the plate extents known, is enough to convert pixel dimensions into millimeters. Once the corners of the plate are selected, the image of the plate is locked, and no longer updated. Locking the image improves system responsiveness by not processing the video stream. During probing much of the plate will be obscured.
A reference could be used to estimate distances. To improve the estimate, the opposite sides of the plate could be probed. These steps could eliminate the need to enter the plate dimensions, and possibly eliminate the need to select the plate corners. Simple references could be gauge blocks, a couple circles with known diameters and center distance, or a ruler of known length.
A list of approximate position and size of each hole is now known. A probe can measure each hole, improving the accuracy of the estimates. A Haimer 3D Sensor probe is used to measure the position and diameter of each hole. A second camera is attached to the probe so the software can read the mechanical face. How this is done is described in an earlier article. The probe is otherwise used normally, with the probe mounted in the spindle of the mill. LinuxCNC is the controller and software, the LinuxCNC driver, sends commands to LinuxCNC to move the probe. The total traveling distance of the probe is minimized by solving the travel-salesperson problem. The currently optimal path is shown and updated as the probe moves. Before automating the probing operation, the path is locked to improve responsiveness.
From LinuxCNC, driver software can read machine coordinates, active coordinate system, and offsets of each coordinate system. The driver sends MDI commands to LinuxCNC with G-code. It’s convenient in the driver software to send G54 positions, and otherwise operate in machine coordinates. Measurements come from the difference in positions and movements are mostly incremental, so coordinate system selection is only for convenience.
The upper-left corner of the plate is the G54 origin. The software expects to lower the probe tip into any hole without the probe reading changing. Z-axis origin is the plate’s top and the probe tip is 4mm in diameter. So, the software expects to lower the probe tip to -2mm (half the probe tip diameter) without the probe reading changing. Holes that are too small to fit the probe into the hole safely should be filtered. Minimal hole diameter is proportional to probe tip diameter and expected error in the image analysis estimates. If an obstruction is encountered while entering a hole, a warning should be recorded and the hole filtered. While probing, dimensions of each hole are written to a CSV file, including estimated position and size, probed position and size (if possible), and warnings.
Hole probing is similar to how one would touch off to find the center of a hole manually. The steps are:
The probing operations could optimized by not requiring the Haimer 3D Sensor to read 0. As edges of the hole are probed more information is known about the hole. Initially, while the probe tip is moving, little is known about the hole or the edge being probed, other than “the edge is still somewhere over there.” Only when an edge is located is useful information available. However, it’s not necessary for the software to drive the probe until the probe face reads 0. Once a measurement is shown on the face, the remaining distance is known, and the probing operation could be aborted. The software currently probes until the probe reads 0 to emulate what a person might do to aid demonstration.
Measured hole diameter comes from probing along the Y-axis. The initial probing along the X-axis will most likely be smaller than the diameter because the estimate center is unlikely to be the actual center. Probing a second time along the X-axis might be useful for verifying the diameter. Probing additional points around the hole could be used to verify the roundness of the hole, related to the ability of the machining operation to create the hole.
An inefficient way to probe the hole would use 3d probing following a grid pattern. The density of probing must be high enough to capture all the holes. Once a hole is found, with the probe able to descend below the plate top, an operation similar to the one listed above could find the dimensions. This method would require less assistance from the operator and no overall information, such as what the camera provides, but will be slow.