Modal and non modal G codes
Modal and non modal G codes
Let Me explain
We all know that programming can be complicated. So let me explain to you how it all works. This article explains the real meaning of Modal and non modal G codes.
Modal means that once a command is issued it stays in the control.
How Can you Actually Use This?
If you issue a G0 or G00 command the machine is in rapid and you do not need to re-state it.
Rapid means all motors are flat out, like a teenager in a Ferrari.
Every move from then on will be a rapid move unless you tell it otherwise. The G code that changes it must be in the same group. For example G0 G1 G2 and G3 are all in the same group a bit like The Beatles used to be.
The other day I was talking to a “young person” who hadn’t even heard of the Beatles. I mean fuckin hell, am I really really old or are they doomed to be forgotten?
By the way my definition of a young person seems to get older every day.
Imagine being called a “young person”. You hear politicians on the telly saying “oh yes I was talking to one of those young people the other day”.
God I hate the fuckin telly, well apart from Love Island, Naked Attraction, Embarrassing Bodies, Goggle-box, Coronation Street, Emmerdale Farm, East Enders, and Strictly Come Dancing.
To be really honest I watch everything but in my defence I never stop complaining and throwing Pot Noodles at the TV.
My TV’s are covered in dents and scratched from various foreign bodies being thrown at them. Obviously I have a TV in every room and toilet. They all still work even when the noodles trickle inside.
I have five, toilets not TV’s. My mother said “you must use loads of water, not to mention lavatory paper”
I said “mummy darling don’t you understand that you can’t shit or a piss in five toilets at the same fuckin time”
Obviously I didn’t say toilet in front of my mother it’s always lavatory.
Oh Yea I Was Saying I Hate The Telly
I saw this thing on the Internet 8 huge Emmerdale Spoilers .
Now I know a lot of you CNC Programmers out there are big fans of the show but I got to say it.
Spoiler I mean how in the fuck can you spoil something that’s already a mind numbing piece of crap!!
When I hear the music to that show it gets me really enthusiastic about emptying the cat trays that are heaving with piss and shit. (I know you are not supposed to leave them for over a week but in my defence I am getting into a routine now)
“Come on Dave the swearing gets worse, the Americans won’t like it”
I admit this is a rant too far and I wouldn’t blame you for going to a different website.
This guy writes serious stuff about G Codes unfortunately for you, almost every post and video is full of mistakes and often blatantly wrong.
Anyway you deserve it for not sticking with me through difficult times.
I shouldn’t say this but there are so many mistakes in these articles I don’t know how the fuck he gets away with it. Well that’s the Internet folks.
His new series of training videos is called “Learn The Five Quickest Ways to get Instantly Dismissed as a CNC Machinist”
Modal and non modal G codes
G2 Clockwise arc.
G3 Counter-clockwise arc
It is pretty obvious that these would have to replace one another because if you had them on the same line they would contradict one another.
You can’t go around a clockwise circle and in a straight line at the same time.
G0 X0 Y0 (Rapid to X0 Y0)
(Control says “ok I get it, rapid again, no need to repeat yourself, I heard you the first time”)
Modal and non modal G codes. How do they actually Work?
There are not many non modal commands G53 and G4
Can’t think of anymore right now.
G4 is a dwell if this were modal it would cause many problems
G0 X50. Y50. (Rapid move)
G4 X5. (Five second dwell)
X0 (This would be a rapid command not another dwell because it remembers the G0)
It remembers the G0 but conveniently forgets the G4.
My third wife was a bit like that she said I slapped her in the face but conveniently forgot that this was only after she kicked me in the bollocks and chopped off my left ear with a potato peeler.
The machine will do the G4 dwell and then completely forget it. If you really want another dwell you’d have to repeat the G4. Otherwise it’s like being told it’s your turn to feed the dog, the command is ignored.
Yes folks you can use X or P for a dwell command. I use X cos I love the feeling when the operator comes back to me n says “Dave you got this wrong”.
First of all I ignore him because my name is David and I don’t answer to Dave.
When he finally gets through to me, I love that feeling of power and superiority when I explain to him it works with P and X.
If you use a non modal command you have to repeat it for every line you want to use it on.
G53 X0 Y0;
“Wake Up State” Modal and non modal G codes.
What’s This all About?
These are the G codes that are active when you turn on the control. Wake Up State, not to be confused with getting out of bed with a steaming hangover after a night on the piss.
This wake up state cannot be guaranteed as you can change this state by parameters.
There is also a parameter which controls what happens when you press the reset button. So for example pressing reset may cancel a canned cycle. (Or not).
Your modal G codes will change when……
You press reset.
When you first turn on your machine (Wake Up State)
You read an M30 at the end of a program.
These are not actually called modal but the same applies once you start the spindle (M3) you do not need to write it again until you want to stop or reverse it. M4 will start the spindle in reverse CCW. M5 will stop spindle.
Speeds are modal but your machine may wake up with a speed of zero.
So in MDI if a speed is active and you program M3 the spindle will start at the active speed (so be careful).
If you program just a speed S2000
If the spindle is running it will change. If the spindle is not running it will change but not start. When you later start the spindle it will be at the new RPM.
When you program just a speed the machine becomes a smart arse. It laughs at you saying “Fuck off sucker, I’m not starting the spindle cos you didn’t ask me”
When I first started programming CNC machines in 1905 each program had loads of information at the beginning. None of us knew what the fuck it meant and no-one dared to alter it or take any of it out.
It could only be altered after a religious ceremony and the ritual slaughter of a Gerbil when there was a full moon.
You could be fired on the spot for even talking about these G Codes.
If only we had known about Modal and non modal G codes life would have been so much better.
So now I am all grown up, I say “do everything for a reason”. Consider your Modal and non modal G codes.
The program on the right has wasted code.
Oh and in the early day’s we often used to turn the machine off and back on again which usually sorted most problems.
No one knew why the fuck we did this but because it seemed to work we always did it.
Women often say why do men keep putting their hands down their pants. The answer is we don’t know but we do it anyway. Well I don’t know maybe you do know why.
Coming back to turning the machine off and on again. Imagine if you didn’t have a G50 in your CNC lathe program and it was set to a very low speed in another program that you had just been running.
You could wonder why you machine was running so slow. Obviously if you turn the machine off this would reset. Everything would work fine again.
So let’s see how this works.
You may want to include this line at the beginning of your program as a standard thing.
G40 G80 G90 G21
G40 Cancel tool radius compensation.
G80 Cancel canned cycle.
G90 If you state this at the beginning of each tool then you don’t need this at the start of the program.
G21 Metric, if you never change to inches you don’t need this at program start.
Anyway if you must write a load of bollocks at the beginning of your program please learn what each G Code means and why it’s there. Oh and don’t blame me when your fingers wear out.
It’s just not good enough to say “the bloke on nights always puts that in”
And That’s Not All with Modal and non modal G codes
If you are running short on memory these are things to look at. Some CAD systems will output loads of unnecessary shit but you need to sort your post processor to stop this. It’s quite easy to fix. Loads of leading and trailing zeros to get rid of.
X0.000 same as:
X050.000 same as:
Feed-rates are modal too so you only need to state them once and then again when you wish to change them.
It is best to state all of the modal information you require at the start of each section of code. Just after the tool change is the best place.
Try to program each tool as a section, as if it were a program on it’s own.
Each tool should have all the necessary information to run on its own. Nothing should be assumed at the start of each tool. Oh and always take into account Modal and non modal G codes.
But There is a Catch
Be careful when using MDI with Modal and non modal G codes as you do not know what G codes are active. All controls will have a screen displaying active G codes.
There are loads of them on this screen, don’t worry if you don’t know what they all are (even Fanuc don’t really know, they just make them up).
How Can you Actually Use This?
If for example in a section of program you have only one feed rate then that is all you will need to alter. If it’s repeated in several places (which your pesky CAD system may do). Then you will need to remember to change each one.
I very much doubt that you enjoyed reading this article but their are loads more
Loads of articles on CNC Programming, enjoy yourself:
Thanks for reading my article.
- CNC programming training.
- Want to learn CNC programming.
- Fanuc control training.
- Yasnac programming training.
- Any type of CNC course.
- CNC lathe training
- CNC Vertical Machining Centre training
- If you have won the lottery and you want to give some money away.
Services offered at CNC Training Centre
Mazak Training Fanuc Training
Don’t forget we offer training on all types of Mazak Machines and all Fanuc Controls 6m to 31i Oi old to young.