CNC Macro Introduction
There are two types of macro expressions: arithmetic expressions and conditional expressions.
An arithmetic expression is a mathematical formula involving variables and/ or constants (such as 0.12, 1.2, 12, 120, etc.), with or without functions (such as SIN, ACOS, SQRT, LN, etc. ).
A nested expression and the argument of a function must be enclosed within square brackets. Small brackets (parentheses) cannot be used because they are used for inserting comments in a program. An arithmetic expression evaluates to an arithmetic value.
1 + #2
#3 + #4 * SIN[30 * [#5 I 10 ]]
A conditional expression includes conditional operators (such as EQ, NE, and LT) between two variables/ constants/ arithmetic expressions. It must be enclosed in square brackets. It evaluates to either TRUE or FALSE (these are called Boolean values). A conditional expression is also referred to as a Boolean expression.
[#1 EQ 0]
[ [#2 + 1] LT [SIN * #3]]
The available macro variables cannot be used to store the result of a conditional expression. Only arithmetic values can be stored in macro variables. The Boolean TRUE/FALSE is not equivalent to the arithmetic 1/0.
#1 = 10; (Stores 10.000 in variable #1)
#2 = [ 1 LT 2] ; (illegal, as TRUE or FALSE cannot be stored in a variable)
|You may be interested also:|
|“CNC | Programming Formats”|
Things to Know
The manual data input (MDI) panel usually has just one key for the left bracket and another one for the right bracket. While typing, whether the bracket will appear as a square bracket or a parenthesis, depends on your parameter setting. If the machine has Fanuc Oi or Oi Mate control, set the first bit (from right), which is conventionally referred to as bit #0 (the eight bits are designated as #0 through #7, starting from the right), of parameter number 3204 to 0 for a square bracket, and 1 for a parenthesis.
The default setting for the remaining bits is 0, which is not shown, for the purpose of highlighting what requires to be edited (i.e., bit #0). Obviously, it would not be possible to use square brackets and insert comments at the same time with this parameter setting. If some comments are desired to be inserted in a macro program, first type / edit the program using square brackets, wherever required. Then change the parameter setting to get parentheses, for the purpose of inserting comments. After inserting comments, if again some corrections in the program involving square brackets are needed, another change in parameter 3204 would be required.
There is, however, a way to use both types of brackets, with the same parameter setting. For this, set parameter 3204#2 to 1 (3204#0 should remain 0; status of the other six bits does not affect this feature) :
Such a parameter setting displays an extended character set, as soft keys, in the EDIT mode, displaying “(“, “)” and “@”. With this setting, if square brackets are needed, use the bracket keys on the MDI panel, and if parentheses are needed, do the following (in EDIT mode):
- Press PROG on MDI panel (press PROG again if the current program is not displayed).
- Press the OPRT soft key.
- Press the right extension key(..,.. ) twice.
- Press the C-EXT soft key.
After this, soft keys for left parenthesis, right parenthesis, and @ (which can be used in the comments inserted in a program) will appear which can be used as and when required for editing in EDIT mode. However, a change in display screen will make these soft keys disappear. If they are needed again, the process to display them will have to be repeated.
Note that the MDI panel and the LCD screen (color or monochrome) come as an integral unit as well as separate units. The standalone type MDI panel is larger and has more keys. So, there is a lesser need to use the SHIFT key for typing alphanumeric characters/ arithmetic operators, which makes typing faster. The keypad also has separate keys for both types of brackets, obviating the need for displaying soft keys for them.
Coming back to the discussion about macro expressions, an arithmetic expression evaluates to a positive or negative arithmetic value, following the usual priority rule:
bracket (innermost first) > function evaluation > division and multiplication > addition and subtraction.
Mixed mode arithmetic, that is, calculations involving both real and integer numbers, is permitted, which results in a real number. In fact, the control stores even an integer number as a real number, with zeroes after the decimal point. So, for example, 10 is equivalent to 10.0, and these can be used interchangeably in all arithmetic calculations.
Note that this statement is valid only for arithmetic calculations. For example, X10 may be interpreted as 10 mm or 10 micron (in millimeter mode), depending on whether parameter 3401#0 is 1 or 0.
The negative of the value stored in a variable can be used by putting a minus sign before the variable address, but two consecutive arithmetic operators (+, -,*,and / ) are not allowed. In such cases, square brackets will have to be used:
– #1 + 10 (A valid expression)
10 + -#1 (An invalid expression)
10 + [-#1] (A valid expression)
A variable can also be designated in terms of another variable or an arithmetic expression, which must be enclosed within square brackets:
#[#1] (#1 should contain a number in the permissible range. If, for example, #1 contains 10, then #[#1] is equivalent to #10. ##1 is illegal)
#[#1+10] (If #1 contains 10, then the referred variable is #20)
The designation number of a variable is an integer quantity. If a real value is specified (which is only a theoretical possibility, as this situation would never arise in any practical application), it is automatically rounded to the nearest integer (refer to Sec. 2.3 for the methods of assigning a value to a variable):
#1 = 1.4999999; (Stores 1.4999999 in variable #1)
#[#1] = 1.5000000; (Stores 1.5000000 in variable #1)
#[#1] = 1; (Stores 00001.000 in variable #2. A variable stores and displays a value using eight digits, with three digits after the decimal, unless the value cannot be expressed in this format)
#0.4999999 = 1; (Illegal command because it tries to assign a value to variable #0.Variable #0 is a predefined, read-only type null variable, which cannot be redefined.)
#0.5000000 = 1; (Stores 00001 .000 in variable #1)