Created and Maintained by the Real World Software Developers and Machinists at ... click here to check it out !!

Wednesday, July 31, 2013

Fanuc Macro Programming Series - Part #3 : Local & Common Variables

Part #3 in our Fanuc Macro Programming Series is dealing a little bit more in-depth with the definition and use of Local Variables and Common Variables

Local Variables are so named because they are used "locally" in a macro program. This means that the value of the local variable is retained only in the program for which it was assigned. Values of local variables are not retained when branching out to other sub programs.

Local variables are primarily used for data transfer or for intermediate calculations within a macro. The table below represents the local variable available LETTER ADDRESS and corresponding NUMERICAL ADDRESS contained in the macro program. Local variables are assigned either through the use of the G65 command or by direct data input. All local variables are "vacant" unless assigned, and can be freely used by the user.

Program Example using Local Variables :

Assignment by Macro Call :
Macro Call : 
G65 P1234 A2.00 B5.00 ;
Result :  
G65 call assigns the value of 2.00 to local variable #1 ( A )
G65 call assigns the value of 5.00 to local variable #2 ( B )

Program Command :
G01 X#1 F#2
Actual Command :
G01 X2.00 F5.00

Direct Assignment by Program Command :
Macro Statement : 
#1 = #2
Result :
Direct assignment of variable #1 set to the value of variable #2

Intermediate Calculation within a Macro :
Macro Statement : 
#1 = #2 + #3
Result :
Variable #1 is equal to the sum of variables #2 and #3


Common Variables are different from local variables in that once a value is assigned, that value is shared by all other macros and the values are not cleared at M30 or RESET. This means that #100 used in one program is the same value of #100 used in another program. In addition, if the value of a common variable is calculated in one macro, that value is retained when called in another macro.

The main important feature of common variables lies in the fcat that they can be used between macros and that their values are not cleared at M30 or RESET. Users should be careful when performing calculations with common variables because when the program is re-started, the value of common variables is retained from any previous calculations and may produce unexpected results. Common variables can be freely used by the user.

#100 thru #149
These variables are cleared at power off

#500 thru #549
These variables retain their value even after power off.


Stay Tuned for more ... 

Monday, July 15, 2013

Fanuc Macro Programming Series - Part #2 : Variables

What Are Variables
The Fanuc Custom Macro language uses a variety of what are called VARIABLES in the language. Variables can perform a variety of chores in the language, their main job is to carry and gather data for use in the macro program.

A Variable always begins with the # sign, followed by a number. For example, #100 is a variable. In it's simplest form ( without getting into specifics of how that is done ... it will be covered later ), a variable is used to carry data. An example :

First Program Line : #100 = 2.00
Second Program Line : G01 G90 X#100 F10.0

In the above example, the macro program first defines the value of the variable #100 ... that value is 2.00 as defined in the First program line. The variable #100, carrying the value of 2.00, is called or used in the Second program line. To the control, the value of the Second program line is :

G01 G90 X2.00 F10.0

Once the variable is defined ( without getting into specifics of how that is done ... it will be covered later ) anytime the control sees the variable, it replaces it with it's defined value, in this case 2.00.

To take this just a step further ... remember anytime the control sees the variable #100 it will substitute it's defined numerical value, the following line :

G01 G90 X#100 F#100

would read to the control :

G01 G90 X2.00 F2.00

As mentioned, variables have other functions as well. The types of variables available will be discussed in more detail in various posts in our series.

Types of Variables
There are basically (3) different types of variables available ... the type to utilize is dependant on how you want the data to be transmitted.

Local Variables
( # 1 thru #33 )
Local variables are primarily used for data transfer and their value remains active only within the local program. When a sub-program is executed, the value of the Local Variable does not carry over into the sub-program. The value of a Local Variable is usually set using the G65 macro call command.

Common Variables
( # 100 thru #149 and #500 thru #509 )
The main difference between Common Variables and Local Variables are that Common Variable values are retained between programs. That means that the #100 used in one program is the same in every other program or sub-program called. The value of any Common Variable, even if arrived at via a mathematical instruction, is the same value in subsequent program use.

The value of variables #100 thru #149 are cleared at power off, while those of variables #500 thru #509 are retained, even after power off. However, these conditions may be altered via Parameter Settings.

System Variables
System Variables are normally used to obtain conditions, positions or values from areas within the CNC control. Some examples of the use of System Variables :
  • To record an axis position at a certain time
  • To record or adjust a tool offset value
  • To record or adjust a work coordinate offset setting
  • To generate s user defined alarm condition 
  • Suppress the single block, feed hold, feedrate override functions
  • Read and record modal information
Stay Tuned for more in our series !!

Tuesday, July 2, 2013

Fanuc Macro Programming Series - Part #1 : Basics

R U Sitting Down ??
OK then Buckle up !!!

We are about to begin a long ... somewhat complex ... but very beneficial series teaching the how's ... why's ... and details of the Fanuc Macro B Programming Language. If you do CNC programming and are utilizing a Fanuc Control ... your review and understanding about what we are about to present will definitely send you to the next level of CNC programming.

Over the next months ... we will be interspersing articles in this series covering Fanuc Macro B programming from the basics to the complex. We will still be including and sharing some of our sought after CNC Tips and Tricks ... but we will also be including articles in this series as we go along as well.

So check back often ... follow along ... and hopefully we can help bring your CNC programming skills to the next level.

P.S. - A lot of the information here is included in our KipwareEDU® - CNC Programming Training & Reference Software - Macro Version. So if you like what you see here ... and there's tons more in KipwareEDU® ... you can purchase the Macro Version of KipwareEDU® and have this information at your disposal on your own PC ... or use it to tech your personnel. KipwareEDU® contains the info here and tons more along with in-depth video training not included here.

Part One : The Basics
What is Fanuc Custom Macro B ?
Custom Macro is the name given by Fanuc to it's programming language that enables users to take the standard G code programming to another level. Custom Macro allows users to include instructions, mathematical equations, changing variables and a host of other advanced functions in a G code program.

Because of the power of this language, anytime a thought occurs like " I just need to repeat what I did here" or similar, it's probably a good time to consider using custom macro programming. Some examples where Custom Macro programming can be employed :

  • Dimensions or other values require calculations or re-calculations "on the fly". 
  • The programming of family of parts or parts that repeat the basic operations but contain only dimensional changes.
  • Dimensions or other values need to be stored or transferred to other addresses in a program.
  • Complex operations where the basic pattern or cutting sequence remains the same ... an example would be pocketing ... but dimensional changes, that can be defined by one or a series of mathematical formulas, need to be re-calculated "on the fly".
  • The basic "rule of thumb" is that Macro programming probably can be utilized anywhere where repetition exists.

As you explore this series, we will bring out many instances where macro programming can and should be employed ... but we are also sure that these will open doors to macro programming examples in your own world as well. Keep an open mind !!!!

Macro Programming vs. Sub Programming
There are similarities and many differences between a CUSTOM MACRO program and a standard SUB PROGRAM. We outline in this chapter some of the major differences and similarities.

  • Both types can be called from another program.
  • Both types are stored in memory  under their own program number.
  • Both types can be called to repeat a pre-determined number of times.
  • Both types can be called multiple times from other sub or macro programs.
  • Both types end with the M99 command.
  • Macro program body can perform and contain mathematical equations.
  • Macro program calls can establish values for variables used in the macro program. 
  • A macro program can be called and made "modal" to repeat until the cancel command is issued.
  • Macro programs can be called from user defined G, M and T codes via parameter settings.
The creation of a custom macro program is identical to the creation of a sub program. Both types are registered to the memory under their own program number and stored separately in the memory. As with sub programs, the end of the custom macro program is done through the use of the M99 command.

OK ... there are some basics. If you have questions ... I'm sure we will address them in the coming articles.

SOOO ... stay tuned for even Happier Chip Making !!