Using Macro System Variables

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”]

 


Log out of this account

Leave a Reply

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