Category Archives: Macro

Using Macro System Variables

Category : Macro

Macro System Variables, I often get random emails from people asking me all sorts of questions.

I got one only the other day it began “Hi David, your articles are shit”

I don’t answer every email I get, but I try to answer when I think there is an appropriate response or I feel I can help.

Macro System Variables

Macro System Variables

Anyway someone called Neil from America (I think) asked me if I would create a tool setting macro. This involves using Macro System Variables

There is a really annoying thing on a Fanuc control (well actually there are quite a few). This one really pisses me off because I find myself making excuses for the control. I mean like I designed the fuckin thing.

For one, I am no where near clever enough and don’t even work for Fanuc. (I am available Mr. Fanuc, sorry I dissed your control)

To set a tool length it’s a really convoluted procedure. You first zero out the Z on the REL display.

You then bring down a tool and get the control to record the Z position by pressing the soft key INP C.

Macro System Variables

Here’s a couple of videos showing you how.

Origin Z

Use INP C to Enter Offset

 

Once the Z has been set you can measure as many tools as you want. Just bring each tool down to the setting block and press INP C.

Macro System Variables

Here comes the problem…..

If you turn turn off the machine or, for some reason, you have to reference it again you will lose your REL Z position. You will now have to set it again.

Oh and if you don’t notice you’ll be in deep shit. (Your tool length will be wrong!!!)

There are ways around this by using a work offset, but to be honest it’s all a pain in the arse.

Oh and one other thing. Make sure you write the offset to the correct tool because you can write it to any tool.

Warning

Check the Z zero position each time before setting tools.

A good guide is to slap a good old steel rule or a tape measure against the tool for a rough check.

Macro System Variables to the Rescue

For years I have used a work around both on Haas Machines and Fanuc Controls. First of all you need to establish where your setting block is. In my case it’s a table probe.

To do this you need to note down your machine position in Z when you touch your block or setting probe.

This will later be stored in a variable to be used to calculate the tool length.

Try to set your block in a known position so that each time the Z figure is the same. You may even be able to fix it to the machines table.

Read on to see how this variable can be written to automatically with a calibration program.

The Program…  OK Let’s Do This

  1. Write the position of the table setting probe (or block) into #102 by touching on it.
  2. Call your tool to be measured into the spindle in MDI (T06 M06;)
  3. Bring the tool down to the setting probe.
  4. Run the program below.

O9001(Tool Measurement Macro)
1.  #100=#4120 (Tool Number);
This will cause the machine to store the tool number in #100
2. #101=#5023 (Store Machine Z Position);
This will cause the machine to store the current Z position in #101 
3. #102=-500.887 (Setting Block Z);
This is the figure you recorded from the position of the setting probe.
4. #150=#102-#101 (Calculate Tool Length);
Now we can calculate the tool length by taking the known position from the current position.
This will give us a minus figure, we will reverse this in the code below.
5. #150=-#150 (Reverse Z Figure);
6. #[#100 + 2000] = #150 (Put tool length in offset);
This is a bit more difficult to understand, this puts the tool length into the correct offset.
7. G28 G91 Z0 (Return Z To Zero Return);
8. G90;
M99;

More Explanation (Macro System Variables)

System variables know shit.

What I mean by this is that system variables contain information about the system. Some are read only and some you can write to, like the tool offsets for instance.

You can ask the system loads of stuff like.

  • What speed do you have?
  • What’s the tool in the spindle?
  • What position are you in?
  • How old is my auntie Joan?
  • Do I have a big nose?

These are all stored in special Macro System Variables.

You can read them and sometimes you can write to them. It’s not like that bloke at work who thinks he knows every fuckin thing. Sometimes he’ll listen, but most of the time he has to tell you.

No, no macro system variables follow special rules.

Anyway (The Explanation)

O9001(Tool Measurement Macro)
1.  #100=#4120 (Tool Number);
This will cause the machine to store the tool number in #100
2. #101=#5023 (Store Machine Z Position);
This will cause the machine to store the current Z position in #101 
3. #102=-500.887 (Setting Block Z);
This is the figure you recorded from the position of the setting probe.
4. #150=#102-#101 (Calculate Tool Length);
Now we can calculate the tool length by taking the known position from the current position.
This will give us a minus figure that we will reverse below.
5. #150=-#150 (Reverse Z Figure);
6. #[#100 + 2000] = #150 (Put tool length in offset);
This is a bit more difficult to understand, this puts the tool length into the correct offset.
7. G28 G91 Z0 (Return Z To Zero Return);
8. G90;
M99;

The first line 1. looks into system variable #4120 which contains the number of the current tool in the spindle.

You ask what this is and then put it in #100. Obviously you can’t write to this variable.

The next line 2. asks where the machine is in Z (Machine Position) #5023. Again you can’t write to this but you store it in #101.

Line 3. stores the value that you measured early in #102. This is where your measuring block is from zero return.

In line 4. you take these values away from one another to give you the tool length

Macro System Variables

This ends up as a minus figure so we need to reverse it. We do this on line 5.

Now For The Complicated Bit

Go to bed now and look at this bit tomorrow when you wake up, after a double espresso (I  find  half  a bottle  of  whisky  good  to  start  the  day).

Good Morning Hope You Slept Well

The system variables for tool length offsets are from stored in #2001 to #2200

Therefore #2001 would be the tool length offset for tool 1.

#2020 would be the tool length offset for tool 20.

You can read this variable and you can write to it to change the tool length offset.

Let’s Do The Maths

From our calculation we know that the tool length is stored in #150.

We now want to write this value into the length offset of the tool that’s in the spindle.

The number of the tool that’s in the spindle is stored in #100 (see below).

#100=#4120 (Tool Number)

So if we add 2000 to that number (#100) then we have the correct system variable to store it in.

6. #[#100 + 2000] = #150 (Put tool length in offset)

Example

Imagine the tool in the spindle is tool 20

#100 would equal 20

Add that to 2000

[#100+2000] would give you 2020

Now stuff a # sign in front of it.

#[#100+2000] (in other words #2020)

So your offset length would go to #2020 this being the tool length offset for tool 20.

#[#100 + 2000] = #150

So You Want To Use Macro Like An Adult?

Lots of programmers use macro in a very complex and confusing way. A good macro should have a really simple interface.

Ill show you mine.

M16

Yep that’s all it is

M16 is aliased to my program O9001 meaning if you run M16 it goes into my program 9001 and returns.

Read this article if you don’t know how to alias a macro to an M code or a G code.

More Macro System Variables

Now what we could also do is when we bring the spindle nose down to set the original Z figure, we could make the machine store this in #500

500 series variables stay in the control even when it’s switched off. These variables are the cockroaches of macro programming (they survive anything).

The code for this is really simple. Just one line in fact,

All you need do is bring your spindle down to the setting block. Then run M16, which I have aliased to program 9002

Or if you like just run program 9002

O9002 (Calibrate Table Block);
#500=#5023 (Z Machine Position);
M99;

Word Of Caution

Don’t use M99 at the end of your Macro unless you are calling it with an M Code Alias. Otherwise it will be stuck in a never ending loop.

So Now It’s Simple

Bring the spindle down to setting block and run M15.

This sets #500. If the block is in the same place then this is not needed.

Call the tool you want to measure to the spindle in MDI otherwise it won’t be registered in #4120

T20 M06;

Bring the tool down to the block and run M16.

This will then store the tool length in the correct offset.

Please contact me if you require:

  • Fanuc training.
  • CNC programmer training.
  • Want to Learn CNC programming.
  • Fanuc programming   training.
  • Any type of CNC course.

Don’t forget to watch my Tutorial Videos

Services offered at CNC Training Centre

Edgecam training.

Classroom programmer training.

Onsite CNC Machine Training.

CNC Training on all controls and machines.

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.

[contact-form-7 id=”2706″ title=”Contact Form”]

 


D01 END1 Macro How does it work?

Category : Macro

D01 END1 How does it work?

Someone said to me the other day to “why don’t you just do one”. In fact people often say this to me, even complete strangers. I was forced in the end to google it.

Anyway having researched it at length I can safely say it’s not a term of endearment. It actually means “fuck off”.

Now in macro programming it all takes on a different meaning. If you ever programmed computers back in the 1980’s then you’ll remember BASIC

(Beginner’s All-Purpose Symbolic Instruction Code)

This was a computer language very similar to Macro programming. Mmmmm not come far have we?

Anyway that’s where this language originates. Often known a Spaghetti programming. A pejorative phase to describe this type of programming used mainly because you can be hop skipping and jumping all over the program with GOTO statements and all sorts of confusing shit.

You have to be very disciplined with this type of programming and add loads of explanations. You must space the code out in neat chunks.

Although crude, macro programming has some great uses.

Oh and it adds real functionality to CNC programming.

D01 END1 What is it then?

This is a kind of loop and is best explained in an example. My example is a macro that will drill a grid of holes. The user states the spacing in X and the spacing in Y. Also the number of holes in each direction.

Now I know the smart arses are saying “fuck me, doesn’t he know there are cycles that already do this, yawn yawn”

Well actually I do.

I also know that the wheel was invented 3500 B.C. but the wheel can be used for demonstration which is what I’m about to do.

Demonstrate grids that is not wheels.

First of all this is just drilling one line of holes I’ll then go on to complicate the shit out of it by doing a grid.

First of all I drill one hole at X0 Y0, or whatever I want as my first  position. The G201 has two parameters W and X.

W is the number of holes along the X axis.

X is the width between holes.

So this will give me 6 holes 10mm apart along the X axis.

I have aliased G201 to program O09011 which is my macro. Here’s how you do it in case you forgot.

This is program O9011

D01 END1

The line WHILE [#23 GT 1] DO1

Tells the control that as long as #23 is greater than 1 to go around the loop.

It’s now looking for END1 which corresponds to D01 and it whizzes around the loop.

You can have loads of these.

The END must match the D0.

It could be D02 & End2 the choice is yours. The D02 is just the name it’s nothing to do with how many times you go around the loop.

Just make sure you don’t get mixed up else you will have a nightmare trying to sort them out.

Each time it goes around the loop it checks the condition in the statement.

The line #23 = #23 -1 will reduce #23 by one each time it goes around the loop. (Eventually #23 will not be greater than 1 and the control will escape the loop and carry on)

The next line moves X incrementally (G91) by the amount stored in #24 (this was the X value you put in the G201). It drills a hole because the G81, stated in the main program, is still active.

The control is then put back into G90 (Absolute) as a safety measure.

Read this article for more on G and M code aliasing.

Now Lets Complicate Things

OK so you understood that?

Good now lets completely fuck it up.

D01 END1, This is the complete program.

First of all I drill one hole at X0 Y0, my first position same as above.

The G201 now has four parameters D,W and X, Y

D is the number of rows in Y.

W is the number of holes in X.

X is the width between holes along the X axis.

Y is the depth between holes along the Y axis.

So this should give me 6 holes 10mm apart in the X axis and 6 rows of holes 10mm apart in Y.

(A grid of holes)

 

More D0’s and Ends

Now we have D01 END1 inside D02 END2.

D01 END1

So……… the D01 END1 is the rows of holes across (X Axis).

The D02 END2 s the number of rows (Y Axis).

Now lets break it all down.

O09012 (Drill Grid of Holes)
G103 P1 (NO BLOCK LOOK AHEAD)

#100= #23 (Store W Value)

The line above puts #23 which was the W value into #100. This is because we are going to need it again when we go round the D01 END1 again. This loop reduces it down each time it goes around, so it needs to be restored.

WHILE [ #7 GT 0 ] DO2 (DO LOOP)

The line above is the condition that allows it to keep going around the loop as long as #7 is greater than zero.

WHILE [ #23 GT 1 ] DO1 (DO LOOP)
#23= #23 – 1 (COUNTER DECREASES BY ONE)
G91 X#24 (Drill a Hole)
END1

The D01 END 1 above is one row of holes once the condition is satisfied it escapes the loop.

#23= #100 (Restore W Value)

Remember we saved #24 in #100. you need to set this back to it’s original value because the loop above reduced it down to zero.

#24= – #24 (Reverse X)

This is to make the X move in the opposite way to make the path zig-zag. This will make it toggle between plus and minus.

#7= #7 – 1 (COUNTER DECREASES BY ONE)

The above is the counter for the rows. Number of rows was in D (#7) so wee need to reduce this number as we go.

IF [ #7 EQ 0 ] GOTO1
G91 Y#25
N1

This little bit of code above is for when we get to the last row of holes we don’t want the Y move as we have completed the grid.

END2

G103 P0 (RESTORE BLOCK LOOK AHEAD)
M99

It looks like this.

So there you have it. I hope you now have an understanding of how these loops work.

This kind of programming is notoriously difficult to get your head around. Once the penny drops it gets easier.

The problem is our brains are not too good at thinking about two things at the same time.

It’s called spaghetti programming for a reason.

My advice with all programming is to break the program down into small manageable chunks. Make simple little programs of each part and prove them till they work. You can the piece your program back together.

I hope you have enjoyed reading this article.

Thanks for watching and reading

If you have been affected by any of the issues in this post or need CNC Counselling then contact me.

Siemens 828 840 Sinumerik Training

Or call us 

If you want to learn to program CNC Milling Machines

Look no further Contact CNC Training Centre

 

 


Macro For Over 18 (Using Alias In a Macro)

Category : Macro

 

 

Macro programming can use a G code to access a 9000 series program.

Read this article if you don’t know about this.

 

In this example macro we are going to set G181 to access program 9010.

macro

 

We will create a new drilling cycle that can take into account the point of the drill in the drill depth.

The line below would call program 9010 from the G181

G181 A120. D16. R1. Z-20. F200.

It works the same as a G81 but with a drill point angle (A) and a drill diameter (D). It then goes on to use some simple trigonometry to calculate the drill point.

It feeds down to the Z depth then incrementally drills the extra bit for the drill point. Then it rapids back out.

G181 A120. D16. R1. Z-20. F200.

A (#1) = 120.
D (#7) = 16.
R (#18) = 1.
Z (#26) = -20.
F (#9) =200.

Remember the table below from the last article.

O09010 (Drill Point Macro)

G103 P1           (No Look Ahead)

(Letter A #1 = Drill Point Angle)
(Letter D #7 = Drill Diameter)
(Letter R #18 = Rapid Point)
(Letter Z #26 = Depth)
(Letter F #9 = Feedrate)

G00 Z#18           (Rapid To R Point)

G01 Z#26 F#9       (Feed to Z depth)

#100= #1 / 2                  (1/2 Drill Angle)
#100= TAN[ #100 ]     (Tan Of Half Drill Angle)

#101= #7 / 2                   (1/2 Drill Diameter)
#102= #101 / #100      (Calculate Extra Depth)

G91 Z – #102            (Extra Bit)
G90
G00 Z#18          (Rapid Back To R Point)

G103 P0           (Look Ahead On)
M99

Let me explain this macro line by line

O09010 (Drill Point Macro)

G103 P1 (No Look Ahead)

The G103 is so that the macro does not read in front and get confused, it will now only read block by block.

Always include an explanation with your macro in case you forget how it works.

(A #1 = Drill Point Angle)
(D #7 = Drill Diameter)
(R #18 = Rapid Point)
(Z #26 = Depth)
(F #9 = Feedrate)

G00 Z#18 (Rapid To R Point)

G01 Z#26 F#9 (Feed to depth at 200mm per minute)

The calculation below halves the drill angle. You will note that the drill angle is letter A which corresponds to #1

#100= #1 / 2     (1/2 Drill Angle)

Below will get  the tangent of the angle and this ends up back in #100 
#100= TAN[ #100 ]       (Tan Of Half Drill Angle)

Calculation below halves the drill diameter and puts it in #101

#101= #7 / 2       (1/2 Drill Diameter)

Macro, The Trigonometry

This is simple trigonometry and the answer is the depth of the drill point (Y).
Macro

In the diagram above
X is #101    (Radius of drill)
A is #100    (1/2 drill point angle)
Y is #102    (the bit we need to know)

#102= #101 / #100        (Calculate Extra Depth)

G91 Z – #102        (Feed down the extra amount calculated above incrementaly)
G90                      (Back to absolute)
G00 Z#18           (Rapid Back To R Point)

G103 P0         (Look Ahead Back On)
M99

Carry on If You Are Over 18

Earlier in the post I mention the “Grown Up World Of Macro”. That is because I often meet programmers who learn macro and use it just because they can. Oh and to confuse the shit out of the machine operators and other programmers.

You learned a bit of macro.

So fuckin what no one is impressed.

You can actually do more harm than good. As I have said in these posts before no one gives a flying fuck if you mess up the machine. Well apart from your boss (you know that bloke with the fat arse and the Porch 911).

Seriously (and I rarely am) if you want to write macros here’s what you need to do.

  1. Do you really need one or is it just your huge ego?
  2. Maybe you need to get out more?
  3. Will it confuse the operator?
  4. Can anyone use it?
  5. Is it simple for the user?
  6. Is it fool proof?

Let’s Look At My G181

Do you really need one or is it just your huge ego?
I think it could be quite useful to be able to allow for the drill point.

Maybe you need to get out more?
Definitely.

Will it confuse the operator?
No it’s very similar to a G81

Can anyone use it?
Yes

Is it simple for the user?
Yes my mum loves it and she’s 95.

Is it fool proof?
No definitely not we need to talk about this

Fool Proof

What if you missed out the Z value?

What if you had a minus value in R and a plus value in Z?

Would it still try and work if you input ridiculous figures?

Any of the above would completely screw it up. You could say “I’ll tell the operator to make sure he follows my rules”.

OK so if you just bought a new television and you accidentally pressed 12356 as a channel number.

What if the television just went off, or the screen locked up or it exploded and burnt down your house.

You would complain wouldn’t you. Us Brits can ignore this because we never complain. We’d probably ring up and thank them for the opportunity to build a new house.

Anyway we all know that the telly wouldn’t do that. It would either ignore you and treat you like the dipstick that you are. Or it would just go to channel 999 which is it’s highest channel.

Now this is not because Mr Sony is inside your telly thinking what to do if you make a mistake like shoving the remote control up your arse.

Your television has logic. This means in every scenario it knows what to do. It’s like the Bear Grylls of televisions.

So Let’s Look At Improving This

In a macro you can use a conditional statement. It’s like my wife said to me you either change your underpants every week or you piss off back to your mothers.

It gives choices.

Let’s Add This Line

IF [ #18 LT 0.0 ] GOTO999

What this means is that if #18, which is the R value, is less than 0 the control will jump to N999.

This means if you put a minus figure in R it would be less than zero and trigger the jump to N999.

N999 #3000= 1 (R LESS THAN ZERO PRICK!!)

#3000 puts the machine into an alarm state. The comment in brackets will be the alarm message and it looks like this.

This is how the program looks now.

%
O09010 (Drill Point Macro)

G103 P1 (No Look Ahead)

IF [ #18 LT 0.0 ] GOTO999

(Letter A #1 = Drill Point Angle)
(Letter D #7 = Drill Diameter)
(Letter R #18 = Rapid Point)
(Letter Z #26 = Depth)
(Letter F #9 = Feedrate)

G00 Z#18 (Rapid To R Point)

G01 Z#26 F#9

#100= #1 / 2 (1/2 Drill Angle)
#100= TAN[ #100 ] (Tan Of Half Drill Angle)

#101= #7 / 2 (1/2 Drill Diameter)
#102= #101 / #100 (Calculate Extra Depth)

G91 Z – #102 (Extra Bit)
G90
G00 Z#18 (Rapid Back To R Point)

N999 #3000= 1 (R LESS THAN ZERO PRICK!!)

G103 P0 (Look Ahead On)
M99
%

Now it doesn’t take much imagination to see that you could completely fool proof this macro.

Variable Zero

#0 is a unique variable because it means no value.

IF [ #18 EQ #0 ] GOTO998

If you put a statement like the one above it means if #18 is vacant (meaning it has no value).

Then the program will jump to N998.

N998 #3000= 2 (SORRY MY FRIEND, R HAS NO VALUE)

This is a much politer alarm and it saves a kick in the bollocks from the machine programmer.

Default Values In Your Macro

So for the no value scenario. You could make your  program jump to a line that gives a default value.

IF [ #18 EQ #0 ] GOTO123
GOTO124
N123 #18=1.
N124 

Take a moment to study the above code.

Come on get a grip do you understand it?

Now I’m from the old school of education. When I was a boy if you didn’t know the answer to the teacher’s question it was simple.

They beat the fuckin shit out of you.

And if you discount completely fucking up the planet and starting a lot of pointless wars my generation have done our kids proud.

Anyway today I’m going to be patient.

Let me explain…..

If you  are offended by any of the above please go to this website(this bloke writes much better stuff than me)

IF [ #18 EQ #0 ] GOTO123
GOTO124
N123 #18=1.
N124 

It’s very easy really, the first line will jump to N123 and set #18 to 1 if #18 has no value.

If however, there is a value in #18, then the control ignores the GOTO123 and reads the next line which jumps to N124 and carries on as if nothing ever happened.

Belt and Braces Things You Can Do

Check all of the following, what happens if…………

  • Values to high
  • Values to low.
  • No value entered
  • Letter missed out

You can set alarms if these conditions are not met or set default values.

It’s a bit like blackmail except for the bit where they have to leave a shit load of money in a phone box for you to pick up.

Things to Think About

Think of every dumb ass thing that your user could do with your macro.

Then make your macro respond in a adult way. So if he inputs daft information the macro sorts it out. It can use defaults or go into an alarm state with a message.

Keep the macro front end really simple, this is the bit the user sees and uses. For example my macro needs the radius of the drill for it’s calculation. You will note I ask the user to input the diameter.

Why?

Because it’s simple and easy for him and that’s what he will know. I can do all the work behind the scenes hidden away in my 9000 series program.

The front end.

G181 A120. D16. R1. Z-20. F200.

This bit is all he needs to worry about I take care of everything else. It’s like an all inclusive holiday. All you needs to do is eat sleep and constantly get pissed on cheap booze.

I hope you have enjoyed reading this article.

Thanks for watching and reading

If you have been affected by any of the issues in this post or need CNC Counselling then contact me.

Siemens 828 840 Sinumerik Training

Or call us 

If you want to learn to program CNC Milling Machines

Look no further Contact CNC Training Centre

 


G Code Alias M Code Alias (How to use them)

Category : Macro

G Code Alias. What is an alias Wikipedia?

Alias, it’s not just about James Bond

Alias, in the case of CNC Programming means you are using a G code or an M code to call a program.

For example you could set up G181 to call program O9010

G181 would be an alias for program O9010

These are special 9000 series programs and you set them in your parameters.

M Code Alias Fanuc Parameter 6080

G Code Alias Fanuc Parameter 6050

If you have a Haas machine it’s parameter 81 to 90 for M code alias.

It’s parameter 91 to 100 for G code alias.

So if you look above at parameter 91.

Then enter 181.

When you write G181 in a program or in MDI.

The control would go into program O9010

Therefore you can use a G code to access O9010 through to O9019. You can’t use any G code it has to be one that is not used.

 

It’s important to check that these 9000 programs are not used by things such as probing cycles. So be sure to check before altering.

The same thing applies with M codes (Programs 9000 to 9009).

You may be asking why you would want to do this. Well it means that you can fully automate your Macro.

You first of all place your macro code in one of these program numbers then when you want to use it you just use the G or M code you allocated to the program.

G Code Alias, M Code Alias, It Gets Way Better

Imagine you set 100 in parameter 81, when you issue an M100 the control will jump into program O9000

G Code Alias

This is very simple but you can see how exciting it can get. I didn’t sleep for a week when I first discovered this. Just make up your own M code to do any old shit you want.

In your parameters you can alter a setting so that 9000 programs can’t be viewed or edited. So no one gets to tinker with your precious code. Below is Haas but you can do it on any control.

Welcome to the grown up world of macro because now you can make an M code that an operator can freely use but never access or alter. So to him it’s just a regular M code.

Oh don’t forget to tell him what it does otherwise he’ll never be arsed to use it.

You may well ask why can you do this with M codes and G codes. Well with M codes that’s really all you can do.

Let me explain….

With a G Code Alias………

You can add parameters. You know like when you use a G81 drilling cycle.

G81 calls a program that drills holes. You control the depth and feed etc with parameters.

Once you call a G81 it knows all about drilling holes. Like when it gets to the bottom it has to get the hell out of there.

G81 Z-20. R1. F100

  • G81 calls the cycle
  • Z-20. is the depth
  • R1. is the point to rapid to
  • F100. is the feedrate

The Z the R and the F are the parameters that pass into the program.

With an M Code Alias………

None of the above. It’s just an M code. Very useful I must say but you can’t pass parameters to it.

Toolchange (Fanuc Controls)

Ever worked on a machine where you have to write extra code to stop the spindle and take the tool up to zero before you can tool change?

Well that’s what M6 does, just tool change.

What most machines do is use an alias for M6.

So it’s not really M6?

Nope…..

M6 uses an alias. So in your parameters you make M6 access a 9000 program. That way you can put any old bollocks in the 9000 program.

When you subsequently use M6 it goes into this program which contains everything you could ever want for a tool-change.

  • Stop spindle
  • Turn off coolant
  • Return Z to zero
  • Feed the dog
  • Change the tool

And all with just an M6.

If you have one of these old machines you could make your own alias.

G Code Alias Passing Parameters?

This is where it gets clever and it gets complicated.

But……

You have me to hold your hand.

OK so you set G181 to access program O9010.

G181 A50. C20. Z-10.

This G181 would pass the values of A, C and Z through to program 9010

9010 would then use the values to do it’s business.

Mmmmm how does that work?

These guys below are know as the macro variable gnomes and each one has his own letter and his own macro variable.

G Code Alias

If you think I’m joking then go into your programming department and ask them. Say you want to learn about the macro variable gnomes.

It took me ages to do those stupid fuckin gnomes. Then I realized it wasn’t even funny but I couldn’t bear to get rid of them.

Below is a table that shows the corresponding variable for each letter. Forget the gnomes, it’s just a failed experiment.

What this means is that if you put a value in A it will register in #1 and if you put a value in Z it will register in #26.

Then in your 9000 series program it can use those values. It’s like a secret way to get information into your macro program.

First of all put 181 in parameter 91.

G Code Alias

 

This means that G181 would call program O9010.

Lets create a drilling program the same s G81  we will call it G181.

It’s no different to G81 but it will demonstrate the use of Alias.

In other words it’s completely fuckin useless but at least I’ll get my point across.

G181 Z-20. R1. F200.

The G181 above will call O9010 and pass the values for Z, R and F into it.

#26 (Z)
#18 (R)
#9  (F)

Remember The List

G Code Alias

This is how O9010 Looks

O9010 (My Drilling Cycle)
G0 Z#18 
G1 Z#26 F#9
G0 Z#18
M99

Explanation

G181 Z-20. R1. F200.

O9010 (My Drilling Cycle Linked to G181)
G0 Z#18
#18 is the value passed from the letter R
R had a value of 1 so #18 is assigned the value 1
The machine will rapid to Z1.

G1 Z#26 F#9
#26 is the value passed from Z
Z had a value of -20. therefore #26 is assigned the value -20
Machine will feed to Z-20.
#9 is the value passed from the letter F
F had a value of 200 so #9 is assigned the value of 200
Machine will use a feed-rate of 200 mm per minute.

G0 Z#18 
#18 is the value passed from the letter R.
R had a value of 1 so #18 is assigned the value 1
Machine will rapid back to Z1.

M99

This is Only the Tip of The Iceberg

See this post for grown up Macro programming

Thanks for watching and reading

If you have been affected by any of the issues in this post or need CNC Counselling then contact me.

Siemens 828 840 Sinumerik Training

Or call us 

If you want to learn to program CNC Milling Machines

Look no further Contact CNC Training Centre


Haas Spindle Warm Up Macro

Category : Macro Useful Stuff

Warm up Programme

Haas Spindle Warm Up MacroHaas Spindle Warm Up Macro

This Haas Spindle Warm Up Macro is something I created recently for the Macro training course that we offer at the CNC Training Centre. The course covers Macro Programming suitable for Mazak, Haas and Fanuc.

This course will be available online soon.

Please fill out the enquiry form on the right if you are interested.

I must admit I often think that where Macro programming is concerned, a little knowledge is a dangerous thing. I just think it’s more about a programmer’s ego than really getting good code.

This article gives a brief description of macro programming if you just want the Haas Spindle Warm Up Macro then jump to the end and copy it. I won’t be offended, honestly.

Be Careful What you Wish for.

Gratuitous use of macro programming , can be dangerous and very confusing to the operator using it.

If you don’t know what gratuitous means don’t worry neither do I, I just heard a bloke say it on the telly.

  • Using a macro can automate a regular task.
  • Families of parts can be grouped together in one programme.
  • All macros need to be “fool proofed” you must add alarms to protect from erroneous input.
  • Use parameter s to lock and protect your macro programmes.
  • Macros can be aliased to G and M codes.
  • Don’t reinvent the wheel every day, just use a macro.
  • Don’t forget to check if you have the macro option on your machine it can be quite expensive to add on.

This macro (Haas Spindle Warm Up Macro) is for the warming up of the spindle on your Haas machine.

It does not take big leaps in speed so it’s smoother and more gradual.

Set the maximum rpm you want to warm up to and the time you want the warm up to run for. You also set the initial speed you want your spindle to start at from cold. Also give it the amount the speed increases per step.

It will calculate the difference between your start speed and your maximum speed. Then it divides this speed by the speed increment that you give it. From this it will know how many times to loop.

Once in the loop it uses the machine timer #3001. It zeros the timer then runs it for the calculated time each step.

Time needs to be set in milliseconds because that’s what the geeks use in these machine timers, so it multiplies by 60,000.

Ideally I suggest you alias it to an M code.

Alias what the fuck is an alias?

No it’s not like changing your name from Reginald Kenneth Dwight to Elton John no no it is a bit more sophisticated.

What does Alias mean.

It means you can access a programme using your own G code or M code.

Mazak Spindle Warm Up Macro

So for example see above. If you put 201 into parameter 91 when you programme a G201 it enters programme 9010. Like programming M98 P9010 or G65 P9010. With a G code you can pass arguments to the programme a bit like G81. In G81 you tell it the depth and rapid point these are the Z and the R values. These are called arguments. So now you can do the same with your very own G code.

G81 G98 Z-10. R1. F100.

Also for parameter 81 (see above) if you put 33 into parameter 81 when you programme M33 the control will jump into programme 9000. You cannot pass arguments when you use an M code. Best not to argue then, I say.

So for my Haas Spindle Warm Up Macro we will use M33 and alias it to programme 9000. So having done all this you can lock out programme 9000 so no one can even see it. (It can be our little secret). They will not be able to edit or delete it either.

All they need to know is that M33 will run the Haas Spindle Warm Up Macro.

M33 is aliased to O9000

A word about testing.

When you test your macro you don’t want your control to look ahead.

Why Does Your Programme Need to Look Ahead?

Let’s talk about cutter compensation:

Below is a tool path where the tool is compensated to the left. To machine the part without cutting into it the control would need to read in front.

Mazak Spindle Warm Up Macro

It moves up the left hand side so it needs to know where its going in advance, moving round the outside in single block it would stop here.

Mazak Spindle Warm Up Macro

If it were about to cancel compensation it would end here.

Mazak Spindle Warm Up Macro

If it were about to go left on the inside it would stop here.

Haas Spindle Warm Up Macro

They would all be the same Y position but in single block it would stop in three different places.

So this explains why the control needs to look ahead. Each move relies on the next one for it’s positioning.

When we write macro programmes and we are testing them this look ahead can be a real pain in the arse. You see the system often will know the answer before you think it has seen the question.

Complicated? Read on, I meant to confuse you so it makes me look intelligent.

Right , what we do is to use a G code that will stop the system from looking ahead. We can then single block through our macro and check the calculations as we go.

When we are happy with the code we can let the system look ahead again by turning look ahead back on.

Although what you are doing may be very simple in terms of calculations a very simple mistake can really bugger things up.

Be very systematic in your approach and test each section of your macro as you go. As you are happy that each line works move on to the next.

Try my Haas Spindle Warm Up Macro below. Turn off the block look ahead and the single block restriction and check each variable as it changes. It will help you to understand how the Haas Spindle Warm Up Macro works.

One other thing, plan your macro before you start don’t get too excited and rush on. Keep a record of what variables you have used so you don’t accidentally use a variable twice. Things can get very messed up if you do.

Comment, comment, and more comments to say what the comments mean. You can’t have too many comments in a macro. The best approach is to imagine you were abducted by aliens. Will anyone understand your code if they don’t bring you back to Earth?

If you are like me and you have the memory of a goldfish then you will need them for yourself when you look back at this macro in years to come.

Check out this fantastic article on how to lay out your CNC code and comments.

“The code, give me the code?”  you ask.

OK OK.

So here is my Haas Spindle Warm Up Macro.

Hope it is useful to you.

PLEASE DO NOT USE THIS MACRO IF UNDER 18 OR OF A NERVOUS DISPOSITION

Mazak Spindle Warm Up Macro

Oh by the way if you get bored easily then don’t read all this shit. Just put the code in your machine and enjoy it with my compliments.

Haas Spindle Warm Up Macro

O09000 (Haas Spindle Warm Up Macro)

G103 P1 (NO BLOCK LOOK AHEAD)

#3004= 7 (OVERRIDE CONTROL NOT ALLOWED)
#100= 20. (TIME)
#101= #100 * 60000. (TIME MILLISECONDS)

#102= 500. (RPM FROM COLD)
#103= 7000. (MAX RPM)
#104= #103 – #102 (RPM INCREASE)

#105= 1. (RPM STEP)
#106= #104 / #105 (LOOP)
#107= #101 / #106 (DWELL)
M03 S#102 (Start spindle at initial speed)

WHILE [ #106 GT 0 ] DO1 (DO LOOP)
S#102 (START SPINDLE AT INCREASED RPM)
#3001= 0 (RESET INTERNAL TIMER TO ZERO)

WHILE [ #3001 LT #107 ] DO2
END2

#106= #106 – 1 (COUNTER DECREASES BY ONE)
#102= #102 + #105 (INCREASE SPEED BY STEP)
END1

#3004= 0 (OVERRIDE BACK ON)

G103 P0 (NO BLOCK LOOK AHEAD)

M30 

Very boring so what does it all mean? You ask.

Explanation of my Haas Spindle Warm Up Macro

O09000 (Haas Spindle Warm Up Macro)

G103 P1 (NO BLOCK LOOK AHEAD)
(This will stop block look ahead)

#3004= 7 (OVERRIDE CONTROL NOT ALLOWED)
(Set this to a 7 to stop override of speed.)

#100= 20. (TIME)
(Total time of warm up in minutes)

#101= #100 * 60000. (TIME MILLISECONDS)

#102= 500. (RPM FROM COLD)
(Spindle will start at 500 RPM)

#103= 7000. (MAX RPM)
(Maximum RPM you want the warm up to reach)

#104= #103 – #102 (RPM INCREASE)

#105= 1. (RPM STEP)
(This in the step used as the RPM increases)

#106= #104 / #105 (LOOP)
(Calculate the number of times it goes around the loop)

#107= #101 / #106 (DWELL)
(Dwell time after each speed increase)

M03 S#102 (Start spindle at initial speed)

WHILE [ #106 GT 0 ] DO1 (DO LOOP)
S#102 (START SPINDLE AT INCREASED RPM)
#3001= 0 (RESET INTERNAL TIMER TO ZERO)

Haas Spindle Warm Up Macro

WHILE [ #3001 LT #107 ] DO2
(TIMER COUNTS DOWN BY DWELL TIME)
END2

#106= #106 – 1 (COUNTER DECREASES BY ONE)
#102= #102 + #105 (INCREASE SPEED BY STEP)

END1

#3004= 0 (OVERRIDE BACK ON)
(Override works again.)

G103 P0 (BLOCK LOOK AHEAD)
(This will put block look ahead back on)

M30

Single Block

You can stop single block from working in a macro.

It is really annoying if you expect your spindle to warm up in 20 minutes. You come back having made tea cos you left the machine in single block.

“Shit” (expletive of your choice) “the machines been on single block and stopped on 500 rpm for 20 minutes”

#3003= 1 (SINGLE BLOCK OFF)

#3003= 0 (SINGLE BLOCK ON)

Stop single block is used in a G84 tapping cycle. There is a thought, imagine using single block when tapping. (You may need to think about that one)

I also have suppressed spindle override because you want the correct speed in a warm up programme. So your override control won’t work until it’s cancelled again at the end of the macro.

Again this is used in G84.

If you read the code and explanations above you’ll see how it works.

Haas Spindle Warm Up Macro

Oh and by the way here is a similar article for a Mazak machine.

Services offered at CNC Training Centre

Workholding devices (design and manufacture of jigs and fixture). Pneumatic or hydraulic clamping systems.

Edgecam programming and training.

Turnkey full solutions (Programming, fixture design, tooling, fully working solution, including training)

Classroom programmer training.

Onsite CNC Machine Training.

CNC Programming and Training on all controls and machines.

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.

[contact-form-7 id=”2706″ title=”Contact Form”]

[contact-form-7 id=”2706″ title=”Contact Form”]


CNC Training Centre
WP to LinkedIn Auto Publish Powered By : XYZScripts.com