I put some code together to demonstrate a couple of options. This should give you some pointers.
See also linuxcnc.org_docs_subroutine-parameters
The g-code:
Code:
%
OTestTriangle
N10 (TurboStep example: move along a triangular path across the x axis)
N20 G90 G54 G64 G50 G17 G40 G80 G49
N30 G21 (Metric)
N40 #<feed_rate> = 300 ; to demonstrate passing a local parameter
N50 o<test_triangle>call[5][10][#<feed_rate>]
N60 o<test_triangle>call[5][10][#<feed_rate>]
N70 o<test_triangle>call[5][10][#<feed_rate>]
N80 o<test_triangle>call[5][10][#<feed_rate>]
N90 o<test_triangle>call[5][10][#<feed_rate>]
N100 M30
%
and the subroutine:
Code:
o<test_triangle> sub
; test_triangle.ngc move along a triangular path across the x axis
; input parameters:
; #1 = step size in X direction
; #2 = step size in Y direction
; #3 = required feed rate
; save initial Y position for later use
#<yStart> = #<_y>
; first move
; #_x = global system parameter representing the current X position
; #_y = global system parameter representing the current Y position
G1 X[#<_x> + #1] Y[#<_y> + #2] F[#3]
; continue to step in X but return Y to original value
X[#<_x> + #1] Y[#<yStart>]
o<test_triangle> endsub
Some of the square brackets aren't strictly necessary but we regard them to be good practice when programming Unix scripts so I like to use them here too.
Step