Do While problem

More
01 Jan 2013 22:41 #28257 by tricky-dicky1945
I am a newbie to Linux CNC. When I include the following in a file Linux CNC appears to lock up "spinning ball"
o303 do
#10=[#10+1]
g0 x#7 y[#9*#10] ;Move to next Y position
g0 z#11
g1 x#8
G0 z10
o303 while [[#9*#10] LT #2]

I cannot see my error! can anyone assist?

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

More
01 Jan 2013 23:03 #28258 by BigJohnT
Replied by BigJohnT on topic Do While problem
I don't see where you initialize #9 or #2 to any value. Might be easier to follow if you used named variables. Also note that #1-#30 are local variables in a subroutine .

John

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

More
01 Jan 2013 23:19 #28260 by tricky-dicky1945
Replied by tricky-dicky1945 on topic Do While problem
Thanks for the reply. #9 and #2 are initialized earlier in the file. the file did start as a "Subroutine" with the variables called. But I kept getting an error when I "called" and applied the variables. The whole file follows. It is probably incorrect in its action but I cannot get it to load and allow me to run it in the first place
g21
f200
(Milling the top face of a block)
(Clamp block then touch off using G54 on far right corner x and y and top of block)
(Stored parameters when called are #1 Length, #2 Width, #3 amount to remove, #4 cutter diameter #5 depth of cut #6 % width)
(#7 - #11 are also used)
(o300 call [x] [y] [z] [cutter dia] [cut depth] [cut width decimal fraction])
#1=20 #2=15 #3=3.5 #4=10 #5=1 #6=.8
#3=[0-#3] (Negate Z depth)
#7=3 (Far right X start postion)
#8=[#1+#4+3] (Far left end position value)
#8=[0-#8] ;negate
#9=[#4*#6] (Y increment)
#9=[0-#9] ;negate
#10=0 (Number of X passes)
#11=0 (Current Z position for cuts)

o301 while [#11 NE #3]
#11=[#11-#5]
o302 If [#11 LT #3]
#11=#3
o302 endif
#10=0
G0 z10 ;raise to clear height
o303 do
#10=[#10+1]
g0 x#7 y[#9*#10] ;Move to next Y position
g0 z#11
g1 x#8
G0 z10
o303 while [[#9*#10] LT #2]

o301 endwhile
G0 z10
G0 x0 y0

m2

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

More
01 Jan 2013 23:32 - 01 Jan 2013 23:34 #28261 by BigJohnT
Replied by BigJohnT on topic Do While problem
You probably have an infinite loop, To sort that out use a break in front of the ending tag(s) and add some debug comments to see what the variables values are at that point. Also breaking each loop down and testing might reveal where the error is.

Nesting is easier to read when indentation is used.
o301 while [#11 NE #3]
  #11=[#11-#5]
  o302 If [#11 LT #3]
    #11=#3
  o302 endif
  #10=0
  G0 z10 ;raise to clear height
  o303 do
    #10=[#10+1]
    g0 x#7 y[#9*#10] ;Move to next Y position
    g0 z#11
    g1 x#8
    G0 z10
    (debug, #9 #10 #2)
  0303 break
  o303 while [[#9*#10] LT #2]
o301 endwhile

I'll get my LinuxCNC computer booted up in a bit and see if I can spot the error before you.

John
Last edit: 01 Jan 2013 23:34 by BigJohnT.

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

More
02 Jan 2013 00:04 #28262 by tricky-dicky1945
Replied by tricky-dicky1945 on topic Do While problem
Thanks for that John, I assumed that it was something like an infinite loop. I will do the debug (now that you have shown me how to use it!) I have also rewritten with "Named Parameters". The original software is fully indented but lost it in the copy and paste to the message. Thanks for your prompt help

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

More
02 Jan 2013 00:06 #28263 by BigJohnT
Replied by BigJohnT on topic Do While problem
I commented out all the moves as they are not needed to test the loops and put each assignment on a line and the following seems to run. The debugs will give an output, when you run this is this what you expected?
#2=15
#3=3.5
#3=[0-#3] (Negate Z depth)
#4=10
#5=1
#6=.8
#9=[#4*#6] (Y increment)
#10=0 (Number of X passes)
#11=0 (Current Z position for cuts)
o301 while [#11 NE #3]
  #11=[#11-#5]
  (debug, 11 #11)
  o302 if [#11 LT #3]
    #11=#3
    (debug, 302)
  o302 endif
  #10=0
  ;G0 z10 ;raise to clear height
  o303 do
    #10=[#10+1]
    ;g0 x#7 y[#9*#10] ;Move to next Y position
    ;g0 z#11
    ;g1 x#8
    ;G0 z10
    #31 = [#31 + 1]
  o303 while [[#9*#10] LT #2]
  (debug,31 #31)
o301 endwhile

M2

John

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

More
02 Jan 2013 01:41 #28272 by tricky-dicky1945
Replied by tricky-dicky1945 on topic Do While problem
Ok I have debugged and I cannot understand what is happening. In the code #10 resets to 0 after each iteration of "Do".I cannot understand it!

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

More
02 Jan 2013 02:12 #28275 by BigJohnT
Replied by BigJohnT on topic Do While problem
Post what you have so far and if you hit reply instead of quick reply you can see the code tags to surround your code with.

John

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

More
02 Jan 2013 03:35 #28282 by tricky-dicky1945
Replied by tricky-dicky1945 on topic Do While problem
Ok file is attached
Attachments:

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

More
02 Jan 2013 04:02 #28283 by BigJohnT
Replied by BigJohnT on topic Do While problem
Now that you have named them which one was #10?

John

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

Time to create page: 0.095 seconds
Powered by Kunena Forum