Zeroing CNC Mills With OpenCV

For [Jay] and [Ricardo]’s final project for [Dr. Bruce Land]’s ECE4760 course at Cornell, they tackled a problem that is the bane of all machinists. Their project finds the XY zero of a part in a CNC machine using computer vision, vastly reducing the time it take to set up a workpiece and giving us yet another reason to water down the phrase ‘Internet of Things’ by calling this the Internet of CNC Machines.

For the hardware, [Jay] and [Ricardo] used a PIC32 to interface with an Arducam module, a WiFi module, and an inductive sensor for measuring the distance to the workpiece. All of this was brought together on a PCB specifically designed to be single-sided (smart!), and tucked away in an enclosure that can be easily attached to the spindle of a CNC mill. This contraption looks down on a workpiece and uses OpenCV to find the center of a hole in a fixture. When the center is found, the mill is zeroed on its XY axis.

The software is a bit simpler than a device that has OpenCV processing running on a microcontroller. Detecting the center of the bore, for instance, happens on a laptop running a few Python scripts. The mill attachment communicates with the laptop over WiFi, and sends a few images of the downward-facing camera over to the laptop. From there, the laptop detects the center of the bore in the fixture plate and generates some G-code to send over to the mill.

While the device works remarkably well, and is able to center the mill fairly quickly and without a lot of user intervention, there were a few problems. The camera is not perfectly aligned with the axis of the spindle, making the math harder than it should be. Also, the enclosure isn’t rated for being an environment where coolant is sprayed everywhere. Those are small quibbles, and these problems could be fixed simply by designing and printing another enclosure. The device works, though, and really cuts down on the time it takes to zero out a mill.

You can check out the video description of the build below.

45 thoughts on “Zeroing CNC Mills With OpenCV

  1. Not going to replace a renishaw probe any time soon. And I can indicate a bore with a DTI with greater accuracy probably just as fast.

    This is kind of one of those solutions looking for a problem.

        1. I didn’t catch if that was inches or mm. .050 mm or 50 microns is very usable in the makerspace world. (0.002″ roughly) The big question is the update rate. The slower the rate the slower you have to go to get good resolution.
          50 microns is a typical target. 0.050″ is not super useful.
          I can’t help but think about the lander that smacked into Mars because of an inch/metric thing.

          1. There are lots of factors in using a camera to find the center or edges of objects. One simple trick is to simply rotate the spindle 90 degrees and take 4 pictures. That will allow you to find the center pixel. If it were me I would take do the prior step, and then move to the center location and test it again. This is basically calibrating the sensor geometry. Depending on the geometry of the piece and lots of other things, you can use this technique to position to 50 millionths of an inch or better (~1 micron) — or good enough for a mill/lathe with accuracy/percision in the 0.0001″ range. Yep. half a tenth. It is all simple geometry and photogrametry. If you have a suitable machine, then you can automate the calibration step programtically and find the center pixel each time. The advantage of that is that you do not have to worry about thermal expansion or someone smacking the camera throwing it into the tool chest and mucking up the calibration.

            One of the things I was thinking of doing with this to extend the idea is to take a couple of pictures moving in a box or triangle and use photogametry techniques to estimate the distance of the sensor to the camera to set the focal plane. Then the edges are in sharp focus. I like this idea. Unfortunately I am VERY busy with other things. If someone is in the DC area and want to play at MakerTech Tuesday on this, let me know.

    1. Indeed. A coaxial indicator is actually significantly faster. I can find center of a bore with a coaxial in about 20 seconds. You have to understand , these kids havent made in to the real world yet to find out that there are already solutions to this problem , and have been for some time. Just like a lot of these projects i see by young people , they just havent the experience/exposure to realize their efforts are somewhat pointless, as there is very often already a GOOD solution to the problem.

  2. What does this have to do with internet of things (or more accurately, internet of s**t) though? WiFi does not necessarily equal internet. The sooner everyone stops plugging IoT as being some kind of revolution, the better.
    But on the subject at hand, I have to agree with previous comments. While a nice notion, the accuracies they are quoting are frankly an insult to the machinery they are using.
    That’s not to say I wouldn’t like to see this improved, though. Machine vision is being used to set jigging to some pretty impressive tolerances in industrial applications.

    1. Hey look, another guy who doesn’t get it and thinks IoT = my toaster on the internet. If you haven’t seen the revolution already, you’re in the wrong industry. … Or actually not in industry in general. .. Or commercial … are you an insurance salesman?

      1. I’m an electronic engineer and I do understand what IoT is, it just irritates me how much crap is flooding onto the consumer market and all you see these days is garbage being touted as IoT devices. Yes, including things like toasters, refrigerators, lightbulbs, etc, for which an internet connection really offers no utility and is actually ridiculous.
        Since the advent of devices like the ESP8266, it’s now more like “Oh, look how cheap that is. I’ll buy some.” shortly followed by “Right, what shall I connect to the internet today?” rather than starting with a problem and recognising it might be solved by implementing an internet connected device.
        Obviously it has its place and I have no doubt that there are some IoT devices that are making a difference , but now marketing idiots have found out about “IoT” and “cloud” and want everything they advertise to be part of it.

        I’m not disputing that there are applications where data centralisation is of value or where remote monitoring is making a big difference in industry, but we’ve been doing that for years and didn’t feel the need to slap a snazzy IoT badge on it.

        Having said all of this, I do get a good laugh out of reading about people who have converted their homes to a “smart home” only to be unable to turn their lights on because a server somewhere is undergoing maintenance.

        Anyway, as for my original point, this is not an IoT device. It has a WiFi connection such that it can be controlled via a laptop over a LAN.

        My original post wasn’t to denigrate the project itself, more taking a pop at the way the author of the article couldn’t resist getting “Internet of Things” in there somewhere. I’d wager that the guys doing the project never even labelled it as such.

  3. We are working on something very similar for the Smoothie project ! Looking for OpenCV devs for hire btw :) Really glad to see more people are working on this. Ours uses a fisheye webcam in combination with either an XYZ probe, or a USB microscope.

    1. The way I was thinking, overhead camera to image the part and let the operator pick a hole location, then the machine uses a mechanical probe to find the hole center, part edge, etc. Just use the camera to get the machine close and find the real value with the probe.

    2. Is that .050 mil or inch? Has anyone thought of using thermal imagery? It may give a clearer picture for the PC. As far as adjusting for actual axis that should be given on each cnc. If the cameras are mounted in the cnc and that is measured prior to inserting in machine then zero for that tool should be easy to find. The above comments regarding accuracy are correct and not good enough for most applications but this is the start and I would assume it can only get better from here.

  4. Reading the text, I thought this thing found the centre of a solid or partly machined mass.
    Watching the vidio, twice, the point of the thing was lost on me, other than to point ot the difficulties in finding the centre of a hole if you never seen a milling machine before.
    050! 50 thou? The thickness of a hacksaw blade and a spark plug gap added together?
    Reading the comments my fears are confirmed…..tutor “go make something electronic the involves the internet and a 3Dprinter and hopefully has a use” student,….. “how about this, it has an inaccuracy of 050″ and fits a mill wih an accuracy 0001″ can we mak a video? ” tutor… ” yes and here’s a piece of paper that documents your waste of 3 months in college”
    Oh and how exactly is this a hack?
    Or did I miss something?

    1. what i find most frustrating about hackaday is the fact that for so many projects people assume no further progress will ever be made, sure this is useless as is, but if we are looking a few years down the line with cheap 8k cameras and it might become very useful.

      with inaccuracies above 1mm it is effectively useless, but if they down the line made something far more precise it could allow real time feedback and error correction, even collision avoidance and sanity checking becomes a lot easier.

      1. And while you will wait for your megabuck 8k camera with the matching image capture and processing hw to become available while costing as much or more than your milling machine, machinists will be happily doing this using cheap probes which are pretty much standard accessories for most mills since ages.

        This is a solution looking for a problem and throwing more money and more expensive equipment at it will *not* fix that.

        Also, as pointed out by others already, only an idiot that has never seen a milling machine to actually operate could put a camera in the workspace – cutting oil and sharp hot metal bits are typically flying everywhere. Your shiny new 8k camera would be ruined after few pieces. Even small toy mills cutting only wood and plastic produce enough aggressive dust to scratch the lenses. And a removable camera would not achieve the accuracy, making it pointless.

        1. First, you don’t need a 8k cam. A low cost webcam and a mechanism to switch between normal and microscope lens would do the trick here and be extremely cheap.

          Also, no the camera won’t receive any oil or metal : it’s an ATC, it’ll be safely in the tool magazine when not in use.

          Saying “machinists have been doing this for ages” is the same is the same as being in 1991 ( or whenever ) dissing email because it costs more to send than snailmail … you are completely missing the point.

          This has a lot of potential, and can be developed into something faster, and more useful, than classic centering tools/probes. For example on large format routers this can be used to autodetect where the part is in the work area. It can be used to detect fixtures. It can 3D scan parts. You could even go one step further and get the CAM software to use those results, displaying what’s in your work area while you are setting up CAM … That and other features could give you a *much* better user experience when using CNC mills … ( reducing the number of operations a user has to do, and making those left easier )

    2. Waste of 3 months? You mean other than going through the learning process of having a problem and solving a problem. What, all student projects now need to be super accurate and solve world hunger? Get a grip on yourself man.

        1. And you think that keeping those lasers and optics in alignment is easier? Or that it will never require a touch up? If you can’t use a probe, you shouldn’t have anything to do with a milling machine – doing a bit of basic vector math for the setup is part of basic skills that *every* machinist or CNC operator is taught.

          1. it is almost never what you should be able to do but what is worth doing, considering that when you work for someone in a machine shop the two most expensive resources is the time of both the machine and operator.

            saving time is money earned in that context, which is why all productive shops have several insert holders with the commonly used bits already installed instead of just a single holder with all the bits available, if this down the line saves a minute here and there it could very well be worth it.

  5. Holy crap… those whining about the accuracy miss the point of the exercise, which was for a class! This kids were learning, solving a problem, and moving on. This is not a project who’s goal is to give great accuracy, it’s a way for the kids to learn how to solve such a project down the line, or any project. Sheesh.

    1. That would be an acceptable argument for a high school project or someone doing just for fun. Not an university course at Cornell where the students are future engineers that will be solving real world problems somewhere in a factory few years down the line. One would expect that the objective is to not only solve the problem but to solve it in an actually usable and useful way – which typically requires learning how the task is normally done and *then* improving upon that solution. Which obviously didn’t happen here.

      1. Oh my god give me a break. What did you do for your engineering education that was so novel and useful? They don’t work on this one class full time. Frankly it’s very creative to come up with a solution that is at least somewhat useful in such a short period of time.

  6. I think this is a great project! Sure, it’s a prototype, but they can improve accuracy with better algorithms and scripts, and automate the process in the same way turning was automated. I want one right now!

  7. To all you worthless idiots out there complaining about a wasted college degree, solving your problems was not the point of this exercise. These projects are among the most valuable experiences you get in a degree, a practical problem you can sink your teeth into. OMG two college undergrads couldn’t fix something that the industry with it’s collective $billions haven’t fixed either. Shocking!

    I’m not one for the SJW type but these guys need defending so on behalf of undergrads everywhere, go screw yourself.

  8. One of the several interesting uses I can see for this, as an extension to finding bore centers, would be finding feature sets. Sure we can use our co-ax to find the center of a single round hole, but how about finding the center of a square, or something with keyways? On my circuit board mill, the software allows me to indicate in two holes on the board, and then it recalibrates the gcode around those two points, so I don’t have to precisely align the circuit board, just two holes. We usually leave the mill vise parallel to the ways, but with something like this we wouldn’t have to indicate the jaw to make sure it was still parallel: indicate in two holes, and the software does the interpolation. Likewise, one of the frustrating things for me is trying to find a good reference point on a rough casting. Well, this thing could find the centers of several rough holes and be ready to clean them up as my initial references. (and I personally loathe trying to determine bolt locations on non-rectilinear patterns, whereas this thing is ready to do that for me.)

  9. The problem as I see it with this device is that it assumes perpendicularity of the spindle axis to the top of the workpiece (and that the hole is perpendicular to the workpiece). When indicating in a hole, it is best to always take indicator readings at two different depths. This verifies that the hole is indeed parallel to the spindle axis, and not canted.

Leave a Reply to maconaCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.