3.4 Subroutines

To make g-code convenient for re-use, you can centralise it and then access it from the main program. G-Code language provides two different methods for doing this: subprogram/subroutines calls and macro calls.

With Rosetta CNC you can:

Parameters:

( © 2019 by RosettaCNC Motion                                      )
( file name: subroutines.ngc                                       )
 
F5000
G0 x0 y0 z0
G1 x100
 
( RosettaCnC supports G-code subroutines                           )
( To call a subroutine type "M98 P<subroutine id> L<repetitions>". )
( The following line calls the subroutine with id 1 for 2 times.   )
M98 P1 L2
 
( RosettaCnC supports G-code numbered external subroutines.        )
( The subprogram 0101.ngc should exist in the macro folder.        )
M98 P101 L2
 
( RosettaCnC supports G-code named external subroutines            )
M98 P"named_sub.ngc" L2
 
m2 ( Program End)
 
( 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 marks the end of the subroutine       )
M99