CNC stands for "Computer Numerical Control". When you slap a "CNC" onto a set of motors, linear axes and a cutting tool (called a spindle), you get a CNC milling machine. CNC mills are useful because they allow you to machine parts with complex geometry at extremely high accuracy and speed. Check out this video for an incredible demonstration of a ridiculously expensive German built CNC machine manufacturing a demo part. Obviously my CNC will be orders of magnitude simpler than this one, as I don't have $3 million to spend.
At the college we had learned quite a bit of circuit theory. From DC to AC circuits, and some digital and programming as well. My understanding of how I could build the electronics to control a CNC machine was strong in its foundations, but I was clueless on the best way to go about starting. Thankfully google is a good friend, and it wasn't long before I discovered LinuxCNC. From forum posts to wiki articles, I was able to construct a basic block diagram of how a generic CNC machine works:
LinuxCNC does most of the dirty work. It understands the G-Code language that machining programs are written in, calculates the required control signals to move the axes into the correct XYZ positions, and sends these signals over a basic DB-25 parallel printer port. My job was to build a stepper motor driver circuit and make sure that all it needed was the inputs from the PC.
To get started I just googled "stepper motor driver". Little did I know at the time engineers design integrated circuits for just about bloody everything. The magnificent Texas Instruments DRV8825 caught my attention immediately. Here we have a single 28-pin chip that drives one bipolar stepper motor using no more than "step" and "direction" signals. It it literally the perfect solution. All my driver would need is three of these chips along with a voltage regulator to step down the motor supply (24V DC) to a logic level (5V DC) to power some signal buffers.
I will skip over all the headaches I went through in the design process as this was my first official, ground-up circuit design project. The following is the final circuit board (with a fancy heat sink that I ripped off an old PC motherboard):
The 3 motors connect on the left side of the circuit, power goes in to the top, a motor enable switch goes in the bottom and the DB-25 cable from the PC connects to the right.
This circuit was milled on an industrial CNC mill at work during some downtime, but later on I redesigned the board (with some upgrades like a DC-DC buck converter instead of an LDO) and sent the design out to a production company based in China named SeeedStudio. Their price was unbeatable (as expected) and their quality is well within tolerance. I send them the design, they send me back the unpopulated board. This is the final board in its working state:
(I will soon be adding a sidebar gadget that I will throw all my schematics in for anyone that is interested.)
So now I have a working stepper motor driver. Next up is to get the actual machine structure and spindle. Since this is essentially an electronics project, I decided to go with good ol' ebay.
I browsed auctions for a few weeks, and eventually found a really sweet deal. It had an aluminum construction, and my favourite part: ball screws. The best part was that the entire price of the aluminum and ball screws together was about the price of any other set of ball screws I could find. Here she is:
There are a few quirks and bad design decisions embedded in this thing, but for what its worth I don't mind. For example, the spindle hangs way off the front of the x-axis (left and right from picture view). When you put axial load on the spindle (z-axis), the machine experiences a lot of flex due to the spindle mount applying a high torque to the support rails (torque at a point is proportional to the force applied at the perpendicular distance from the point of interest). Another issue which coincides with the previous one, is the spindle is not aligned with the y-axis ball nut, so at maximum y-axis stroke the spindle either hangs off the end of the table, or doesn't make it all the way to the back. I could continue pointing out the mind-numbingly bad decisions here but I don't want to depress myself too much (I plan on redesigning and building the body using only the ball screws from this machine).
Along with the body I ordered a brushless DC spindle motor. The motor came with a drive but I ended up building a (slightly) faulty driver circuit that I ended up having to put off for more important things. Due to the complexity of the circuit, that's a topic for another day. This is the motor I purchased:
At this point the machine was fully functional. I was programming machining programs on my personal desktop and usb-keying the programs over to the Linux PC. Here are a few things I machined out of wood:
Actually the first thing I machined, a shell made out of hard maple:
How about a lizard?
An Elephant?
Now obviously these are all just for-fun projects. The cool stuff came when I started milling circuit boards to improve the functionality and convenience of the machine.
First off, I made a handwheel. Handwheels on CNC machines are used to manually move the axes for part setups. You may wonder, "Okay, I have a piece of wood on my CNC machine, now how does the machine know where it is?" Generally whenever you are setting up a workpiece, you want it to be square to an axis. So, you throw a dial indicator in the spindle and indicate a surface on the workpiece. If you have the same reading on the indicator on one side of the workpiece as you do the other, then the workpiece is aligned to that axis. After that you can manually tell the machine that it is at position X0.0 Y0.0 Z0.0, or "home". Handwheels make this very convenient. I can select the axis of motion, the speed of motion and turn a rotary encoder to index the axis in the direction of rotation. On my handwheel, I took some designs from the fancy machines I use at work to help make life easier. There is a "deadman" switch that has to be pressed in order for the machine to move, as well as a button that sets the current axis position to 0.0 for orientation. I will skip a lot of detail for the sake of brevity, but here is the circuit for the handwheel (which was milled on this CNC machine!):
You may wonder why the circuit has an odd shape, and that's because I also designed an enclosure for the circuit to sit in. Using the same techniques I use at work on the weekends, this is what I came up with:
There are 6 holes for the push buttons used for selecting the axis of movement and speed, the square hole is for the "homing" button that sets the position of the current axis to 0.0", there is a little wheel that will be friction coupled to the shaft of the rotary encoder and there is a mounting hole at the top right that you can use to hang the handwheel on something. I use a standard bolt driven into the side of my table. I ended up machining the handwheel out of a machinable plastic called Renboard which is commonly used for prototyping. The final product (again, milled on my machine):
On the left is the final product, hanging off my table, and on the right is a still from when I was machining the inside compartment where the circuit goes.
Next up on my list was an RPM sensor. This would be a simple circuit that would display the speed of the spindle motor on some 7-segment displays. The circuit works by using a counter that is triggered by the shaft of the motor passing by a hall-effect sensor. Every quarter second the count is taken, multiplied by 240 (0.25*4 = 1sec * 60 = 1min) and the result is displayed on the 5-digit 7 segment display I designed (the spindle ranges from 0-14000 RPM). Being so simple I was able to whip this circuit up in a couple hours on a breadboard. Within a week I had the working circuit:
For the last circuit, I wanted to make a "motherboard". This circuit would connect all the pieces together, act as a common ground point, add some GPIO, and some safety circuits like an E-stop and Power enable switches. Pretty simple design really. It didn't take that long to make, however for some reason I made it very large. I don't know why, I must have not been thinking too much that week. Anyways, here's an image of the circuit:
Actually I lied. The LAST circuit was a small LED module that I plugged into some of the GPIO I had made room for on the circuit (those 8 open holes on the south-side of the board). This module is basically just an LED driver I can use to indicate which power/e-stop states the machine is in. This is the circuit:
To finish the project off, I had to come up with some way of housing all the components. I decided on using some plain old MDF boards from home depot that I could machine into the desired shape on my CNC. This is an image of what all the components looked like prior to the housing:
Fans and cabled all over the place, two mains plugs, and a large footprint. The following is an early 3D model of the enclosure and the finished product:
I kinda messed up on the button labels, as the text got messed up in some spots, but overall I was pretty happy with it. It served the exact function I needed it to and posed no risk to the circuitry inside.
So there it is. A fairly brief walkthrough on my CNC project. If you're wondering how it was received by my fellow students and faculty, it was absolutely awesome. I presented my project on the last day of a 2 week presentation process and without fluffing my own feathers too much, it was a great way to end the presentations. I had unintentionally went like 20 minutes over time while still spewing information a break neck speeds just because there was so much detail in the project. I think my professors were enjoying it though so nobody said a word. A few nights before I had spent some time making a video showcasing the CNC in action. When I showed this video the entire class and faculty was in an uproar of laughter right from the beginning. Let's just say there are a few inside jokes in the video. The most obvious of which is the still image of a faculty member that pops up randomly. Oh the memories of that day. By far the presentation alone made every headache and late night worth it. Words really can't explain how much this project meant for me at the time and still does to this day.
Feel free to comment or ask me for details, schematics, layouts etc.
You spelled "vacuum" wrong. Hah; just kidding!
ReplyDeleteBrilliant work, Mr Sousanator. Looking forward to seeing much more.