First of all, I’d like to send my thanks to NIST, the EMC and EMC2 teams for an excellent platform!
EMC2 is a popular choice among hobbyists, academics and a growing group of professionals for CNC and robotic machine control. Most commonly it seems to be used to drive machines using stepper motors because of their low cost and simplicity. EMC2 drives servo motors equally well. While doing my research preparation for my own projects I found that there was a need for a simple tutorial laying out basic procedures for integrating servo control under EMC2. As always, the very best way to learn is to do so I ended up playing with a small servo “lab” so I could visit as many concepts and parameters as possible before applying them to a larger machine.
Machine integration is an important and unavoidable step along the way of building or converting to CNC operation. This is where planning, patience and practice come together and you start to see results as your machine comes to life for the first time. Sometimes spastically or even with spectacular violence! Hopefully you can avoid any real excitement and bring your machine into this world in a very sedate and controlled way. My goal here is to help you transition more gracefully from static metal/wood/plastic sculpture to a kinetic moving and useful addition to your life.
Servo motors, feedback, control and mechanics are huge topics each with their own sub disciplines and collections of textbooks. The idea here isn’t to educate you on every possible combination of configurations you may run in to, but to show you how you can set up and play with servo control under EMC2 for very little cost and do it safely.
Eventually you can move on to implementing it on a larger scale. I’m going to make certain assumptions about your level of knowledge ie. basic electronics knowledge, multi-meter use, passing familiarity with the EMC2 Live installation, etc.
Fair warning, I’m by no means an authority on EMC2 or servo control and have only limited experience with the actual tuning portion to do with servo drives, but the other pieces and concepts of machine integration are well known to me. None of this should be taken as gospel, it’s simply what my process is and I welcome any queries or feedback. My focus here will be on EMC2 and small servo drives but the steps and concepts can be applied to most servo control implementations.
The devices as described are low cost, and fairly lightweight so generally they should be pretty safe for anyone to work with. However care should still be exercised and this project treated just like a giant multi-ton machine. Get in the habit of being over-careful to the point of paranoia and stay there. It will help keep you safe as you progress to work with larger machines.
WARNING: Most automated machines CNC related or otherwise contain or can generate dangerous energies. These energies can be but may not be limited to mechanical, electrical, optical, thermal or acoustic in nature and appropriate care and precautions should be taken. Injury to operator(s) or bystanders may result as well as damage to the machine and its mechanisms. No machine should be operated with guarding removed or interlock mechanisms bypassed unnecessarily. If you are at all uncomfortable with this by all means seek a mentor who can supervise your activities or find something else to do with your time. You have been warned and I cannot be held responsible if anyone or anything is damaged. I am supplying this in good faith that anyone reading this will do their own research and pursue additional training/supervision as needed.
Peculiarities of Servo Drives – A little more challenging
Compared to stepper motors which don’t do much without explicit instructions, servo drives should be approached with a touch more respect because they inherently have the property of constantly correcting their position by themselves using a feedback loop. This means that they’re reacting to a feedback signal and if the drive and feedback signals aren’t working together in concert, ie. polarity is reversed on one of them, or a signal is operating intermittently, then the axis may behave unpredictably, erratically or run away violently. The product of this article should allow you to experiment and screw up with a forgiving mechanism that won’t break the bank if damaged, and shouldn’t cause injuries as long as you don’t play with them in the bath.
Managing Expectations – Some more challenges
One of the things I’ve found is that it appears that inkjet printer mechanisms are geared mostly around moving the print head quickly. This means that they may not perform as well at lower speeds. Issues may arise from the looseness of constraint in the system, ie. the print head can bounce a bit on its guides, the tension pully is spring-loaded and may not have enought resistance in some circumstances, etc. I’ve found the mechanism I’m working with most is noisier at slower speeds.
If you think about it, a printer doesn’t have to position the print head accurately. All a printer normally needs to do is “fly” the head over the page it’s printing at some set speed, then using the encoder to know where the head is and pulse the ink jets to deposit drops at precise positions as the head is moving by. The only time the print head is moving at slower speeds, is when it’s performing a homing or head cleaning operation and these both rely on simple velocity commands as well until the print head hits some kind of mechanical stop. That’s not to say that ALL printers work this way, but it makes sense that the majority would as it’s a much simpler problem to solve mechanically and programatically than the one of managing a velocity and position profile for intermediate positions across the page and thus lower cost.
All this means is that your results may vary when trying to get the system tuned to perform well across a wide performance envelope.
A second challenge that I’ll talk more about later is that in order to keep costs for this project down we’ll be relying on EMC2′s own software counters to track encoder pulses. This will put an upper limit on the frequency that can be counted and thus the velocity of the axis. So far I’ve been very pleased with the performance of EMC in the regard, but for more critical applications than a teaching aid it’s important to consider this and plan for a hardware-based counter system when needed.
Emergency Stop Control – For when things are going badly
From what I’ve seen this is an often neglected topic in hobbyist CNC forums and understandably so. It’s much like discussing insurance and premiums. It’s one of those things that you don’t care about until you need it. You want it to be reliable, easily accessible and provide you with the protection required. Again it’s a large subject deserving of a textbook or two and possibly a good subject for a later post.
For this project I consider e-stop control to be an optional piece. Again, this should be a relatively safe mechanism to work with, but as part of the learning process you may consider adding an e-stop circuit to your servo “lab”. However when you do go to move on to the “real world” and an actual CNC machine ensure the e-stop system works and become familiar with it. If the machine doesn’t have an e-stop system, DON’T USE IT UNTIL IT DOES!
Practice – Your own Servo Drive Lab
As I’ve alluded to a few times, integration is a process where things can and sometimes do go wrong. It is possible to break stuff or people. In Part 3 you’ll find that the steps we’re going to follow for integrating a servo-driven axis are laid out so they slowly and incrementally grow the risk as you progress. Observing, Testing predicted results against actual results and tweaking/correcting as you work through the process.
Your “lab” can be set up at surprisingly low cost with just one or two evenings of effort. The apparatus for a Servo Drive Lab is as follows:
|PC (with printer port?)||Free||You knew you needed a PC to run EMC2 anyways right? I’ll assume you already have this.|
|Printer port card (Optional)||$10-$20||If you have one available, it’s preferable to use an add-on card for your printer port. If you’re not careful (and even if you are sometimes) it’s possible to damage the printer port. To keep things simple and more accessible I’m not going to bother with things like opto-isolation, and that means it’s possible to damage the port you’re working on, and it may be best to avoid damaging any ports that are directly connected to the motherboard.|
|EMC2 Software||Free||Thanks to NIST for starting this project and making it open source, and the community for picking it up and running with it!|
|DB25 Cable||Free-$3||Plugs into the printer port so it needs a DB25 Male end. The other end doesn’t matter, just hack it off and use a multimeter to figure out which wires go to which pins. The ideal cable is a DB25 – DB25 with a thicker body. This makes it more likely that all 25 pins will be connected to 25 wires of a gauge that is easily used. Printer cables with centronics connectors tend to have 36 wires of very fine gauge making them harder to work with.|
|Old Inkjet Printer||Free-$10||Check under your bed, your neighbor’s basement, garage sales or local thrift store. A gold mine of stepper and servo components as well as other sensors, switches and mechanisms. We’re gonna break it, so make sure it’s not one that the kids are relying on to get their homework off of.|
|H-Bridge Motor Driver||$3-$25||Build from scratch, buy a kit or buy an assembled unit|
|12 to 24VDC power supply||Free-???||I’ve found this can be any set output voltage between these two values. 12VDC is working great for me. Should be capable of at least 1Amp. An old PC power supply is fine.|
Inkjet Printers – A goldmine of small parts
Aside from the pieces we’re really interested in, inkjet printers and multifunction scan/print machines contain a fair assortment of motors, sensors, springs shafts and gears. Some are easier to disassemble than others, but most will do the trick for our purposes here. What we’re after is the motor and encoder mechanisms that make the physical parts of the servo system. At a bare minimum you should be able to pull out a whole linear mechanism that has the motor, linear guide that carries the print head (with the encoder reader), encoder strip, toothed belt and tensioning pulley. It may also be possible to use other parts like the power supply, flex cables, etc.
So here you’ll have to get creative in tearing apart the printer and finding the mechanisms you want to work with. All the printers I’ve looked at so far have their print heads moved by servo control while the paper feed mechanisms may be either stepper or servo control.
Before buying anything, just double check that the print head uses an encoder strip by opening the access panel on the front or top where you have access to the head. Running parallel to its direction of travel you should find a transparent plastic strip with fine lines etched across it. Really expensive printers and plotters often have laser cut metal strips but you probably won’t be using those for this project.
In this case I’m using an Epson Stylus C86 colour inkjet which has a stepper on the paper feed, is nice and compact with solid construction.
I’ve also found a Lexmark (X2350?) multi-function machine drives the paper feed with servo control. This combination is really neat as you can experiment with the paper feed first which has a shaft encoder giving you continuous rotation without limit (if you get a run-away situation there’s nothing to collide with or jam). Then when you’ve mastered that, you can move up to the linear axis of the print-head which has a limited amount of travel and will bang into stops at either end.
An HP All-In-One unit I tore apart had servo control of all three actuators including the movement of the scanner.
Ensure you have the power supply or power cord to go with the printer as well as this will help in reverse engineering parts of the printer.
In Part 3 we’ll go through the actual steps of integrating the servo mechanism with the PC and EMC2.
In Part 4 I’ll address the PID tuning of the servo drive from within EMC2 to get the best performance out of your new servo mechanism.