Rosetta CNC supports Macro programming (following Fanuc Macro B style).
Your G-code programs or sub-programs can include a few non G-code commands that use:
Subroutines, Macros and WHILE
statements can be nested up to 100 times.
The following example provide an overview of the supported macro programming features.
F5000 G0 x0 y0 z0 G1 x100 ; G-code subroutines support ; To invoke a subroutine type "M98 P<subroutine id> L<repetitions>". ; The following line invoke the subroutine with id 1 for 2 times. M98 P1 L2 ; Numbered external G-code subroutine call M98 P101 L2 ; Named external G-code subroutine call M98 P"named_sub.ngc" L2 #1 = 10 #2 = 20 #3 = 30 #4 = -10 ; Macro call support: ; - The arguments are loaded in the correspondent parameters. ; - When the call is finished the parameters 1-33 are restored to the value ; they had before the call ; A = #1 ; B = #2 ; C = #3 G65 P2 A3 B5 C2 IF [#4 EQ -10] THEN M109 P"Parameter 4 is restored to #4 when the macro is finished" G65 P"named_sub.ngc" A3 B5 C2 ; RosettaCnC supports user defined M codes with arguments [M200 - M299] M200 A10 B5 C7.0 ; "CALL" can be used as a more readable alias for G65. CALL P"local_named_sub" M2 ( Program End) ; RosettaCnC supports G-code subroutines: ( The following lines declare a subroutine with id 1 ) O1 ( Subroutine body that contains G-code instructions ) G0 x0 y0 z0 G0 x0 y0 z50 G0 x0 y0 z0 ( The following line define the end of the subroutine ) M99 O2 ( Subroutine body can access and modify local parameters ) #4 = [[#1 + #2] * #3] IF [#5 EQ #0] THEN M109 P"Parameter 5 has not been set when the macro has been called" IF [#4 EQ 16] THEN M109 P"Parameter 4 is equal to #4" ( The following line define the end of the subroutine ) M99 ; Local named subroutines can be defined as follows, where: ; - "SUB" and "O" can be both used for the subroutine declaration ; - "ENDSUB" and "M99" can be both used for subroutine end ; - "RETURN" and "M99" can be both used to return from a subroutine SUB "local_named_sub" G1 Y100 IF [#1 EQ 0] THEN1 RETURN END1 ENDSUB