Enter a drawing to win a SideStop work stop and receive our free weekly newsletter.Enter Now!
|CNC Tips & Techniques|
Herein are my notes on various techniques that are specific to CNC, but not necessarily a particular type of machine. They are to date a rather disorganized collection of anecdotes found elsewhere. Over time I will organize these and test each one, discarding those that don't work so well and emphasizing those that do. For now, I am using a font convention to differentiate the tips:
If I have written a tip in this font, I have personally verified it.
If it is written like this, I found it on the Internet and am awaiting verification. These are the ones to take with a grain of salt.
|I Have A CNC Mill and Some G-Code, What Next?|
First, see my tip below about starting out with just 2 axes.
If you want to plunge in, here is a rough play by play for how it should go in 3 axes. When you draw your part in your cad system, you should place one corner of it so that the top of that corner is at X0Y0Z0. This is the datum, or reference point for that part, and is called Work Zero.
When you power up your machine and it homes, all the axis are in certain positions which the machine calls home, and typically these would all be zero, or they might be assigned particular values. This location is called Machine Zero, or just the Home Position. Often the home position will be the position where the machine can access the toolchanger if there is one, or perhaps it will be the maximum positive values for all axes. A switch is often located there so the machine can positively find it again.
Clamp your stock down on the table. You want to reconcile the origin of the stock relative to the machine zero. So, pick a corner of your stock and say, "This is my datum point or Work Zero". This should correspond with the position of your stock in the cad screen. Through a series of jog movements, and use of an edge finder (precise method) or a sharp point held in the spindle (crude method) you move the spindle to where the Work Zero datum on the stock lies. At this time, the machine's axis displays show your jog amounts from machine zero, so these X and Y values are entered into your G54 work offset. These values represent how far the datum on the part is from the machine zero. There is no need to enter a Z G54 work offset at this time, because the tools have not been loaded as you are just working with an edge finder or point probe.
Now, load the tool and jog in Z from machine home down to the top of the part. Whatever this distance is, you could use for your tool length offset for that tool (see below for more info on tool length offsets!). All the tools could be measured in this manner. Thus, because the tool length offset sets all the tools to the same Z level, you are done, there is nothing to set in the Z G54 work offset, which should be zero.
Your program needs a T1 M6 command to load a tool from the toolchanger and an G43 H1 command to load the length offset for that tool. It is simplist if you use H1 with T1, H2 with T2. Even if you do not have a toolchanger, the T number in your program is really only for your reference, because the H number will execute the length offset.
Now if it bugs you to set (and reset) all the tools to the top of the work, then you can set the tools to the table, or to a reference block that is sitting on the table. In such an instance, then you set all your tool length offsets to that reference, each and every time. This is the preferred method.
But, this introduces one more step, and you do make use of the G54 Z work offset for this. After any of your tool length offsets are set to the reference, you then need to measure the height from the reference to the top of the stock. If you zero the display temporarily when the tool is touching the top of the reference, then you can jog up or down as required to touch the top of the stock. This will give you a direct measurement which will be inserted in the G54 Z register.
Near the very start of your program, you need to call for the machine to use the G54 work offset. Just insert G54 into your program.
For trial, after you call G54, then call G00 X0 Y0 and the table should move to position the tool over the corner reference of the part. Note, in some systems, like Mach 3, G54 is the default, and you need not call G54 explicitly.
Then G43 H1 G00 Z1. should position the tool 1" above the corner of the part. If you are cautious, turn your rapid override down real slow, and watch the motion happen. Or you could use G01 in place of G00 and use a slow feedrate to make sure stuff is happening as you expect. Be ready to hit the feedhold or E stop if you see a collision coming
You can return the machine to home with a G53 X0 Y0 Z0 command, if Z0 is the homed position of the Z axis. G53 is the name of the machine coordinate system. Some say that it "cancels the work offset" but really, you are just dropping back into the 'real' coordinate system that the machine works in. The work offsets are just an imaginary shift of the coordinate system zero for convenience sake.
important relationship to keep in mind is:
An important relationship to keep in mind is:
Height = fixture height + work height + tool height
Total Height = fixture height + work height + tool height
of the work we've been discussing here involves setting offsets so that
we don't have to think about this relationship in our part program. We
can simply program relative to Work Zero (that datum in our CAD drawing)
and it all works out regardless of how high our vise sits on the table,
how thickness of the material varies, and how long the tool is.
Much of the work we've been discussing here involves setting offsets so that we don't have to think about this relationship in our part program. We can simply program relative to Work Zero (that datum in our CAD drawing) and it all works out regardless of how high our vise sits on the table, how thickness of the material varies, and how long the tool is.
At this point, you've got your offsets all set, you've tried the program out "cutting air" in slow motion. It's probably time to try it out for real. You might cut a little more slowly on something cheap (like a block of wood) until you build confidence, but eventually, you'll get it all right and be making parts!
What about shortcuts? Well, you could dispense with the edgefinder to find the X, Y work offsets and just job to a suitable point that's "close" by eyeball but within the material and cut the machine loose. This assumes you can do all of the machining in one setup. If, for some reason, you need multiple setups, then you have to be able to precisely locate the Work Zero setup on subsequent setups or the machine won't be aligned properly and nothing will come out right.
It is also possible that you have a fixture that enables you to swap to the next setup while preserving orientation to Work Zero. One can certainly imagine a fixture where you are essentially just flipping the part upside down and registering it with a pin or some such to cut the back side. This is something to think about for a complex part requiring multiple setups.
|Tip for Beginners: Start Out In X,Y With A Sharpie "Cutting Tool"|
A good place to get started is 2D CNC programming with a mill. In this mode, you manually control Z, and just run the program in X and Y. You'll have to write your program with that in mind, but the idea is to see whether you can get your machine to draw a circle in a particular place without going off track. You can put the Sharpie into your keyless chuck (you do have a keyless chuck, right? <G>) and jog it down until it makes contact with a sheet of paper taped down on a flat surface. Jog to the point you want to use as your Work Zero, and go from there. Experiment with your machine and program until you can draw a circle or other simple shape exactly where you want it. Move on to something more complex. The Mach 3 gang likes to use a g-code program that draws a roadrunner, so check their site for that.
Once you have 2D programming down, you'll be ready to tackle 3D. BTW, more than one CNC mill project built the X and Y axes with manual machining and then used this 2D technique to build the Z-Axis parts under CNC control. Not a bad way to bootstrap!
|Managing Tool Length Offsets & Automatic Tool Height Setting / Tool Touchsetting|
What is it and why do I care?
As we saw above, getting all the offsets right can make writing the CNC program a lot simpler. It just needs to keep track of where the cutter is relative to the Work Zero datum point, which is part of the CAD drawing (the 0,0,0 origin there) we started from. All that fussing with edgefinders and such can be a bit of a nuisance, particularly when you get into tool length offsets, which could be different for each and every tool. Your CNC control program (such as Mach 3) needs to know how long each cutting tool is and in the worst case, you'll have to go through a process of telling it every time you change tools.
This is a tedious and time consuming process that doesn't make a lot of sense if you can avoid it. There are two approaches to avoiding it. First, you can use an organized manual system of some kind to manage the problem. Second, you can use an automated system that measures the tool length under CNC control.
Manual Tool Length Offset Management
The simplst manual system involves measuring the tool length offset once for each tool (assuming you can change them on the machine and maintain repeatability of these offsets) and entering all of them into your control program's tool table. A height gage and surface plate will greatly facilitate this operation, as will a rack that lets you keep track of which is which:
Tools organized by their Tool Table entry in Mach 3. The offsets were pre-set and entered into the table...
Then again maybe you can fill that tool table! Geez those toolholders must have cost a pretty penny...
Mach 3 supports up to 253 entries in its tool table, so you'll likely go broke purchasing tool holders before you run out of slots in Mach! It certainly pays to keep your most common tooling in the table at the very least. For example, you might have:
Large Carbide Insert Facing Mill
Large Carbide Insert Roughing Mill
Big "Corncob" Rougher
3" Fly Cutter
1/2" Roughing End Mill (2 and 4 flute)
1/2" Finishing End Mill (2 and 4 flute)
3/8" Finishing End Mill (2 and 4 flute)
1/8" Finishing End Mill (2 and 4 flute)
1/16" Finishing End Mill
Drill Chuck w/ Bit (How many common hole sizes do you need? Should you standardize your shop on just a few hardware sizes? You'll want a chuck for each one. You may need the hole size for tapping, for clearance, and probably a counterbore as well.)
Drill Chuck w/ Center or Spot Drill
Deburr or Chamfer Tool
Special purpose cutters: Dovetail mills, keyway cutters, slitting saws, etc.
Given the flexibility of CNC to do things like interpolating holes with smaller end mills, a surprisingly small collection will cover a lot of ground. You can always tee up a few special purpose cutters if you need them for a job.
Assuming you have this level of organization, you can even write your CNC program so that the operator can see which tool to pop in (by a # that is also on the tool rack). He pops it in, pushes the button to go, and the program knows exactly which tool entry to select and move on with. Having available a power drawbar or quickchange tooling system can make this go surprisingly quickly on machines that don't have an automatic toolchanger.
You are going to need to make sure you can re-register a tool in its holder to exactly the same offset each time you insert it. This probably means the tool holder needs a shoulder of some kind that registers on the spindle nose. If you are running R8 or MT tooling, take care that you don't assume the collet or R8/MT shank will always tighten to the same position as the drawbar pulls it in--it won't unless there is a shoulder to reference the tool to the spindle nose.
Fixed Offset Tooling Systems
The next level of sophistication for this problem involves creating a system whereby every tool is set to the same length. Companies like Tormach sell these kinds of tooling systems, or you could consider building such tooling yourself. Tormach's is based on an ER collet system. You need a separate Tormach tool with collet for each cutter, and they also offer drill chucks.
It seems to me that given a surface plate and height gage, you might do something similar to Tormach's system with normal mill holders. At the least you might segregate your tools into standard length offsets. Again, you need a way to reliably reference the holder to the spindle nose without relying on consistent pull-in by the drawbar. The latter will not be repeatable!
Automatic Tool Length Sensing
The peak of sophistication is a mechanism whereby tool offsets are automatically determined by having the tool contact a switch or close a circuit at a fixed location on the table. If every tool is measured against the same device, they will all be in the same position relative to one another once the tool offset is applied. At this point, you would then be able to apply multiple tools against the workpiece using only a Work Zero touch off, which can save a lot of time and effort on a CNC job.
If you don't have automatic tool height setting, you'll need a manual mechanism to deal with the problem. Some use a gage block and just eyeball it, and there are also various arrangements using dial indicators and the like. You can do a touch off with cigarette paper in classic fashion. You can also create or buy a tooling system where all of the cutters are precision set to a particular height, such as the one sold by Tormach. If you've got a surface plate and height gage, this is very easy to do for yourself, and a lot of pro shops have the Tool Crib doing this work so that when a tool is checked out it comes with a slip that tells the proper tool offset. Lastly, there are a variety of switches that light an LED (ala LED edgefinders) also available.
Many professional CNC shops also use this method to allow for insert wear, and to stop a continuous production job if an insert breaks. In this mode, the toolsetter captures the initial offset, and if it varies by more than the amount of wear expected (usually less than 0.005"), the insert is assumed to have broken and the program is halted until an operator can look at it.
What Kind of Sensor Can I Use?
The switch used can take a lot of formats. I have heard of one fellow who closed a circuit between the QCTP and the chuck on his lathe. This method of just letting contact do the job of closing a circuit works pretty well, and is certainly easy enough to build. A CNC touch plate is a device that can be dropped atop the workpiece. It is of known thickness, and has a contact with the spindle, and hence the end mill. The Z-Axis lowers until the circuit is completed, at which point the cutter is a known height above Work Zero (i.e. the thickness of the touch plate). The plate is simply a metal plate with a wire that is backed with some sort of insulating material such as Delrin. The Delrin insulates the connection from the workpiece, which presumably would otherwise have a closed circuit through the frame of the machine and all the way back to the spindle.
Insulation is not neccesary for a touch plate that sits on wood workpieces!
Here is a switch mounted off to the side that finds a zero for the top of the spoil board (the table) of a router setup:
Touchsetter relatively to table zero on a router--top of spoilboard...
Another homebrew touchsetter switch. This one is pretty tall!
A commerical Blum Nano touchsetter...
If you want to build a probe that works along the principles of commercial devices, Indoor Flyer has an excellent article on one. It's intended for digitizing, but could be used for this purpose as well. Why not make 2 so you have one for each purpose?
If you want to buy a probe, try IMServices. The reviews I've heard on their probes have been great!
How about using an optical limit switch? Industrial Hobbies used to sell these, but now only offer them as part of their CNC kit. I've been working on a design for one. They're pretty simple:
An optical limit switch could be made into a touchsetter switch...
After I determine how accurate my design is in the limit switch application, it wouldn't be hard to re-engineer it for this application where it could be mounted vertically near the home position. The neat thing about the optical limit is the contact closure is completely "soft" as a flag blocks the beam of light to the sensor. As such, over travel is easy to arrange so you can slam into the limit pretty fast, apply minimal back pressure to your cutting tool, and if the axis has a bit of over travel before the switch cuts in, you haven't ruined anything.
Finally, Mariss Freimaniss (Mr Gecko Drive) had an interesting suggestion for those into building probes:
How about a probe rod attached directly (superglued) to a pizeoelectric crystal? Any contact would generate an easy to detect voltage. Take apart a clicker type butane lighter and attach a voltmeter to the wires; it takes the faintest pressure on the crystal to generate a voltage. Nothing moves so the contact/no-contact point hysterisis is negligable.
Another fellow mentioned the availability of small "bimorph" piezoelectric devices to be used as Mariss suggests. He says they put out 4v with 10 micrometers of deflection. That's pretty darned sensitive! Not sure this sensor is ideal for this application, however. It is simple, but the problem is it only sends a brief signal at the point of contact and then stops signalling. It might be necessary to "latch" that signal in some way. Anyway, mechanical switches are cheap and easy.
Setting up Mach 3 for Touchsetting: Basic Script
Okay, let's take a look at the software component of creating an automatic touchsetter for use with Mach 3 on a mill.
First, you need a sensor, which we covered just above. Next, you'll need a macro to position the tool over the sensor and drive down in the Z-axis until contact is made, at which point the Z-position may be used to calculate an appropriate offset. Before going to a lot of trouble to write a custom macro for this purpose, be sure to experiment with the "Set Tool Offset" command on the control panel. This is the manual approach to setting these offsets, and you'll want to be comfortable that your automated approach does something similar without as much manual intervention from you. Basically, you just touch-off the tool, enter any additional offset in the DRO next to the button, and click the button. For example, if you touch down on a gage block, enter the thickness of the block in the additional offset DRO. You want to be very comfortable with all the offsets available in Mach 3 before tackling this job!
On the sensor, you need to tell Mach 3 what input pin to use as a probe sensor contact. Use the "Input Pins" dialog to do this. From what I can read in my travels, a Z-axis feed rate on the order of 10"/minute is slow enough to work well without damaging the tool or the sensor.
Now about those Mach 3 macros. Here are some samples, use at your own risk until I get my own written (my own comments are after the "//", ignore those!):
code "g31 z-10 f10"
code "G92 Z0"
// Retract Z, set feedrate of 10"/min
// Wait for the move to finish
// Zero the Z-Axis DRO
// Move to Z 3"
// Try moving down until the probe touches
// Zero the Z-Axis DRO again after the probe touches
Again, ignore everything from "//" on, inclusive, those are my notes about what is happening and don't go into the macro. Now you need to determine exactly what it is that's being zeroed. Do you want to just find the tool offset? If so, you probably want to measure from the table height or some fixed position. Do you want work zero as the top of the workpiece? If so, you want something that sits atop the workpiece and is repeatable. Either way the macro shown above has no provision to deal with any offset between Z0 and the thickness of the switch or other calculations you may want to do to get exactly the offset you are looking for.
Here is another sample macro (written for the router switch shown above) with my "//" comments (as usual, they'd have to be removed before use):
if IsSuchSignal (22) then
code "g0 x10 y1"
code "g0 z-30"
code "g31 z-3 f20"
call SetDRO( 2, .125 )
"G0 Z2.5 F60"
Wend end iF
// Check whether a probe input is defined
// Move to the location of the touchsetter switch: X=10", Y=1"
// Raise Z 30"
// Start moving Z down at 20"/min after dropping Z 3".
// G31 is Mach3's "straight down probe" function.
// Move until the contact closes...
// Set DRO2, the Z, to the thickness oF the touch plate code
// g-code to quickly go up 2.5” to get out of the way (is 2.5" enough?)
// do nothing while the motor is moving up
Again, I'm not endorsing these macros, just trying to understand them before working on my own version. Here is another sample that is a bit more complex than the first two:
if IsSuchSignal (22) Then
Fixture_Num = GetOEMDRO(46)
Call SetOEMDRO (46, 202)
Code "G00 G53 Z00."
'Code "G53 X0. Y0." 'Move into Probe Pos ***EDIT HERE***
Tool_Number = GetDRO(24)
code "G91 g31 z-4. f10"
If Tool_Number = 0 Then
z = GetOEMDRO(85)
Else Call SetDRO(24,0)
Height = GetDRO(2)
code "G91 G0 Z0.25"
While IsMoving() Wend end if
// Check whether a probe input is defined
// Set to fixture number 202
// Height to move into probe pos
// Needs editing for use, but how?
// Move Z to -4" at 10"/min
// Wait for move to complete
// Tool_Number 0 means master tool Cal
// Get Machine ZPos
// Set fixture offset
// Turn off the tool offset by loading tool #0
// Get the pos of the Z axis without the Tool comp on
// 'Turn the tool Back on so the offset will go to the
// Set the Tool Height offset
// Set the Fixture back to what it was
This macro is designed with the idea that all of the tool offsets are relative to the offset of a master tool, which is tool 0. Hmmm, this guy went to a lot of trouble to do that, but I don't yet understand why. Perhaps he establishes Work Zero with tool 0 and then keeps the other offsets relative to that. The answer is probably obvious, but I'm not there yet.
And yet another, even more elaborate macro from the Mach 3 support forum. It is interesting in that it simply keeps track of the difference between the current tool and the newly inserted tool rather than bothering with the tool table. It also shows how to prompt the operator to insert the new tool:
ChX = GetUserDRO( 1200 )
ChY = GetUserDRO( 1201 )
ChZ = GetUserDRO( 1202 )
Code "G53 G00 Z-1"
ZOld = Getdro(2)
Code "G53 G00 X" & ChX & "Y" & ChY 'Move to the probe position
Code "G31 Z-230 F450"
Old = GetVar(2002)
Code "G53 G00 Z-1"
Code "G53 G00 X65 Y-200"
MsgBox ("Insert the new tool")
Code "G53 G00 X" & ChX & "Y" & ChY
Code "G31 Z-230 F450"
HitNew = GetVar(2002)
Diff = HitOld - HitNew
If DiffABS=0 Then End
If HitOld < HitNew Then
ZNew = ZOld - DiffABS :A=1
If HitOld > HitNew Then
ZNew = ZOld + DiffABS :A=2
Code "G53 G00 Z-1"
// Get X, Y, Z where the touchsetter probe is located from user defined DRO's..
// Move the tool all the way up = 1" above Work Zero
// Record this Z-position after the move up. Should change to an OEM DRO, which?
// Move to the touchsetter X, Y position
// Move down in Z until we hit the probe. That F450 looks too fast! Is it metric?
// Get the position where the probe hit on the old tool
// Z move all way up
// Move to change tool position
// Tell the operator to insert the new tool
// Move to the probe position
// Z move down untill hit, F too fast? Metric?
// Get the Position that the Probe hit at on the new tool
// Offset difference in the two tools
// Absolute difference
// If no difference, don't bother
// If new tool is longer, calculate new Z DRO setting by subtracting
// If new tool is shorter, calculate by adding
// Select new coordinate system and move Z -1"
// Set Z to the new value, adjusted by tool length
Everyone says this works great, but I wish it would use the real tool length offsets as intended by the g-code language. Also, it makes use of a lot of deprecated functions that are being discouraged in Mach 3. Note also that it is likely working in metric, so the specified feedrate is not 450 inches/minute but rather 450 mm/minute, which is about 18"/minute, much safer! You will need to deal with that difference on your system. As I write this, the macro works reliably for some, but not others. Still searching for nirvana!
Setting Up Mach 3 for Touchsetting: Interface Niceties...
Okay, let's say we have the basic script up and running. How do we access it from within our g-code part program so that we can set the tool length offsets either at the beginning of the program, or in a program that let's you go through your whole rack and set up the table, or for some other application such as after each tool change?
One easy approach is to make use of Mach's capacity to create custom M-codes. Let's say you wanted to trigger your macro with an M450. Simply place the following at the top of the macro:
SetTriggerMacro (450) would set it to M450
That's pretty cool. We've just added our own canned cycle to Mach to set the tool height!
I Wish I Could Say This Is All Done And Easy, But...
Despite all the research, I still do not have a definitive macro and touchsetter design that is confirmed working. I have a lot of "almost there" prototypes where an individual got it to work well enough and moved on. It's a pity, but that will give me some challenge working out the bugs when it comes time to build my own!
Do you want to be a better CNC'er?
Get Better Tool Life, Surface Finish, and Material Removal Rates.