en:software:mdurosettacncsoftwaregcode:macro_programming: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:

  • call a subroutine defined in the same G-Code file by number. Example: M98 P100 L10
  • call a subprogram defined into an external file by number. Example: M98 P100 L10 where in the macro folder you have defined a file 0100.ngc.
  • call a subprogram defined into an external file by name. Example: M98 P“named_sub.ngc” L10

Parameters:

  • P: identifies the subroutine/subprogram to be called. It can be a number of a string with the name of the external file
  • L: identifies how many times the G-Code commands inside the subroutine should be repeated before returning
( © 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
  • Last modified: 2023/03/22 09:07
  • by 127.0.0.1