Are nested subroutines possible?

More
8 years 1 month ago #118085 by helmholtz
Are nested subroutines possible? was created by helmholtz
Can anyone help with the syntax for a nested subroutine? Or to rephrase how can you call a sub from another subroutine?
I've written a couple of linux subroutines using the repeat function, so I get the basics, but it doesn't appear that you can call a sub from within another sub?

here is a Fanuc example, distilled to the basics that works but I can't wrap my head around making this work in linux syntax.

If anyone could provide a simple example like this I'd appreciate it!
Thx.
Code:
M98 P1234 L17 (run sub 17 times) M30 (end program) O1234 ...run some milling code then call another sub... M98 P5678 L12 (CALL SUBPROGRAM 5678 12 TIMES) M99 O5678 (sub called from other sub) ...more milling code... M99 (END SUBPROGRAM )
More
8 years 1 month ago - 8 years 1 month ago #118090 by MaHa
Replied by MaHa on topic Are nested subroutines possible?
If the subroutines are specific for this machining, you could put everything in one file.Then this example must be saved as (yourfile).ngc. Otherwise save the subroutines and the main, calling the subroutine as single file. You could set the repetitions from the main calling file, so the subroutines stay variable.


o1234 sub
o111 repeat [#1]

;nccode

o5678 call [#2]
o111 endrepeat
o1234 endsub

o5678 sub
o112 repeat [#1]

;nccode

o112 endrepeat
o5678 endsub

; M A I N
o1234 call [17][12]

M2
Last edit: 8 years 1 month ago by MaHa. Reason: removed, no named subroutines
More
8 years 1 month ago #118105 by andypugh
Replied by andypugh on topic Are nested subroutines possible?
Are you wanting to use the Fanuc-style subs or would LinuxCNC-style subs be acceptable?

Have you tried LinuxCNC-style? ( O100 SUB / O100 ENDSUB / O100 CALL )
More
8 years 1 month ago #118122 by helmholtz
Replied by helmholtz on topic Are nested subroutines possible?
Thank you. That was just what I needed. 'Repeat' was a big help and just the order of how things are done.
Code:
G90 o5678 sub o112 repeat [12] G91 G0 A30 (ROTATE 30 DEG, 12 DIVISIONS TOTAL) G04 P50 o112 endrepeat o5678 endsub o1234 sub o111 repeat [17] G91 G0 X0.250 (MOVE IN .250 INCREMENTS) o5678 call o111 endrepeat o1234 endsub (M A I N) o1234 call G90 M30
More
8 years 1 month ago #118123 by helmholtz
Replied by helmholtz on topic Are nested subroutines possible?
I'm moving from Mach3 to Linux(pathpilot) and none of my current programs work. so, I'm learning all of the new syntax and converting the programs but there are lots of differences.
More
8 years 1 month ago #118171 by andypugh
Replied by andypugh on topic Are nested subroutines possible?
Something that you didn't mention is what version of LinuxCNC you are using.

The M98 / M99 subroutine format was only added to the LinuxCNC development branch very recently (for compatibility with some other controls). Is that the version you are using?
Time to create page: 0.200 seconds
Powered by Kunena Forum