Gcode subroutings issues

More
26 May 2013 21:11 - 26 May 2013 21:14 #34718 by Nick
Hi while developping LinuxCNC features we saw some strange behavior of subroutines...

1. Oxxx RETURN works strange:
O123 sub

   O<200> IF [5 LE 0.01]
      O123 RETURN
   O<200> ENDIF

   O124 WHILE [1]
      O124 BREAK
   O124 ENDWHILE

O123 endsub(End definitions)

M02
This code gives "Unxepected character after O-word"
If we remove "O123 RETURN" or WHILE code is accepted.

2. This is more complicated example.
It's a subroutine which shuold generate rectangle pocket with multipass spiral milling of rectangle.

So we have two subs
first <multipass> sub - it makes passess for mulptipass machining
second spiral rectangle.
So here's the deal: in multipass sub there's O#<sub> CALL - a call to the sub defined in #<sub> parameter. And it does not work. It says that #<sub> parameter is undentified, dispite the first string of the sub #<sub> = #1.
We have tried several variations:
O#<sub> CALL [#8] [#9] [#10] [#11] [#12] [#13] [#14] [#15] [#16] [#17] [#18] [#19]
- does not work!

O#1 CALL [#8] [#9] [#10] [#11] [#12] [#13] [#14] [#15] [#16] [#17] [#18] [#19]
- works fine!

#<sub> = #1
O#<sub> CALL [#8] [#9] [#10] [#11] [#12] [#13] [#14] [#15] [#16] [#17] [#18] [#19]
- does not work!?!?!
How can it be?

the whole subroutine:
#<_tool_feed> = 100
   (Rectangle sub definition)
   O<multipass> SUB
      #<sub> = #1
      #<depth> = #2
      #<step> = #3
      #<surface> = #4
      #<rappid> = #5
      #<x0> = #6
      #<y0> = #7      
   
      G0 Z#<rappid>
      G0 X#<x0> Y#<y0>
      #<z> = #<surface>
      O<multipass-while> WHILE [#<z> GT #<depth>]
         
         #<z> = [#<z>-#<step>]
         O<multipass-if> IF [#<z> LT #<depth>]
            #<z>=#<depth>
         O<multipass-if> ENDIF 
         F#<_tool_feed>
         G1 Z#<z>   
         (call pass sub with the restof parameters)
         (DEBUG, #<sub>)
         #<sub> = #1
         O#<sub> CALL [#8] [#9] [#10] [#11] [#12] [#13] [#14] [#15] [#16] [#17] [#18] [#19]
      
      O<multipass-while> ENDWHILE
   
      G0 Z#<rappid>   
   O<multipass> ENDSUB




(Rectangle sub definition)
#<_spiral-rectangle> = 1000
O#<_spiral-rectangle> sub
   #<cx> = #1
   #<cy> = #2
   #<w>  = #3
   #<h>  = #4
   #<spiral-step> = #5 
   #<a>  = #6

   O<spiral-rectangle-if-0001> IF [#<spiral-step> GT 0.01]
        
      #<x1> = [#<cx>-#<w>/2]
      #<x2> = [#<cx>+#<w>/2]
      #<y1> = [#<cy>-#<h>/2]
      #<y2> = [#<cy>+#<h>/2]
      G1 X#<x1> Y#<y1>

      ; CW
      O<spiral-rectangle-while> WHILE [1]
      
         G1 X#<x1> Y#<y2>
         #<x1> = [#<x1> + #<spiral-step>]   
         O<spiral-rectangle-if-0002> IF [#<x1> GT #<x2>]
            G1 X[[#<x1>+#<x2>]/2]
            G1 Y[#<y1>]
            O<spiral-rectangle-while> BREAK
         O<spiral-rectangle-if-0002> ENDIF


         G1 X#<x2> Y#<y2>
         #<y2> = [#<y2> - #<spiral-step>]   
         O<spiral-rectangle-if-0003> IF [#<y1> GT #<y2>]
            G0 Y[[#<y1>+#<y2>]/2]
            G0 X[#<x1>]
            O<spiral-rectangle-while> BREAK
         O<spiral-rectangle-if-0003> ENDIF
   
         G1 X#<x2> Y#<y1>
         #<x2> = [#<x2> - #<spiral-step>]   
         O<spiral-rectangle-if-0004> IF [#<x1> GT #<x2>]
            G1 X[[#<x1>+#<x2>]/2]
            G1 Y[#<y1>]
            O<spiral-rectangle-while> BREAK
         O<spiral-rectangle-if-0004> ENDIF
   
         G1 X#<x1> Y#<y1> 
         #<y1> = [#<y1> + #<spiral-step>]   
         O<spiral-rectangle-if-0005> IF [#<y1> GT #<y2>]
            G0 Y[[#<y1>+#<y2>]/2]
            G0 X[#<x2>]
            O<spiral-rectangle-while> BREAK
         O<spiral-rectangle-if-0005> ENDIF
   
      O<spiral-rectangle-while> ENDWHILE

   O<spiral-rectangle-if-0001> ENDIF

O#<_spiral-rectangle> endsub(End definitions)

(Call spiral rectangle sub cX cY w h spiral-step depth depth-step surface rappid)

;               sub               depth step surf rappid   #x0 #y0 #cx #cy   w    h    [spir-step]
O<multipass> CALL [#<_spiral-rectangle>] [-5.1] [1] [0] [10]       [5] [2] [1]  [1]  [10] [20] [.1]
  
M02

This subroutine should give something like this:
Attachments:
Last edit: 26 May 2013 21:14 by Nick.

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

More
27 May 2013 04:38 #34735 by andypugh
Replied by andypugh on topic Gcode subroutings issues

[code]O123 sub
O<200> IF [5 LE 0.01]
O123 RETURN
O<200> ENDIF


This is quite a strange format. Why O<200> and not O200 ?

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

More
28 May 2013 20:51 #34839 by Nick
Replied by Nick on topic Gcode subroutings issues
I simplified another subroutine to find the bug. There were some named parameters there.
Never the less without <> I get the same error.

Any thoughts about the first issue?
the most surprising thing is this:
O#1 CALL [#8] [#9] [#10] [#11] [#12] [#13] [#14] [#15] [#16] [#17] [#18] [#19] - works fine!

#<sub> = #1
O#<sub> CALL [#8] [#9] [#10] [#11] [#12] [#13] [#14] [#15] [#16] [#17] [#18] [#19] - does not work!?!?!
Attachments:

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

More
28 May 2013 21:00 #34843 by andypugh
Replied by andypugh on topic Gcode subroutings issues
[quote="Nick" post=34839O#1 CALL [#8] [#9] [#10] [#11] [#12] [#13] [#14] [#15] [#16] [#17] [#18] [#19] - works fine![/quote]
You are trying to call numbered subs by number?

So, #1 = 100 ; O#1 CALL will call O100 and #1 = 200 ; O#1 CALL will call the O200 sub?

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

More
29 May 2013 12:26 #34894 by Nick
Replied by Nick on topic Gcode subroutings issues
Yes exactly. It's an additional function which realizes multipass machining. The #1 parameter is the subroutine for each pass. Then it's called in while loop.
In this example we use O1000 as subroutine:
#<_spiral-rectangle> = 1000
O#<_spiral-rectangle> sub
...
O<multipass> CALL [#<_spiral-rectangle>] [-5.1] [1] [0] [10] [5] [2] [1] [1] [10] [20] [.1]

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

More
29 May 2013 17:38 #34904 by ArcEye
Replied by ArcEye on topic Gcode subroutings issues
Hi

I think you are getting caught by indirection
o100 sub

(MSG, inside 100 sub)

o100 endsub

#<_tester> = 100

G17 G21 G8 G40 G49
G80
G90 G94
F600 S800
M3
M8

G00 X0 Y0 Z20

o[#<_tester>] call

M1

g28

M5
M9
M2

This works because it is calling the value held rather than the object itself, similar to *(ptr) in C

You can make arrays in gcode and reference in a similar fashion by using [#[#<_array_index> + 5]] where _array_index is a fixed value, say 100 and that will get you the value held at #105

regards

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

More
29 May 2013 20:17 #34910 by Nick
Replied by Nick on topic Gcode subroutings issues
hmmm... how can indirection cause "named parameter #<sub> not defined" in:

#<sub> = #1
O#<sub> CALL

while :

O#1 CALL works as it supposed to

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

More
29 May 2013 20:28 - 29 May 2013 20:32 #34911 by Nick
Replied by Nick on topic Gcode subroutings issues
I've trimmed almost everything. And here's what I got:

  1. This give an #<sub> unidentified error.
    O<multipass> SUB
        #<sub> = #1
        O#<sub> CALL 
    O<multipass> ENDSUB

  2. This variant works fine
    #<sub> = #1
    O<multipass> SUB
        #<sub> = #1
        O#<sub> CALL 
    O<multipass> ENDSUB

  3. And the most interesting: after opening second variant with #<sub> defined outside of O SUB, the first variant began to work fine until LinuxCNC restart.
    O<multipass> SUB
        #<sub> = #1
        O#<sub> CALL 
    O<multipass> ENDSUB

It looks like that we cannot use named variables inside SUB to call another SUBs. Probably there's an bug inside parser which checks all O-code names/numbers...
Last edit: 29 May 2013 20:32 by Nick.

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

More
29 May 2013 21:34 #34912 by ArcEye
Replied by ArcEye on topic Gcode subroutings issues
The other thing at play here is scope

You are defining local parameters (no leading underscore)
#<tester> = 100
o100 sub
	(MSG, inside 100 sub)
o100 endsub

o200 sub
    o[#<tester>] call
o200 endsub
...
o200 call

gets Named parameter <tester> not defined

whereas
#<_tester> = 100
o100 sub
	(MSG, inside 100 sub)
o100 endsub

o200 sub
    o[#<_tester>] call
o200 endsub
...
o200 call

works

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

More
30 May 2013 03:26 #34926 by Nick
Replied by Nick on topic Gcode subroutings issues
Yes, but I do want a local parameter. More over, the first one with local #<tester> will work too, because you've defined #<tester> at the top of the code outside the Subroutine. (see my second variant)

And notice that we are defining #<sub> = #1 just before calling O#<sub> CALL, even if we define sub to constant #<sub> = 1000 (instead of #1), O#<sub> CALL will cause exception...

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

Time to create page: 0.216 seconds
Powered by Kunena Forum