Are nested subroutines possible?

More
27 Sep 2018 22:20 #118085 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.
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 )

Please Log in or Create an account to join the conversation.

More
28 Sep 2018 06:53 - 28 Sep 2018 13:47 #118090 by MaHa
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: 28 Sep 2018 13:47 by MaHa. Reason: removed, no named subroutines

Please Log in or Create an account to join the conversation.

More
28 Sep 2018 12:26 #118105 by andypugh
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 )

Please Log in or Create an account to join the conversation.

More
28 Sep 2018 15:54 #118122 by helmholtz
Thank you. That was just what I needed. 'Repeat' was a big help and just the order of how things are done.
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

Please Log in or Create an account to join the conversation.

More
28 Sep 2018 16:01 #118123 by helmholtz
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.

Please Log in or Create an account to join the conversation.

More
29 Sep 2018 09:16 #118171 by andypugh
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?

Please Log in or Create an account to join the conversation.

More
29 Sep 2018 15:47 #118180 by helmholtz
I wish I was using a version that supported M98/99 as I'm more familiar with industrial controls, which is why I had been using Mach3 on my hobby machines at home.

I'm using Tormach's Pathpilot version 2.1.3 (on a tormach mill). I haven't seen good documentation of what they are doing with their builds vs. what the rest of the linuxcnc community is doing, but it does seem that Tormach is doing it's own thing.

In general, their support is terrible which is why I'm posting here instead of asking them. MaHa's above example was very helpful and more detailed then anything I would have gotten from Tormach. They just copy and paste sections of their manual when you ask for any help, lol.

Please Log in or Create an account to join the conversation.

More
29 Sep 2018 19:55 #118191 by Grotius
Hi Holzman,

linuxcnc.org/docs/html/gcode/o-code.html
Section 3 : The maximum subroutine nesting level is 10.

Don't forget to set your program prefix in your ini file, section [DISPLAY], otherwise it won't work :
PROGRAM_PREFIX = /home/holzman/.....

Good luck !!

Please Log in or Create an account to join the conversation.

More
29 Sep 2018 23:46 #118207 by tommylight

helmholtz wrote: I wish I was using a version that supported M98/99 as I'm more familiar with industrial controls, which is why I had been using Mach3 on my hobby machines at home.

Mach3 has nothing industrial about it, or in it, it is a motion controller and very limited at best.
I would venture a guess at it having about 10% of capabilities Linuxcnc has, and that is me being generous, very.
Back on topic,
Fanuc uses some nice features on a punch press i often used, LAA ( line at angle ), GRID ( well grid ), NIB ( nibble ), etc that are very easy to use but not easy to learn for normal people, as each of them has it's own variables and parameters.
Adding something like that to Linuxcnc would help a lot to people who have that type of machines running under Linuxcnc, but so far i know of 2 on this forum ( one is from Serbia and he does not share any info, the other did try to contact him for help but i do not know if he got any help ) and a third one on youtube.
KUKA uses some similar short cuts for programming robots like LIN ( linear move with settable speed ), PTP ( point to point move at normal speed so the tool tip will move at any given speed regardless to get to a point ) etc.
Still all of the above mentioned examples have to be programmed by hand in their respective editors.

Please Log in or Create an account to join the conversation.

More
01 Oct 2018 16:22 #118300 by eneias_eringer

andypugh wrote: 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?


Really ??? !!! and a GOTO will be implanted too ??? LOL !!!

Please Log in or Create an account to join the conversation.

Time to create page: 0.207 seconds
Powered by Kunena Forum