Adding auto-leveling to CNC USB ControllerJune 10, 2018 Maker
In my previous post, I mentioned that my 3020 CNC allows my make circuit boards like the ones below, which requires accurate control over the cut depth. In this post, I’ll go deeper into how I achieved this level of control using some software I wrote.
Limits to leveling
As mentioned before, getting the cut depth just right when using V-shaped engraving bits is essential. Too shallow, and the traces won’t get isolated from each other. Too deep and you’ll quickly end up with dull bits and with torn or overly thin traces.
In its most basic form, the cut depth can stabilized from location to location by first milling a flat area into a waste board before the copper-clad circuit board is stuck onto it. This removes any major misalignments between the axes and the bed. However, the copper layer’s height may still vary too much for V-carving as the copper-clad board (or adhesion layer) may vary in thickness or may be curved.
Auto leveling is a process that tries to compensate for height differences instead of trying to prevent them. First, the CNC is used to probe the local height of the PCB in lots of places. Then, these probed heights are used to adjust any G-Code path such that they curve along with any detected imperfections.
Probing the height of a PCB locally is typically done by slowly lowering an end mill until an electric connection is made between the end mill and board’s copper layer. Getting this to work was easy for me as my CNC machine came with both the necessary hardware and software to do this. However, probing over a grid and then using this to distort G-Code to do auto-leveling was unsupported.
Obviously, I could’ve bought better electronics and software. But being a software developer, I had other options as well. In turns out that CNC USB Controller, which is the Windows control software my machine came with, can be controlled through command-line arguments as well as through a COM interface. This makes it possible to add support for auto-leveling using my own external applications.
Here’s an example of the resulting process:
At the beginning of this clip, I’m starting my command-line tool called cnc_warp_probe. The used command-line arguments tell it to probe an area of 40 x 40 mm using 4 x 4 measurements. In turn, this tool makes CNC USB Controller take the individual measurements at all the right locations, and stores the collected probe data into a text file. When it finished probing at all 16 different locations, I then copied the G-Code onto the clipboard and called code_warp_gcode_clipboard.bat. This feeds the probe text file and the G-Code on the clipboard into a second tool called cnc_warp_gcode. This second tool takes the probe text file, fits a quadratic surface through it, and uses it to vertically adjust the G-Code. The .bat file then puts the adjusted G-Code back onto the clipboard, after which I complete the procedure by pasting that into CNC USB Controller again.
These tools have been very useful for me, and I’ve made them open source so that anyone can use them freely. Please do understand that this is just a hobby project, so I do not offer any guarantees or support, nor do I accept any kind of liability. Links to the source code and the binaries are below. The code has been written in C/C++, so anyone comfortable in Visual Studio should be able to build and extend it in any way they want. Enjoy!
- Tool binaries [ZIP]. Last updated on Jun 16, 2018.
- Tool source code [Bitbucket]. Last updated on Jun 16, 2018.