While Loop Possible Bug(s)?

More
29 May 2019 16:51 - 29 May 2019 16:54 #135297 by Todd Zuercher
I was working on a small parametric G-code file that is supposed to spiral mill a circular pocket.

I am running into two problems. The 1st problem was that my while loop was executing one extra loop regardless of if I use LT or LE, for my watched parameter I get the same result. I've worked around this by subtracting 0.0001 from the comparison and seems to give the correct results for everything I've tested so far.

The other problem that I really don't understand is, after the while loop is completed the program is supposed to make a circular finish cut, but sometimes with certain combinations of %overlap and pocket diameter, Linuxcnc completely skips that last circular cut. Is this some sort of an interpreter bug in Linuxcnc? (I am getting these results testing on Linuxcnc sim installed from the R13 Stretch testing ISO on a VM.)

Here is the g-code if you want to test it yourself. If you change #5 to some other number like 50 the program runs as intended.
%
#1=2 (X center)
#2=2 (Y cemter)
#3=.5 (Z depth)
#4=2 (Pocket Diameter)
#5=25  (% Overlap)
g20 g64 g90
t5m6
s18000 m3
#7=[#5410/2]
#9=[[100-#5]*.01*#5410/80]
g92.1
g0 z1
g0 x[#1+#7] y#2
G92x#7y0
G1z0f100
g3 z[-#3] i-#7 j0 p[FUP[#3/[[100-#5]*.01*#5410]]]
#8=SQRT[[#<_x>*#<_x>]+[#<_y>*#<_y>]]
#6=[#4-#7-.0001]
(debug, 8 = #8)
o100 while [#8 LT #6]
g91 g1 @#9 ^4.5
#8=SQRT[[#<_x>*#<_x>]+[#<_y>*#<_y>]]
o100 endwhile
(debug, 8 = #8)
g90 g3 i[-#<_x>] j[-#<_y>]
g92.1 
g90 g0 z1
m2
%
Last edit: 29 May 2019 16:54 by Todd Zuercher.

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

More
29 May 2019 17:16 #135306 by Hakan
Replied by Hakan on topic While Loop Possible Bug(s)?
The first one I would say is because of rounding errors from sqrt or other calculations. You approach it correct but you can add an abs[] function there as well, something like
abs[#<current> - #<endvalue>] LT 0.0001

The other one I don't know. Maybe try to write of the value of #<_x> and #<_y> can give a clue on what is going on.

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

More
29 May 2019 18:06 #135310 by Grotius
Replied by Grotius on topic While Loop Possible Bug(s)?
Todd,

If on your Virtual Machine the code is brought back to the bown in steps you can define a moment that strange things are happening.

I see at your code that i would replace G1z0f100 to G1 Z0 F100 and G92x#7y0 to G92 X#7 Y0

The double % sign's... I don't use them at all for ngc program's and subroutines.

Try it out back to the bone, and step up, step by step. Then you will trigger the bug, Good luck !! B)

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

More
29 May 2019 20:00 - 29 May 2019 20:18 #135321 by Todd Zuercher
The % and upper/lower case have no effect.

Running my code above gives the error where it doesn't mill the finish pass.
If I change the value of parameter #5, valuses 25,26,27, 36, 40 all make the error, but 20-24, 28-30, 35, 42 and 50 do not.

In the attached screen shots you can see that the white line was not exicuted, in the 1st image, and it was in the 2nd. (the retract line after the circle always is executed.)
Attachments:
Last edit: 29 May 2019 20:18 by Todd Zuercher.

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

More
29 May 2019 20:24 #135322 by Hakan
Replied by Hakan on topic While Loop Possible Bug(s)?
On the line with the last circle, should it by any chance be g90.1 instead of g90?

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

More
29 May 2019 20:54 #135324 by Todd Zuercher
Nope, I'd have to change the variables for the arc centers to do that. (and maybe it isn't a bad idea to do that change, since the circles center is known and are varaibles #1 and #2.)
Making that change though has no effect on the error.

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

More
29 May 2019 21:50 #135326 by Todd Zuercher
It took some ugliness, but I think I was able to work around what ever bug that is. by finishing the quadrant arc where ever the spiral finished then doing a complete circle. Doesn't seem like that should be necessary but it is what it is. (also fixed an error I made with the pocket diameter, it was radius by mistake.)
#1=2 (X center)
#2=2 (Y cemter)
#3=.5 (Z depth)
#4=2 (Pocket Diameter)
#5=30.5 (% Overlap)
g20 g64p.001 g90
t5m6
s18000 m3
#7=[#5410/2]
#9=[[100-#5]*.01*#5410/80]
g92.1g91.1
g0 z1
g0 x[#1+#7] y#2
G92x#7y0
G1z0f100
g3 z[-#3] i-#7 j0 p[FUP[#3/[[100-#5]*.01*#5410]]]
#8=SQRT[[#<_x>*#<_x>]+[#<_y>*#<_y>]]
#6=[#4/2-#7]
(debug, 8 = #8)
o100 while [#6-#8 GT .001]
g91 g1 @#9 ^4.5
#8=SQRT[[#<_x>*#<_x>]+[#<_y>*#<_y>]]
o100 endwhile
(debug, 8 = #8)
g92.1 g90 g90.1
o110 if [#<_x> GE 0 AND #<_y> GE 0]
g90.1g3 x#1 y[#2+#6] i#1 j#2
o110 elseif [#<_x> LT 0 AND #<_y> GE 0]
g90.1g3 x[#1-#6] y#2 i#1 j#2
o110 elseif [#<_x> LT 0 AND #<_y> LT 0]
g90.1g3 x#1 y[#2-#6] i#1 j#2
o110 elseif [#<_x> GE 0 AND #<_y> GE 0]
g90.1g3 x[#1+#6] y#2 i#1 j#2
o110 endif
g90.1g3 i#1 j#2
g92.1g91.1
g90 g0 z1
m2

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

More
30 May 2019 02:19 #135344 by rodw
Replied by rodw on topic While Loop Possible Bug(s)?
Not knowing the inner workings of Gcode but it is possible this due to a mismatch between the decimal numbers (base 10) used in Gcode and the hexadecimal numbering system (base 16) the CPU uses internally. Working with decimal precision is fraught with errors becasue of this. Many business programming languages (and SQL databases) add a decimal type to work around this. I am sure LinuxCNC doesn't.

One workaround might be to calculate the number of passes required before entering the loop and use that value to control the loop. That way you only introduce the rounding error to the system once rather than on each loop iteration where it could accumulate.

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

More
30 May 2019 06:53 #135364 by Hakan
Replied by Hakan on topic While Loop Possible Bug(s)?
I tested the code in the first post on my milling machine it's running master. Can not replicate the error.
Tried with #5=25 and 26, the final circle gets done here.

I made a quick check in the code, and from what I can see it's all standard double-precision math internally.

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

More
30 May 2019 12:53 #135383 by andypugh
The screen-shots seem to suggest that it was skipping the (DEBUG) on line 25 too. Is that the case?

So, is there any chance that the interpreter was crashing due to being asked to calculate the sqrt of a negative number?

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

Time to create page: 0.230 seconds
Powered by Kunena Forum