One, variables
Ordinary machining programs directly specify G codes and moving distances with numerical values; for example, GO1 and X100.0. When using a user macro program, the value can be specified directly or with a variable. When using variables, the variable value can be changed by program or by operation on the MDI panel.
For example: #1=#2+100; G01 X#1 F300
(1) Representation of variables
The computer allows the use of variable names, but not user macro programs. Variables are designated with variable symbols (#) and the following variable numbers.
For example: #1
Expressions can be used to specify variable numbers. At this time, the expression must be enclosed in parentheses.
For example: #[#1+#2-12]
(2) Types of variables
Variables can be divided into four types according to the variable number:
1) #0 Empty variable, this variable is always empty, no value can be assigned to this variable.
2) #1-#33 Local variables, local variables can only be used to store data in macro programs, for example, calculation results. When power is off, local variables are initialized to empty. When the macro program is called, the argument is assigned to the local variable.
3) #100-#199, #500-#999 public variables, which have the same meaning in different macro programs. When the power is off, the variables #100-#199 are initialized to empty. The data of variable #500-#999 is saved, even if the power is off, it will not be lost.
4) #1000--- system variables. System variables are used to read and write the changes of various data during CNC operation, for example, the current position of the tool and the compensation value.
(3) Range of variable value
Local variables and public variables can have 0 values or values in the following ranges: -1047 to -10-29 or -10-2 to -1047. If the calculation result exceeds the valid range, P/S alarm No. 111 will be issued.
(4) Omission of decimal point
When defining variable values in the program, the decimal point can be omitted.
Example: When definition #1=123; the actual value of variable #1 is 123.000.
(5) Reference of variables
To use variable values in the program, specify the address followed by the variable number. When specifying a variable with an expression, put the expression in parentheses.
For example: G01X[#1+#2]F#3;
The value of the referenced variable is automatically rounded according to the minimum setting unit of the address.
For example: when G00X#/; is executed in the unit of 1/1000mm, CNC assigns 123456 to variable #1, and the actual command value is G00X12346.
To change the sign of the value of the reference variable, put the minus sign (-) in front of #.
For example: G00X-#1
When referencing undefined variables, the variables and addresses are ignored.
For example: when the value of variable #1 is 0 and the value of variable #2 is empty, the execution result of G00X#1 Y#2 is G00X0.
(6) Common variables of dual trajectory (dual trajectory control)
For dual-track control, the system provides a separate macro variable for each track. However, according to the settings of parameters No. 6036 and 6037, some common variables can be used for two tracks at the same time.
(7) Undefined variables
When the variable value is undefined, such a variable becomes an empty variable. Variable #0 is always an empty variable. It cannot write, only read.
(A) Quote
When referencing an undefined variable, the address itself is also ignored.
When #1=<empty> When #1=0
G90 X100 Y#1
↓
G90 X100 G90 X100 Y#1
↓
G90 X100 Y0
(B) Calculation
Except for assignment with <empty>, <empty> is the same as 0 in other cases.
When #1=<empty> When #1=0
#2=#1
↓
#2=<empty> #2=#1
↓
#2=0
#2=#*5
↓
#2=0 #2=#*5
↓
#2=0
#2=#1+#1
↓
#2=0 #2=#1+#1
↓
#2=0
(C) Conditional expression
The <empty> in EQ and NE is different from 0.
When #1=<empty> When #1=0
#1EQ#0
↓
Established #1EQ#0
↓
invalid
#1 NE #0
↓
Established #1 NE #0
↓
invalid
#1 GE #0
↓
Founded #1 GE #0
↓
invalid
#1 GT #0
↓
Not established #1 GT #0
↓
invalid
(8) Restrictions
Program number, sequence number and optional block jump number cannot use variables.
Example: Variables cannot be used in the following situations:
0#1;
/#2G00X100.0;
N#3Y200.0;
2. Arithmetic and logical operations
The operations listed below can be performed in variables, and expressions can include constants and or variables composed of functions or operators. Variables #j and #k in the expression can be assigned with constants. Variables can also be assigned with expressions.
Definition: #i=#j
Addition: #i=#j+#k;
Subtraction: #i=#j-#k;
Multiplication: #i=#j*#k;
Division: #i=#j/#k;
Sine: #i=SIN[#j];
Arc sine: #i=ASIN[#j];
Cosine: #i=COS[#j];
Arc cosine: #i=ACOS[#j];
Tangent: #i=TAN[#j];
Arctangent: #i=ATAN[#j];
The angle is specified in degrees: 90°30' means 90.5 degrees.
Square root: #i=SQRT[#j];
Absolute value: #i=ABS[#j];
Rounding: #i=ROUNND[#j];
Round up: #i=FIX[#j];
Round down: #i=FUP[#j];
Natural logarithm: #i=LN[#j];
Exponential function: #i=EXP[#j];
Or: #i-#jOR#k;
XOR: #i-#jXOR#k;
With: #i-#jAND#k;
Logic operations are performed bit by bit according to binary numbers.
Convert from BCD to BIN
Convert from BIN to BCD #i=BIN[#j];
#i=BCD[#j];
Used for signal exchange with PMC.
Description:
● Angle unit
The angle unit of the functions SIN, COS, ASIN, ACOS, TAN and ATAN is degrees. For example, 90°30' means 90.5 degrees.
● ARCSIN # i= ASIN[#j]
1) The value range is as follows:
When the parameter (NO.6004#0) NAT bit is set to 0, 270°~90°
When the parameter (NO.6004#0) NAT bit is set to 1, -90°~90°
2) When #j exceeds the range of -1 to 1, P/S alarm NO.111 will be issued.
3) Constant can replace variable #j
● ARCCOS #i=ACOS[#j]
1) The value range is from 180°~0°
2) When #j exceeds the range of -1 to 1, P/S alarm NO.111 will be issued.
3) Constant can replace variable #j
● ARCTAN #i= ATAN[#j]/ [#k]
1) Specify the length of the two sides and separate them with a slash (/)
2) The range of values is as follows:
When the NAT bit (parameter NO.6004, #0) is set to 0; 0° to 360°
When the NAT bit (parameter NO.6004, #0) is set to 1, -180° to 180°
3) Constant can replace variable #j
● Natural logarithm #i=LN[#j];
1) Note that the relative error may be greater than 10-8.
2) When the antilog (#j) is 0 or less than 0, P/S alarm NO.111 is issued.
3) Constant can replace variable #j.
● Exponential function #i=EXP[#j]
1) Note that the relative error may be greater than 10-8.
2) When the calculation result exceeds 3.65X1047 (j is approximately 110), an overflow occurs and P/S alarm No. 111. is issued.
3) Constant can replace variable #j.
● ROUND (rounding) function
1) When the arithmetic operation or logic operation instruction IF or WHILE contains the ROUND function, the ROUND function is rounded at the first decimal position. When executing #1=ROUND[#2]; here #2=1.2345, the value of variable 1 The value is 1.0.
2) When the ROUND function is used in the NC statement address, the ROUND function rounds the specified value according to the minimum setting unit of the address
● Round up and round down
When CNC processes numerical calculations, if the absolute value of the integer generated after the operation is greater than the absolute value of the original number, it is rounded up; if the absolute value of the original number is less than the original number, it is the lower integer. Be careful when handling negative numbers.
● Abbreviation for arithmetic and logic operation instructions
When instructing a function in a program, the first two characters of the function name can be used to specify the function.
ROUND→RO
FLX→FI
● Operation sequence
1) Function
2) Multiplication and division operations
3) Add and subtract operations
● Nested parentheses
The parentheses are used to change the order of operations. The parentheses can use 5 levels, including the parentheses used inside the function. When the 5 levels are exceeded, the P/S alarm NO.118 will appear.
● Parentheses ([,]) are used to enclose expressions. Note that parentheses are used for comments.
● Calculation error During calculation, errors may occur.
Note: The relative error depends on the operation result; the smaller of the two types of errors is used; the absolute error is a constant, regardless of the operation result; the function TAN executes SIN/COS.
If the operation result of the SIN/COS or TAN function is less than 10X10-8 or the operation accuracy is not 0 due to the limitation of operation accuracy, set parameter NO.6004#1 to 1, and the operation result can be calculated as 0.
1) The precision of the variable value is about 8 decimal digits. When dealing with very large numbers in acceleration/deceleration, the expected result will not be obtained.
2) You should also be aware that the use of conditional expressions EQ, NE, GE, GT.LE and LT may cause errors.
3) Be careful when using the next rounding instruction.
● Divisor When a divisor of 0 is specified in division or TAN[90], P/S alarm NO.112 appears
3. Macro program statement and NC statement
The following blocks are macro program statements:
◆ Program segments containing arithmetic or logical operations (=).
◆ Program segment containing control statements
◆ The program segment containing the macro program call instruction
Any block except macro program is NC statement
Description:
● Difference from NC sentence
(1) The machine tool does not stop even if it is placed in the single block mode. However, when the parameter No. 6000#5SBM is set to 1, in the single block mode, the machine tool stops.
(2) In the tool radius compensation mode, the macro program block is not treated as a non-moving block.
● NC statements with the same properties as macro statements
(1) NC statements containing subroutine call instructions but no address instructions other than O, N or L addresses have the same nature as macro programs.
(2) The nature of the block that does not contain instruction addresses other than ONP or L is the same as the macro program statement.
Fourth, transfer and circulation
In the program, use GOTO statement and IF statement to change the flow of control. There are three kinds of transfer and loop operations available;
Transfer and loop GOTO statement (unconditional transfer)
↓→IF statement (conditional transition)
WHILE statement (loop when...)
(1) Unconditional transfer (GOTO statement)
Transfer to the block marked with sequence number n. When a sequence number other than 1 to 99999 is specified, P/S alarm No. 128 appears. The sequence number can be specified by expression.
GOTOn; n: sequence number (1 to 99999)
(2) Conditional transfer (IF) statement
Specify the conditional expression after IF.
IF[<conditional expression>]GOTOn If the specified conditional expression is satisfied, move to the block marked with sequence number n. If the specified conditional expression is not satisfied, execute the next block.
IF[<conditional expression>]THEN If the conditional expression is satisfied, execute the predetermined macro program statement. Only one macro program statement is executed.
Description:
● Conditional expression
Conditional expressions must include operators. Operators are inserted between two variables or between a variable and a constant, and are enclosed with parentheses ([,]). Expressions can replace variables.
● Operator
The operator consists of 2 letters and is used to compare two values to determine whether they are equal or whether one value is less than or greater than the other. Note that the not sign cannot be used.
(3) Loop (WHILE statement)
Specify a conditional expression after WHILE. When the specified condition is met, execute the program from D0 to END. Otherwise, go to the block after END.
Description:
When the specified conditions are met, the program between WHILE from D0 to END is executed. Otherwise, the program segment after END is executed. This instruction format is suitable for IF statements. The number after D0 and the number after END are the specified program The label of the execution range, the label value is 1, 2, 3. If a value other than 1, 2, 3 is used, P/S alarm No. 126 will be generated.
● Nesting
The label in the DO-END cycle can be used as many times as needed. However, when the program has a cross-repetition cycle (overlap of the DO range), the P/S alarm NO.124 appears.
Description:
◆ Infinite loop When DO is specified but no WHILE statement is specified, an infinite loop from DO to END is generated.
◆ Processing time When there is a sentence with a label transfer in the GOTO sentence, the sequence number search is performed. The reverse search time is longer than the forward search. Using the WHILE sentence to realize the loop can reduce the processing time.
◆ Undefined variables In conditional expressions using EQ or NE, <empty> and zero have different effects. In other forms of conditional expressions, <empty> is treated as zero.
◆ Typical program The following program calculates the sum of values 1 to 10.
00001;
#1=0;
#2=1;
WHILE[#2LE10]DO 1;
#1=#1+#2;
#2=#2+1;
END 1;
M30;
Five, macro program call
Use the following method to call the macro program:
Macro program call
Non-modal call (G65)
Modal call (G66, G67)
Call macro program with G code
Call macro program with M code
Call subroutine with M code
Call subroutine with T code
● The difference between calling a macro program and calling a subprogram
The macro program call (G65) is different from the subprogram (G68), as described below:
1) With (G65), you can specify the argument (data is transferred to the macro program). M98 does not have this function.
2) When the M98 block contains another NC command, the subprogram is called after the command is executed. On the contrary, G65 unconditionally calls Use macro programs.
3) When the M98 block contains another NC command, the machine tool stops in the single block mode. On the contrary, the G65 machine tool does not stop.
4) Use G65 to change the level of local variables. Use M98 to change the level of local variables.
(1) Non-modal call (G65)
When G65 is specified, the user macro program specified by address P is called. The data can be transferred to the user macro program body.
Description:
1) After G65, use the address P to specify the program number of the user macro program.
2) When repetition is required, specify the number of repetitions from 1 to 9999 after the address L. When the value of L is omitted, L is considered equal to 1.
3) Specify using an independent variable, and its value is assigned to the corresponding local variable.
● Independent variable specification
Two forms of independent variable specification can be used. The independent variable specification I uses letters other than G, L, O, N and P, and each letter is specified once. The independent variable specification II uses A, B, C and I, J and K (i is 1-10). According to the letter used, the type specified by the argument is automatically changed.
Argument specification I
1) Addresses G, L, N, Q and P cannot be used in arguments.
2) Addresses that do not need to be specified can be omitted, and the local variables corresponding to the omitted addresses are set to be empty.
3) The address does not need to be specified in alphabetical order, but should conform to the format of word address. But I, J and K need to be specified in alphabetical order.
Argument address II
Independent variable specification II uses A, B, and C once each, I, J, and K 10 times. Independent variable specification II is used to transfer variables such as three-dimensional coordinate values.
The subscripts of I, J, K are used to determine the order in which the independent variables are specified, and are not written in actual programming.
limit:
◆ Format: G65 must be specified before any independent variable
◆ A mixture of independent variable designation I and II The CNC automatically recognizes the independent variable designation I & the independent variable designation II. If the independent variable designation I and the independent variable designation II are mixed and designated, the later-specified argument type is valid.
◆ The unit of the argument data without a decimal point at the position of the decimal point is the smallest setting unit of each address. The value of the transmitted argument without a decimal point changes according to the actual system configuration of the machine tool. Using the decimal point in the macro program call can make the program compatible Great.
◆ Call nesting: call can be nested in 4 levels, including non-modal call (G95) and modal call (G66). But not including subroutine call (M98).
◆ Level of local variables:
1) The nesting of local variables ranges from 0 to 4.
2) The main program is level 0.
3) Every time the macro program is called, the local variable level is increased by 1. The local variable value of the previous level is saved in the CNC.
4) When M99 is executed in the macro program, the control returns to the calling program. At this time, the local variable level is reduced by 1; and the local variable value saved when the macro program is called is restored.
◆ Typical program: Make a macro program to process the holes on the wheel circle. The radius of the circle is I. The starting angle is A, the interval is B, the number of holes is H, and the center of the circle is (X, Y). The command can be absolute Specify the value or increment. B should specify a negative value when drilling clockwise.
◆ Calling format: G95P9100 Xx Yy Zz Rr Li Aa Bb Hh;
X: X coordinate of the center of the circle (specification of absolute value or incremental value) (#24)
Y: Y coordinate of the center of the circle (specification of absolute value or incremental value) (#25)
Z: hole depth (#26)
R: Fast approach point coordinates (#18)
F: Cutting feed rate (#9)
I: circle radius (#4)
A: The angle of the first hole (#1)
B: Incremental angle (clockwise when a negative value is specified) (#2)
H: Number of holes (#11)
◆ Macro program call program:
O0002;
G90 G92 X0 Y0 Z100,0;
G65 p9100 X100 Y50.0 R30.0 Z50.0 500 I100.0 A0 B45.0 H5;
M30;
◆ Macro program
09100;
#3=#4003;Store 03 group G codes
G81 Z#26 R#18 F#9 K0; (Note) Drilling cycle
Note: L0 can also be used
IF[#3 EQ 90] GOTO 1; transfer to N1 in G90 mode
#24=#5001+#24; Calculate the X coordinate of the center of the circle
#25=#5001+#25; Calculate the Y coordinate of the center of the circle
N1 WHILE[#11 GT O] DO 1; until the number of remaining holes is 0
#5=#24+#4*COS[#1]; Calculate the hole position on the X axis
#6=#25+#4*SIN[+1]; Calculate the hole position on the X axis
G90 X#5 Y#6; Perform drilling after moving to the target position
#1=#1+#2; Update angle
#11=#11-1;Number of holes-1
END 1;
G#3 G80; G code to return to the original state
M99
(2) Modal call (G66)
Once G66 is issued, the modal call is specified, that is, the macro program is called after specifying the block moving along the moving axis. G97 cancels the modal call.
Description:
● Call
1) After G66, use the address P to specify the program number of the modal call.
2) When repetition is required, specify the number of repetitions from 1 to 9999 after the address L.
3) Same as non-modal call (G65), the data specified by the argument is transferred to the macro program body.
● Cancel When the G97 code is specified, the block after it will no longer execute the modal macro program call.
● Call nesting Calls can be nested in 4 levels. Including non-modal call (G65) and modal call (G66). But not including subroutine call (M98)
limit:
1) In the G66 block, multiple macro programs cannot be called.
2) G66 must be specified before the independent variable.
3) Macro programs cannot be called in a program segment that only has auxiliary functions but no movement instructions.
4) Local variables (independent variables) can only be specified in the G66 block. Note that each time a modal call is executed, local variables are no longer set.
● Typical program Use the macro program to compile the operation of the G81 canned cycle. The processing program uses modal call. In order to simplify the program, use the absolute value to specify all the drilling data.
● Call format G65 P9110 Xx Yy Zz Rr Ff Ll;
X: X coordinate of hole (specified by absolute value) (#24)
Y: Y coordinate of hole (specified by absolute value) (#25)
Z: Z point coordinate (specified by absolute value) (#26)
R: R point coordinate (specified by absolute value) (#18)
F: Cutting feed rate (#9)
L: number of repetitions
● The program that calls the macro program
00001;
G28 G91 X0 Y0 ZO;
G92 X0 Y0 Z50.0;
G00 G90 X100.0 Y50.0;
G66 P9110 Z-20.0 R.0 F500;
G90 X20.0 Y20.0;
X50.0;
X0.0 Y80.0;
G67;
M30;
● Macro program (called program)
09110;
#1=#4001; store G00/G01
#2=#4003; Store G90/G91
#3=#4109; Store cutting feed rate
#5=#5003; Store the Z coordinate of the start of drilling
G00 G90 Z#18; Positioning at point R
G01 Z#26 F#9; Cutting feed to point Z
IF[#4010 EQ 98]GOTO1; return to 1 point
G00 Z#18; locate at point R
GOTO 2;
N1 G00 Z#5; located at 1 point
N2 G#1 G#3 F#4; Restore modal information.
M99;
(3) Use G code to call the macro program
Set the G code to call the macro program in the parameter, and use this code to call the macro program in the same way as the non-modal call (G65).
Description:
Set the G code number (from 1 to 9999) for calling the user macro program (09010 to 09019) in the parameters (NO.6050 to NO.6059), and the method of calling the user macro program is the same as G65. For example, set parameters so that the macro program 09010 is called by G81, and the machining cycle compiled by the user macro program can be called without modifying the machining program.
● Repeat, same as non-modal call, address L can specify the number of repeats from 1 to 9999.
● Argument specification, like non-modal call, two kinds of argument specification are valid; independent variable specification I and independent variable specification II. The specified type of the argument is automatically determined according to the address used.
● Using the nesting of G code macro call, in the G code call program, one G code cannot call multiple macro programs. The G codes in such programs are processed as ordinary G codes. In a program that uses M or T code as a subroutine call, you cannot use one G code to call multiple macro programs. The G codes in such programs are also treated as ordinary G codes.
(4) Use M code to call macro program
Set the M code to call the macro program in the parameter, and use this code to call the macro program in the same way as the non-modal call (G65).
Description:
Set the M code (from 1 to 99999999) to call the user macro program (09021 to 09029) in the parameters (NO.6080 to NO.6089). The user macro program can be called in the same way as G65.
● Repeat, same as non-modal call, address L can specify the number of repeats from 1 to 9999.
● Argument designation, like non-modal call, two kinds of argument designation are valid; Argument Designation I and Argument Designation II. The designation type of the argument is automatically determined according to the address used.
● Restrictions:
1) The M code for calling the macro program must be specified at the beginning of the block.
2) In a macro program called by G code or a program called by using M code or T code as a subroutine, one M code cannot be used to call multiple macro programs. Such macro programs or programs.
(5) Use M code to call subroutine
Set the M code number of the calling subprogram (macro program) in the parameter. The macro program can be called with this code in the same way as the subprogram call (M98).
Description:
Set the M code (from 1 to 99999999) to call the subprogram in the parameters (NO.6071 to NO.6079), and the corresponding user macro program (09001 to 09009) can be called with this code in the same way as M98.
● Repeat, same as non-modal call, address L can specify the number of repeats from 1 to 9999.
● Argument designation is not allowed.
● M code, the M code called in the macro program is processed as ordinary M code.
● Restriction: In a macro program called by G code, or a program called by M or T code, several subroutines cannot be called by one M code. This kind of macro program or M code in the program is processed as ordinary M code.
(6) Call the subroutine with T code
Set the T code of the called subprogram (macro program) in the parameter, and call the macro program whenever the T code is specified in the processing program.
Description:
● Call: Set the 5-digit TCS=1 of parameter No.6001. When the T code is specified in the processing program, the macro program 09000 can be called. Assign the T code specified in the processing program to the public variable #149.
● Restriction: In a macro program called by G code or a program called by M or T code, one M code cannot call multiple subroutines. The T code in such a macro program or program is processed as a normal T code.
(7) Typical procedure
Use M code to call the function of subroutine, call the macro program that measures the cumulative use time of each tool.
condition:
1) Measure the cumulative use time of each tool from T01 to T05. Tools with a tool number greater than T05 will not be measured.
2) The following variables are used to store the tool number and measurement time.
#501 Cumulative use time of tool number 1
#502 Knife number 2 cumulative use time
#503 Tool number 3 cumulative use time
#504 Knife number 4 cumulative use time
#505 Tool number 5 cumulative use time
3) When M03 is designated, the use time will be calculated, and when M05 is designated, the calculation will stop. During the cycle start light is on, use the system variable #3002 to measure the time. During feed pause & single block stop. The time is not calculated, but the time for tool change and workbench exchange must be calculated.
checking
◆ Parameter setting, set 3 in parameter No.6071, set 05 in parameter No.6072.
◆ Setting of variable value, set 0 in variables #501 to #505.
◆ The program that calls the macro program
00001;
T01 M06;
M03;
M05; change #501
T02 M06;
M03;
M05; change #503
T05 M06;
M03;
M05; change #504
T05 M06;
M03;
M05; change #505
M30;
◆ Macro program (called program)
09001 (M03); start the macro program for calculation
N01;
IF[#4120 EQ 0]GOTO9; no tool specified
IF[#4120 GT 5]GOTO9;out of tool number range
#3002=0; clear calculator to 0
N9 M03; rotate the spindle in the positive direction
M99;
09002(M05); macro program to end calculation
M01;
IF[#4120 EQ 0]GOTO9; no tool specified
IF[#4120 GT 5]GOTO9;out of tool number range
#[500+#120]=#3002+#[500+4120];Calculate cumulative time
N9 M05; stop the spindle
M99;
Six, processing of macro program statements
For smooth processing, CNC pre-reads the next NC statement to be executed. This operation is called buffering. In the tool radius compensation mode (G41, G42), NC pre-reads the NC post statements of 2 or 3 blocks in advance in order to find the intersection point. The macro program statements of arithmetic expressions and conditional transfers are immediately read into the buffer register. deal with. The block containing M00, M01, M02 or M30, the block containing the buffer-prohibited M code set by the parameters No.3411 to No.3420, and the block containing G31 are not pre-read.
Description:
● When the next block is not buffered (unbuffered M code, G31, etc.)
● In methods other than the tool radius compensation mode (G41, G42), the next block is buffered (normally pre-reading a block); when N1 is executed, the next NC statement (N4) is read into the buffer. The macro statements (N2, N3) between N1 and N4 are processed during the execution of N1.
● In the tool radius compensation mode (G41, G4
2) Middle buffer next block
When N1 is executing, the NC statements in the next 2 blocks (until N5) are read into the buffer register. The macro statements (N2, N4) between N1 and N5 are processed during the execution of N1.
● In tool radius compensation mode C (G41, G42), when the next block contains a block without movement
When the NC1 block is being executed, the NC statements in the next two blocks (until N5) are read into the buffer register. Since N5 is a non-moving block, the intersection point cannot be calculated. At this time, the NC statements in the next three blocks (until N7) are read. The macro statements (N2, N4, and N6) between N1 and N7 are processed when N1 is executed.
|