Macro Development Tool User Guide V9.0
Macro Development Tool User Guide V9.0
Macro Development Tool User Guide V9.0
Abstract
The develop environment is designed for the programmer to design and test the Macro program. By executing his program offline, the programmer can test it and know where the logical error is by graphic interface.
Edition check in ID 01 Record 1.new Date Author Edition V9.0 2006/07/20 James_lin
Contents
1 OpenCNC Developer Tool Introduction ............................................................. 1 1.1 System require.................................................................................... 1 1.2 Install ................................................................................................. 1 1.3 Using opencnc .................................................................................... 2 Macro Structure Motion language ...................................................................... 4 2.1 Block Format ..................................................................................... 4 2.2 2.3 File format ......................................................................................... 5 Expressions ........................................................................................ 6 2.3.1 Operators .................................................................................... 6 2.4 Statements .......................................................................................... 7 2.4.1 Assignment ................................................................................. 7 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 GOTO ........................................................................................ 7 EXIT .......................................................................................... 7 CASE ......................................................................................... 8 REPEAT .................................................................................... 9 WHILE ......................................................................................10
2.4.7 FOR............................................................................................ 1 2.4.8 IF................................................................................................ 1 2.5 Functions Listing ................................................................................ 2 2.6 Variables ............................................................................................ 8 2.6.1 Global variable table ................................................................... 8 2.6.2 R Resource table ..................................................................... 8 2.6.3 Comment .................................................................................... 8 2.7 Macro Program .................................................................................. 9 2.7.1 Call Methods: ............................................................................. 9 2.7.2 Return Methods: ........................................................................10 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.7.10 2.7.11 2.7.12 Argument specification ..............................................................10 System Variables .......................................................................11 Modal information .....................................................................11 Single Block Control Word(#1502) ...........................................13 Feed Control Word(#1504) ........................................................13 Current position .........................................................................14 Runtime state variable ...............................................................14 Modal variables .........................................................................15 Custom parameter ......................................................................15 Interface signals .........................................................................15
Mode Group Variables...............................................................15 Tool compensation variable(R/W) .............................................15 Workpiece coordinate system compensation values (workpiece
zero point offset values) ............................................................................16 2.7.16 Reference point position ............................................................16 2.8 Hinting of write extension G code .................................................17 2.9 I.Extended Interpolation G Code ...................................................17 2.10 MACRO example ..........................................................................18 3 Appendix ..........................................................................................................21 3.1 Basic G Code Table ...........................................................................21
1.2 Install
1. 2. Close other program first And run setup.exe file Wait a moment and then follow screen will appear
3.
Click Next
4. 5.
Choice Browse to change program install folder and click NEXT to continue Wait a moment to install done
-1-
override
2. 3.
write a macro and load itthen click Cyclestart the output will simulation on the screen function
-2-
4. 5. 6.
Single Stepstep and step to run the program,and click cycle start again between every step Mill or Lathe select set the space
Z X
7. 8.
Z X Y
X Z
Draw Machine or Clear Machine Simulationdirect draw the resoult on the output Graph region
-3-
2
/ / N G X Y Z A B C I J K F S T D M N
Block Delete function validated at he option of operator. If you use a sequence number, it must be the first in the block. The preparatory function(s) G must follow N. The linear dimension words follow G. Specify the X axis first. The linear dimension words follow G. Specify the Y axis second. The linear dimension words follow G. Specify the Z axis third. The rotary dimension words follow G. Specify the X axis first. The rotary dimension words follow G. Specify the Y axis second. The rotary dimension words follow G. Specify the Z axis third. The interpolation words follow the dimension words. Specify the X axis first. The interpolation words follow the dimension words. Specify the Y axis second. The interpolation words follow the dimension words. Specify the Z axis third. must follow the last dimension( and interpolation ) to which it applies. Spindle Speed Function shall follow immediately the Feed Function or Dimension word. The tool function selection follow S. The selection of tool compensation must follow K. Any miscellaneous function(s) that you specify must last in the block, just ahead of the end of block character.
-4-
-5-
2.3 Expressions
2.3.1 Operators
Operator Parenthesis Function Evaluation Negative Complement Multiply Divide Modulus Add Subtract Comparison Equality Inequality Boolean/Bitwise AND Boolean/Bitwise Exclusive OR Boolean/Bitwise OR Symbol ()[] Identifier( argument list ) NOT * / MOD + <,>,<=,>= = <> &,AND XOR OR Precedence 1 2 3 3 4 4 4 5 5 6 7 8 9 10 11
-6-
2.4 Statements
2.4.1 Assignment
Syntax<Variable>: = <expression>; DescriptionAssign a value to variable. Example @1 := 123; #1 := #3;
2.4.2 GOTO
SyntaxGOTO n; DescriptionJump to line numbers N Example 1 GOTO #3; Example % @MACRO // Start MACRO language IF( #1 = 2 ) THEN GOTO 100; G01 X10. Y10.; N100 G01 X30. Y30.; M02;
2.4.3 EXIT
SyntaxEXIT; DescriptionBreak loop or exit jump control Example Refer to WHILE example
-7-
2.4.4 CASE
Syntax CASE <INT expression> OF <INT>: <Statement list> <INT>,<INT>,<INT>: <Statement list> <INT>,<INT>: <Statement list> ELSE <Statement list> END_CASE; DescriptionConditional execution by cases. According to the result of INT expression in the CASE, controller executes corresponding program block. Example % @MACRO // Start MACRO language #1 := 8; G01 G91 G92 X20. Y15. F200000; CASE #1 OF 1: X(1.0*1); Y(1.0*1); 2: X(1.0*2); Y(1.0*2); 3,4,5: X(1.0*#1); Y(1.0*#1); ELSE X(1.0*6); Y(1.0*6); END_CASE; X(1.0) Y(1.0); M30;
-8-
2.4.5 REPEAT
Syntax REPET <Statement list> UNTIL <Condition> END_REPEAT; DescriptionREPEAT loop control Example % @MACRO // Start MACRO language #10 := 30.; #11 := 22.5.; #12 := #10/2; #13 := #11/2; #14 := 2.0; #15 := 1.5; G01 G92 X#12 Y#13 F200.0; REPEAT G00 X(#12+#14) Y(#13+#15); G01 X(#12+#14) Y(#13-#15); X(#12-#14) Y(#13-#15); X(#12-#14) Y(#13+#15); X(#12+#14) Y(#13+#15); #14 := #14 + 2.0; #15 := #15 + 1.5; UNTIL (#14 > #12) OR (#15 > #13) END_REPEAT; X(1.0) Y(1.0); M30;
-9-
2.4.6 WHILE
Syntax WHILE <Condition> DO <Statement list> END_WHILE; DescriptionWHILE loop control Example % @MACRO // Start MACRO language #10 := 20.; #11 := 15.; #12 := #10/2; #13 := #11/2; #14 := 2.0; #15 := 1.5; G01 G92 X#12 Y#13 F200.0; WHILE (#14 <= #12) AND (#15 <= #13) DO G00 X(#12+#14) Y(#13+#15); G01 X(#12+#14) Y(#13-#15); X(#12-#14) Y(#13-#15); IF #14 > 6.0 THEN EXIT; END_IF; X(#12-#14) Y(#13+#15); X(#12+#14) Y(#13+#15); #14 := #14 + 2.0; #15 := #15 + 1.5; END_WHILE; X(-5.0) Y(5.0); M02;
-10-
2.4.7 FOR
Syntax FOR <INT variable1> := <expression1> TO <expression2> [ BY <expression3>] DO <Statement list> END_FOR; DescriptionFOR loop control variable1 : loop control variable expression1 : loop start numberlong or double expression2 : loop end numberlong or double expression3 : loop increasedecreasenumberlong or double statement list :execute statement Examples % @MACRO // Start MACRO language #1 := 2.0; (*INITIAL RADIUS*) #2 := 8.0; (*FINIAL RADIUS*) #3 := 9; (* SIDES*) #4 := 360.0 / #3; (*THETA*) #5 := (180.0 + #4)/2; (*START ANGLE*) G91 G92 X0. Y0. F300000; G01 X(#1); FOR #6:=#1 TO #2 BY 2.0 DO #7 := 2.0 * #6 * COS(180.0-#5); #8 := (#7/2.0) / COS(180.0/6); #9 := #5; G01 X(1.0); FOR #10:= 1 TO #3 DO G03 X(#7*COS(#9)) Y(#7*SIN(#9)) I(#8*COS(#9-180.0/6)) J(#8*SIN(#9-180.0/6)); #9 := #9 + #4; END_FOR; END_FOR;
-1-
2.4.8 IF
Syntax IF <Condition> THEN <Statement list> ELSEIF <Condition> THEN <Statement list> ELSE <Statement list> END_IF; Descriptionconditional execution Examples % @MACRO // Start MACRO language #1 := 3.0; G01 G91 G92 X20. Y15. F200000; IF #1 = 1 THEN X(1.0*1); Y(1.0*1); ELSEIF #1 = 2 THEN X(1.0*2); Y(1.0*2); ELSEIF #1 = 3 THEN X(1.0*3); Y(1.0*3); ELSE X(1.0*4); Y(1.0*4); END_IF; X(1.0) Y(1.0); M30;
-1-
ACOS
ASIN
ATAN
COS
MAX
MIN
SIN
SQRT
TAN
SIGN
CEIL
2. Macro Structure Motion language Function FLOOR Description #2 := CEIL(#10); Return the largest integer that is less than or equal to a number Ex1: #2 := FLOOR(2.3); // #2 will be 2 Ex2: #2 := FLOOR(#10); Return the value of the argument rounded to the nearest long value Ex1: #2 := ROUND(2.3); // #2 will be 2 Ex2: #2 := ROUND(#10); Standardize arguments, read a number, in argument one, by least increment method, in argument two, when necessary for decimal point programming Ex: #9 := STD(#9,#1600); // normalize by distance axis Push value into Macro stack. Ex: PUSH(#1); // push #1 variable into stack PUSH(#3); // push #3 variable into stack Pop value from Macro stack. Ex: #1 := POP(); // popup a value to #1 Peek the stack value by index form top one. Ex: STKTOP(0) the most top element value STKTOP(1) the element value below top one STKTOP(2) the element value below top two etc Issue Macro alarm Ex: ALARM(300); // issue macro alarm id 300 ALARM(#1); // #1 must be integer Temporarily give up this cycle execution Ex: SLEEP(); Wait until all previous motion/logic commands are finished. Ex: WAIT(); Generates a pseudorandom number. Ex: #1 := RANDOM(); Lookup axis identifier, the axis identifier is the machine axis number. When the specified axiss name not exist,
ROUND
STD
PUSH
POP
STKTOP
ALARM
SLEEP
WAIT
RANDOM
AXID
-3-
2. Macro Structure Motion language Function Description then return value will be vacant. Ex: Assume 6th axiss name is Y2, 2nd axiss name is Y, then AXID(Y) will return 2 AXID(Y2) will return 6 Standardize arguments, read a number, in argument one, by least increment method, in argument two is axis address Ex: #24 := STDAX(#24,X); // normalize by X dimension #3 := STDAX(#3,A); // normalize by A dimension Open file, if success then return 1, otherwise return 0 PRINT() function will work after this function execute If file name is COMsystem will open RS232 portand parameter 3905..etc will need to set Example OPEN(PROBE.NC); //open PROBE.NC file for output data Example OPEN(COM); //open serial port PRINT("\p"); //output % char FOR #1 = 1 TO 5000 DO #30 = #1 * 10.; PRINT( "G01 X#30" ); //output G01 X10.000 END_FOR; PRINT(\p); //outpur %char CLOSE(); //close serial port Close the file which open with OPEN functionWhen program end then all open file will close automatic Avoid PRINT function after close file example CLOSE(); // close file This function is for output string to file usethe variable that inside the string will change to its valueif this function run success then it will return 1, otherwise will return 0 example @53 = 20; #3 = 23.1; PRINT(G01 X#3 Y@53 Z20.0); Output result G01 X23.100 Y20 Z20.0; Char \ is skip charspecial char define as follow \\ outpur \ char \@ outpur @ char \# outpur # char \p outpur % char Example for output: -4-
STDAX
OPEN(file name)
CLOSE()
2. Macro Structure Motion language Function Description G01 X(@20/@30) Y#20/2.0; The Syntax format is: PRINT(G01 X(\@20/\@30) Y\#20/2.0); GETARG(address) Read caller argument in subroutine example O0001 main program G101 X30. Y40. Z1=40. Z2=50.; . G0101 extension G code macro #1 = GETARG(X); // the value of X argument will store in #1 #2 = GETARG(Z1); // the value of Z1 argument will put in #2 #3 = GETARG(W); // without W argument, #3 will be VACANT GETTRAPARG(address) For G66/G66.1 modal macro call handler to get trap blocks information example O0001 main program G66 P100 X100. Y100. G01 X20. . O0100 subroutine #1 = GETARG(X); // Get X argument 100. to #1 #2 = GETTRAPARG(X); // Get trap block X argument 20. to #2 DBOPEN(filename) Load specify XML database example DBOPEN(FLAT\\TAB01); // load FLAT\\TAB01 database example #1 = 51; DBOPEN(FLAT\\AB#1[3]ZZ ); //load FLAT\\AB051ZZ database[3] mean 3 available value DBLOAD( CycleNo ) Load data from current XML data base example // load FLAT\\TAB01 database DBOPEN(FLAT\\TAB01); // load first data DBLOAD( 0 ); // load second data DBLOAD( 1 ); COMMENT(comment This function can output comment stringthe variable that string) inside the string will change to its valueif this function
-5-
2. Macro Structure Motion language Function Description run success then it will return 1, otherwise will return 0 example @53 = 20; #3 = 23.1; COMMENT(// G01 X#3 Y@53 Z20.0); Resoult: // G01 X23.100 Y20 Z20.0; Char \ is skip charspecial char define as follow \\ define \ char \@ define @ char \# define # char \p define % char If the output is: // THIS IS TURNING CYCLE Then Syntax format is COMMENT(// THIS IS TURNING CYCLE); DRAWHOLE() Draw a hole using current tool radius, line color, fill color at current position. This function only take effect under graphics simulation DRAWMARK(shape,siz Draw a mark with specified shape, size, color at current e,color) position. The marker will fix in size not regards to zoom scaling. Size: In Pixel Shape:0:Circle,1:Square;2:Diamond. This function only take effect under graphics simulation SETDRAW(LineColor) To assign draw style or LineColor: use for draw contouring line SETDRAW(LineColor,Fi ToolRadius: use for draw hole radius size llColor,ToolRadius) FillColor: use for fill hole interior. This function only take effect under graphics simulation PARAM( no ) To read specified system parameter number #1 = PARAM(3204) // to access PLC scan time interval SYSVAR( AxisGroupI To read system variable of specified coordinate system. D, No ) AxisGroupID axis group identifier, 1 for first axis group, 2 for 2nd axis group, etc No The system variable number. e.g. #1 = SYSVAR( 1, 1000 ); // to read interpolation mode of first axis group. SCANTEXT( No ) To scan text string from global variable. Notes: Because string is local, so only can stores in local variable, and can not save to global variable. That is, following will get wrong result. e.g. // scan string text from @300 #1 = SCANTEXT(300);
-6-
2. Macro Structure Motion language Function Description // following will get wrong result @100 = #1; // @100 will loss string information DBOPEN(ABC_@100); // this will got wrong result // following will get correct result #100 = #1; // #100 contain valid string from @300~ DBOPEN(ABC_#300); // correct result
-7-
2.6 Variables
Vacant Local System Global #0@0 is always VACANT #1 ~ #50 #1000 ~ @1~
R/W
R101~R102 R103~R255 R256~R511 R512~R639 CNC system interface R640~R1023 R1023~R4095 User define
CNC system interface PLC Alarm area User define area Corresponding to system parameter 3401~3420 Tool state User define
2.6.3
Comment
(* This is comment *) // This is comment
-8-
G65 P_ L_ addresses
G66 P_ L_ addresses
G66.1 P_ L_ addresses Modal macro callfor every block P_ subroutine name L_ repeat times
G_ L_ addresses T_
M_ addresses
External G call L_ repeat times Tool selection by subprogram, any T code inside T-subprogram will be treat as ordinary T call. M Code Macro Call M13 A_ B_ C_; Call M0013 Macro M13 must register in parameter No.3601~
Example G66 P10 X10.0 Y10.0; X20. Y20. Description X20 and Y20. move command block will call O0010 Example G66.1 P10 X10.0 X20. G04 X2.; M31; Description X20G04 X2 and M31.every block will call O0010 G128 L3 X1.0;(will call G0128 three times) T3;(will call T0000)
-9-
M99 Q_
G67
-10-
-11-
Operation control/status
#1500 #1502 #1504 #1506 #1508 #1510 Quiet mode, 1(Quiet mode), 0(Normal mode) Single block control word Feed control word Simulation mode, 1(in simulation mode),0(in normal mode) my session ID inside mode group The current active session of multi-session program in CNC main system. 0 for execute the multi-session program simultaneously; 1 to execute $1 program only; 2 to execute $2 program only. Distance least input increment Time/Rotation angle least input increment Use U/V/W addresses as X/Y/Z axis incremental command mode, 1(Use as X/Y/Z incremental command), 0(As normal axis command) The count of element in macro stack. Flag for skip function position latched, 1 for latched, 0 for not latched. Spindle orientation stop angle Default workpiece number Default spindle speed Break point sequence number Break point line number Current sequence number Current point line number Current active spindle ID R/W R/W R/W R R R
R R R
#1606 #1608 #1610 #1612 #1614 #1616 #1618 #1620 #1622 #1624
-12-
Bit 1
Bit2
R R R R
-14-
-15-
2.7.15 Workpiece coordinate system compensation values (workpiece zero point offset values)
#20001~#20006 #20021~#20026 #20041~#20046 #25981~#25986 There are only 16 workpiece coordinate system in this version External workpiece zero point offset value R/W Workpiece 1 zero point offset value,G54 R/W Workpiece 2 zero point offset value,G55 R/W R/W Workpiece 299 zero point offset value R/W
-16-
-17-
-18-
2. Macro Structure Motion language IF( #23 <> #0 OR #26 <> #0 ) THEN // WHEN THERE ARE W OR Z ADDRESS APPEAR, THEN // CHECK WHICH KIND OF COMMAND BEEN ADDRESS // AND SAVE IT INTO MODAL VARIABLE IF( #26 <> #0 ) THEN // Z ADDRESS #2071 := #26 - #1303; ELSE // W ADDRESS #2071 := #23; END_IF; ELSE // WHEN THERE ARE NO Z/W ADDRESS, THEN INHERIT // IT FROM MODAL VARIABLE #26 := #2071 + #1303; END_IF; // PROCESS E ADDRESS IF( #8 <> #0 AND #9 = #0 ) THEN IF( #1008 = 94 ) THEN // FEED PER MINUTE, CALCULATE MM/MIN = // LEAD * SPINDLE SPEED #9 := (25.4 * #1034) / #8; #2072 := #9; ELSE // FEED PER REVOLUTION, CALCULATE MM/REV = // LEAD #9 := 25.4 / #8; #2072 := #9; END_IF; END_IF; // STANDARDIZE ARGUMENT #9 := STD(#9,#1600); #21 := STD(#21,#1600); #23 := STD(#23,#1600); #24 := STD(#24,#1600); #26 := STD(#26,#1600); #18 := STD(#18,#1600); // working variable // #31 chamfer start point relative to block end X // #32 chamfer block X-direction displacement // #33 chamfer amount // #36 thread head number iterative count // #37 thread start angle
-19-
2. Macro Structure Motion language // READ CHAMFER AMOUNT #33 := (#4043 * #9) / 10.0; // COPY X,Z INFORMATION INTO U,W // PROCESS X ADDRESS IF( #24 <> #0 ) THEN #21 := #24 - #1301; END_IF; // PROCESS Z ADDRESS IF( #26 <> #0 ) THEN #23 := #26 - #1303; END_IF; // process H addesss, the head number IF( #11 <> #0 ) THEN #11 := ROUND(#11); ELSE // set default head number 11 := 1; END_IF; // CALCULATE CHAMFER START POINT RELATIVE TO // BLOCK END POINT IN X #31 := (SIGN(#23) * #33 * 2 * #18)/#23; // CALCULATE CHAMFER BLOCK X-DIRECTION // DISPLACEMENT #32 := -SIGN(#21)*#33*2; FOR #36:=1 TO #11 DO // calculate thread start angle #37 := (360.0 / #11) * (#36 - 1); G00 U( #21 + #18*2 ); G33 U-(#18*2-#31) W(#23-SIGN(#23)*#33) Q#37 F(#9*#11); G33 U#32 W(SIGN(#23)*#33) Q#37; G00 U-#21-#32-#31; G00 W-#23; END_FOR; // SET INTERPOLATION MODE TO 21 #1000 := 21; // RETURN M99;
-20-
3. Appendix
3
Code G00 G01 G02 G03 G04 G10 G15 G16 G17 G18 G19 G28 G29 G30 G31 G33 G40 G41 G42 G43 G44 G49 G50 G51 G52 G53 G54 G55 G56 G57 G58 G59 G65 G66 G67 G67 G68 G70 G71 G90 G91
Appendix
Function POSITIONING LINEAR INTERPOLATION CIRCULAR INTERPOLATION (Clockwise) CIRCULAR INTERPOLATION (CounterClockwise) Dwell PROGRAMMABLE DATA INPUT CANCEL POLAR COORDICATES COMMAND MODE POLAR COORDICATES COMMAND MODE XY PLANE SELECTION ZX PLANE SELECTION YZ PLANE SELECTION RETURE TO REFERENCE POSITION RETURE FROM REFERENCE POSTION 2nd,3rd and 4th REFERENCE PPOSTION RETURE SKIP FUNCTION THREAD INTERPOLATION CANCEL CUTTER COMPENSTAION LEFT CUTTER COMPENSTAION RIGHT CUTTER COMPENSTAION POSTIVE TOOL LENGTH COMPENSATION NEGATIVE TOOL LENGTH COMPENSATION CANCEL TOOL LENGTH COMPENSATION SCALING PROGRAMMABLE MIRROR IMAGE LOCAL COORDINATE SYSTEM MECHINE COORDICATE SYSTEM SELECTION WORKPIECE COORDICATE SELECTION SECOND WORKPIECE COORDICATE SELECTION THIRD WORKPIECE COORDICATE SELECTION FOURTH WORKPIECE COORDICATE SELECTION FIVETH WORKPIECE COORDICATE SELECTION SIXTH WORKPIECE COORDICATE SELECTION SIMPLE CALL MACRO CALL CANCEL MACRO CALL CANCEL COORDINATE ROTATION COORDINATE ROTATION INPUT IN INCH INPUT IN MM ABSOLUTE COMMEND INCREMENT COMMEND
-21-
3. Appendix Code G92 G94 G95 G96 G97 Function SETTING OF WORK COORDICATE SYSTEM FEED UNIT SETTING (mm/min.) FEED UNIT SETTING (mm/rev.) CONSTANT LINEAR VELOCITY CONTROL ON SURFACE CANCEL CONSTANT LINEAR VELOCITY CONTROL ON SURFACE
-22-