Variables, Math, Marcos, Jumps and G code usage.
There are numerous sections of the manuals that cover these topics.
Usage and Syntax does change between the Graphical OI, CNC Lite, Plus and Professional versions. All of the commands are the same syntax between each package, but the degree of access and power changes. For example a subset of FANUC variables and Macros are only available in the CNC Professional, while CamSoft variables and macros are available in all versions. The JUMP command is available in all versions and the syntax in the same. See below for instructions and examples for proper usage.
The documentation is lengthy, so we are only providing a limited answer below. The best way to find answers is to electronically search using the Search for Solutions button on CNCsetup.exe or Setup.exe. You can search for answers using key words like a web-browser.
QUESTION 121
Can I use variables and/or do math in my G Code Program?
The controller does have the ability to store unlimited variable names. A legal variable name is a name that begins with any letter of the alphabet. To save a value to a variable in a G Code program, enclose the math and the variable name followed by an equal sign (=) inside curly braces {}. For example, to store 5.5 to the variable
KEEPME: {KEEPME=5.5}
For example, to do math to an existing X axis coordinate in a G Code line where X needs to have .75 added to its value, write the G Code line like this: N100 G01 X{5.5+.75} Y6.2 F30
For example, to add the value of a variable to an existing X axis coordinate in a G Code line, enter: N100 G01 X{5.5+KEEPME} Y6.2 F30
For example, pre-store the values of variables at the top of the program.
At the top of the program:
{FIRSTX=3.489}
{SECONDY=-4.555}
{NUMOFPARTS=1}
For example, to add the variable FIRSTX to the X axis coordinate in your G Code program, enter: N100 G01 X{5.5+FIRSTX} Y5
QUESTION 197
What are the limitations of subprograms and variables within the G code program?
You should first be aware that we allow two formats to be used to assign variables, call macros and do math within the G code program.
Curly Braces { } or Fanuc Style Square Brackets [ ] may be used in macros or to perform math equations. Named variables can be replaced by FANUC style # numbered variables.
Example #1
{MYNAME=45*TAN(MYVARB)}
Same as:
Example #2
#9=45*TAN[#151]
Whereas:
#9 same as MYNAME
#151 same as MYVARB
[ ] same as { } or ( )
These variables, in either named or numbered formats, are public/global throughout the entire time the computer remains on even between different G code programs. They will only be erased when you exit the CNC or overwrite them.
There are three types of variables: LOCAL, USER and SYSTEM variables. LOCAL variables: These are variables that are only available locally within each subprogram. If you call a subprogram with M98, the variables in the main program are not seen by the subprogram. They are not shared. Variables automatically become local when they are placed inside a subprogram.
USER variables: Are seen by all G code programs since the computer has been turned on. They are known as public or global and can be shared.
SYSTEM variables: Are for the installer's internal use only in logic routines. All variables in the G code program are also kept totally separate from the SYSTEM variables that the installer used within the internal system logic. The user cannot change the SYSTEM variable values; however, the installer does have access to the USER variables and can internally read and set the USER variables within the G code program.
Subprograms called using M98 or the command GOSUB must be complete enough to be able to run on their own, by themselves, including the use of user variables in G code, G41, G42, SmartPath or the 3-5 axes tool comp features.
To access a SYSTEM variable from a G code program:
Whereas in logic a SYSTEM variable gets assigned like this:
\100={100+10}
To make a SYSTEM variable such as \100 accessible to a G code program, reassign it to a named USER variable:
{SIZE=\100}
From within the G code program you would write this:
G00 X{SIZE}
Other Examples
When using names as variables for math functions, note where we are using the {} and () characters because the placement of these are important for it to work correctly. LDANG is a named variable that can be used in a G code program and read into logic for calculation or directly used in the G code program. Note that the \112 variable is not valid in a G code program, only in logic files. Refer to the “Pre-Programmed G & M Programming Codes” section in this manual for examples on Fanuc style macro named variables that can be used with trig functions.
{LDANG=45.0}
\112={\110*COS(LDANG)/SIN(LDANG)}
See the 2 pages Titled "Example of macro variables used in G code program."
QUESTION 49
How do I write logic to use a value entered by the user in a text box on the screen?
QUESTION 237
How can we ask the user a question so that the answer can be used in a G code program?
JUMP
This command enables the user to jump or switch the execution of the G code program to a specific G code line that contains a match for the parameter after the JUMP command. The parameter may be a line number, an axis position, a certain feed rate or spindle speed or just about any identical match that can be found in a G code line. The object you are jumping to must appear first in the line of G code. When found, the program will start executing at the line where the match was found. It is important that there is a space following the search item in the G code program.
EXAMPLE: JUMP N350
Tech Support
CamSoft Corp.
951-674-8100
[email protected]
(Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)