CNC G code basics explained

Home Model Engine Machinist Forum

Help Support Home Model Engine Machinist Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

laurent_parti

Well-Known Member
Joined
Jun 11, 2013
Messages
46
Reaction score
6
Hi all,

When you deal with CNC sometimes you hit the "G code" wall. I make this basic video to help beeing less confusing about it, I hope:

[ame]http://www.youtube.com/watch?v=ocPIgODO4DM[/ame]

Laurent
 
Hi Laurent
Are you going to explain in your next video the difference between Absolute and Incremental programming, newcomers to G code can choose the system to suit their application.
Readers with experience of G code will know you were in Absolute mode for the video, a screen shot of the program would be helpful, but congratulations on your work with the video.
Rgds, Emgee
 
i xypylonracer,

Thanks for the input. Indeed G code is able to make a lot of different things like absolute / inc mode, also metric and imperial, tool diameter and length compensation, peek drilling cycle, circular interpolation and so many interesting stuff. Hep, could be a great new video. But did not want to afraid anybody :D
 
good job:)

about time someone did that.....back to basics. nice and simple and not like this...


g76 X.0 Z-2 Q1 P0.05 J0.006 L45 H0.022 I29 C0.025 B0.0001 T0

and expect you to know what it all means, let alone what to do with it.
 
blighty... tell me that's a random string you pulled out of ypur head...
 
blighty... tell me that's a random string you pulled out of ypur head...

i'm not fluent and at that level there are variations from different machine controls but g76 is a threading cycle and you wouldn't always have to use everything but there can be arguments for a lot of things like thread depth, number of passes, taper, finish depth, cut strategy (does it make constant x cuts, or does it offset the z each pass to match the thread angle) angle and how it exits. often these things are presets in the machine parameters but some models of machine may let you alter them within the program. that said i think that is not a real example. i mean why is there a "t" at the end. i'm pretty sure T is exclusively for tool changes and what machine has a tool 0?. letters like i,j,k,p can vary in function from one canned cycle to another but g,m,s,t,h,o,x,y,z,a,b,c are pretty much single purpose. also x is set to 0 and a thread with zero diameter would be weird.
 
X is set to zero...... well spotted sir.

yep g76 is a threading code. the reson i put that up was, i have been having a bit of trouble with using g32 for threading. g32 works fine for semi ridged taping and for thread cutting, but up to 8 or so loops then it goes a bit wrong. needed to find out how g76 worked. so it was sort of in my mind when i read the thread.

plus, with a lot of other things as well, people in the know tend to think others are in the know and they will put up a line like that with no description expecting you to know what your doing. e.g.....

Q. how do i cut a thread on lathe?
A. use g76

no help to any one. the answer should of been......

use g76. and this is how you do it blaa blaa blaa.

just one thing about the vid. yes a cnc can move all it's axis at once, but it's unwise to move all 3 when positioning. best to move the Z axis out the way first, then the other 2.

G0 X0 Y0 Z0 WRONG

G0 Z20 moves the head up out of the way.
X0 Y0 positions head over home.
Z0 move head to home.

best to do this at the end of the program as well. last thing you want is the cutter down the bottom of a 50mm deep pocket then a G0 X0Y0Z0 command.
 
i mean why is there a "t" at the end. i'm pretty sure T is exclusively for tool changes and what machine has a tool 0

your right T is used for tool changes but when its T0101 (T01... tool one. 01 use tool offset 1) or T0202 (T02.. tool two. 02 use tool off set 2) or you could have T0302.... tool 3 but use tool offset 2.

with g76 T is used for taper

g76 X.0 Z-2 Q1 P0.05 J0.006 L45 H0.022 I29 C0.025 B0.0001 T0

X -XEnd
Z -ZEnd
Q - Spring Passes. (optional)
P -Pitch
H -Depth of first pass
I -Infeed angle
R -XStart (optional)
K -Z Start (optional)
L -Chamfer (optional)
C -X Clearance
B -Depth LastPass (optional)
T -Taper (optional)
J -Minimum depth per pass(optional)


the g76 code i put up was from a pic i took of what the mach3 turn wizard did when i was try to figure it all out. i was just putting any old crap in there just to find out what it was doing and understand exactly what's going on with in the g76 line of code.
 
X is set to zero...... well spotted sir.

yep g76 is a threading code. the reson i put that up was, i have been having a bit of trouble with using g32 for threading. g32 works fine for semi ridged taping and for thread cutting, but up to 8 or so loops then it goes a bit wrong. needed to find out how g76 worked. so it was sort of in my mind when i read the thread.

plus, with a lot of other things as well, people in the know tend to think others are in the know and they will put up a line like that with no description expecting you to know what your doing. e.g.....

Q. how do i cut a thread on lathe?
A. use g76

no help to any one. the answer should of been......

use g76. and this is how you do it blaa blaa blaa.

just one thing about the vid. yes a cnc can move all it's axis at once, but it's unwise to move all 3 when positioning. best to move the Z axis out the way first, then the other 2.

G0 X0 Y0 Z0 WRONG

G0 Z20 moves the head up out of the way.
X0 Y0 positions head over home.
Z0 move head to home.

best to do this at the end of the program as well. last thing you want is the cutter down the bottom of a 50mm deep pocket then a G0 X0Y0Z0 command.


well if you are milling it's also best to write out a header to set the proper modals both after tool changes and after certain canned cycles as well. if you run a tapping cycle the machine goes into feed per revolution by default but cancelling the cycle doesn't always bring it back to the mode before the cycle changed it. bassically they machine doesn't not that you put it in the feed/rev mode with a modal command ot a tapping cycle. it just knows it's in a feed/rev mode. restarting a machine after a tap breakage without a safe point with the proper modals and cycle cancel command can cause the machine to try to feed at absurd rates and things crash. and you dont need to home the machine or send it to part zero at the end. many production shops will rapid the table to center x and y full positive to present you the part for removal so there is no reaching.

it's not always needed to go all the way up on the z. a safe rapid point can be established when you write the program. once you retract to a 1inch clearance or so it's ok to rapid all axises but whth key seet and dovetail cutters and sometimes boring bars you need to watch out how you retract. likewise with the lathe you may need to be concious of the x as well as the z since tools can reach around overhanging sections. you may need to move the x to a clearance then z to a clearance then rapid to a safe tool change position. and you may need to do this in a hole. lathe work uses much less code because canned cycles are more often a viable sloution and there are only 2 axises but it takes a lot more metal considerations in my opinion. tool changes are done where the programmer decides it's safe since it doesn't need to retract z 100% to change tools. with long boring bars or long parts you may need to measure tool stickout so you dont ram the next tool into the part when you call up the offset.

i'm all for cad/cam but i think it's best people learn to deal with these things before they start using cam. nothing is worse than a program that doresn't work with 1000+ lines of code. or trying to restart a program half way and not knowing why it's cutting in the wrong place or why the tool zips into the part at maximum feed.
 
what control is that for? I just didn't recognize all the "optional" modifiers. I know what G76 is, I do this for a living after all.

I was curious as to what control that is from.
 
well if you are milling it's also best to write out a header to set the proper modals both after tool changes and after certain canned cycles as well. if you run a tapping cycle the machine goes into feed per revolution by default but cancelling the cycle doesn't always bring it back to the mode before the cycle changed it. bassically they machine doesn't not that you put it in the feed/rev mode with a modal command ot a tapping cycle. it just knows it's in a feed/rev mode. restarting a machine after a tap breakage without a safe point with the proper modals and cycle cancel command can cause the machine to try to feed at absurd rates and things crash. and you dont need to home the machine or send it to part zero at the end. many production shops will rapid the table to center x and y full positive to present you the part for removal so there is no reaching.

it's not always needed to go all the way up on the z. a safe rapid point can be established when you write the program. once you retract to a 1inch clearance or so it's ok to rapid all axises but whth key seet and dovetail cutters and sometimes boring bars you need to watch out how you retract. likewise with the lathe you may need to be concious of the x as well as the z since tools can reach around overhanging sections. you may need to move the x to a clearance then z to a clearance then rapid to a safe tool change position. and you may need to do this in a hole. lathe work uses much less code because canned cycles are more often a viable sloution and there are only 2 axises but it takes a lot more metal considerations in my opinion. tool changes are done where the programmer decides it's safe since it doesn't need to retract z 100% to change tools. with long boring bars or long parts you may need to measure tool stickout so you dont ram the next tool into the part when you call up the offset.

i'm all for cad/cam but i think it's best people learn to deal with these things before they start using cam. nothing is worse than a program that doresn't work with 1000+ lines of code. or trying to restart a program half way and not knowing why it's cutting in the wrong place or why the tool zips into the part at maximum feed.


my description above was a simple code of something that imo should not be done. it wasn't a thesis on the in's and out of cnc programing. thats why i didn't put a header in the example 'cos thats what this thread is about..... CNC G code basics explained.

no it's not needed to go all the way to the top on the z. my mill is set to 10mm clearance. when it comes to a tool change i set it to 100mm that's just so i can get to the chuck/collet easier. most a the cam stuff i have seen will put in a G91 G28 Z0 before the T0202 line. thats cos the machine has a tool changer. on my lathe i tell it where to do the tool change. after the last g code of a tool it will go to x25 z25 and do the tool change.... would be nice to back off well away from the chuck but my lathe is so ruddy slow it will take all day to do a tool change.

vid bellow shows why g00 x0y0z0 is a bad idea...... skip to 2:20

[ame]http://www.youtube.com/watch?v=uWOAAyN3btc[/ame]

i sort of feel that learning everthing about cnc before you use one is like having to do a 4 year engineering apprenticeship before you can can do 4 year engineering apprenticeship.

little steps. walk then run.
 
what control is that for? I just didn't recognize all the "optional" modifiers. I know what G76 is, I do this for a living after all.

I was curious as to what control that is from.

that g76 line was generated for Mach3 turn from a Mach3 turn threading wizard.

the list of modifiers is all the (dont know how to put this) stuff g76 can do (i tried). but you dont have to use all of them.

i tried it today and it work great, i also didn't use all of them. i only used the ones in black.... i think.

X -XEnd
Z -ZEnd
Q - Spring Passes. (optional)
P -Pitch
H -Depth of first pass
I -Infeed angle
R -XStart (optional)
K -Z Start (optional)
L -Chamfer (optional)
C -X Clearance
B -Depth LastPass (optional)
T -Taper (optional)
J -Minimum depth per pass(optional)
 
I've never used Mach3. I have been thinking about building a small lathe tho.
 
i sort of feel that learning everthing about cnc before you use one is like having to do a 4 year engineering apprenticeship before you can can do 4 year engineering apprenticeship.

little steps. walk then run.

i agree with walk then run. that's why i think people should understand how the programs work and what modal commands do before they get into cad/cam. it's a little easier to fix a program that you wrote from scratch than something a computer spat out for you because you know what each part is supposed to do. then you can also come up with ways to make the program safer to run from different points after a failure. i'm not talking macro programming or knowing every last argument for every canned cycle, but knowing why you can't always restart programs where something went wrong and the after effects of using certain cycles that change the modals.

if you jump into cad/cam too early you can maybe do some impressive stuff, but if you are running a 3d program with 100,000 lines of code and several hours on one tool something may break and restarting from the begining may not be ideal, so jumping into mdi mode to insert some relevant modal commands is a good thing to know to avoid more broken stuff.
 
i'm not talking macro programming or knowing every last argument for every canned cycle

dont think you could do that anyway. the first thing i made on my cnc mill was a 3d bust. cant remember how many lines of code it had but the .TXT file was 2.9mb. don't think you could go through every line in g-code that size.

but saying that, it's handy to know what G20 and G21 is. as you dont want to run a code you have measured out in metric and stick a G20 in front of it:wall:
 

Latest posts

Back
Top