NaN in G code

Help for setting up and using
Hessel Oosten
Posts: 24
Joined: Sat Oct 12, 2013 8:36 pm

Re: NaN in G code

Post by Hessel Oosten »

Probably good to mention that the strange "NaN" 's I got in the 0.77 output-code (see first message here in this thread) were probably due to the missing G21 !?

Now, when putting it manually it in the source code.... that strange "non-code-above" is GONE !

Shortened example to prove it ...:-), below.

Hessel

////


(Set S value to ensure Speed has a value otherwise the spindle will not start on an M3 command)
S20000

(The program will pause to allow the probe to be detached)
(press cycle start to resume from current line)
M0


(The original mill file is now rewritten with z depth replaced with a)
(bilinear interpolated value based on the initial probing)

(Generated by ColiCAM Version: 3.54 Revision: 2013/01/20)
(TOOL LIST:)
(T3 3.000mm Id=81 Flat end mill ø 3,00 mm)
G21
G94
G0 Z20
G0 X0 Y0
(Id=81 Flat end mill ø 3,00 mm 3.000mm)
T3
G97 M3 S24000
G0 Z20
G0 X0 Y0
G0 Z0.5
#102=#500
#101=[#500+0*#505-0*#500]
#100=[#102+0*#101-0*#102]
G1 Z[#100 + -1] F15
#102=[#500+0*#505-0*#500]
#101=[#501+0*#506-0*#501]
#100=[#102+0.5*#101-0.5*#102]
G1 X5 Y0 Z[#100 + -1] F96
#102=[#500+0*#505-0*#500]
#101=[#501+0*#506-0*#501]
#100=[#102+1*#101-1*#102]
G1 X10 Y0 Z[#100 + -1] F96
#102=[#501+0*#506-0*#501]
#101=[#502+0*#507-0*#502]
#100=[#102+0.5*#101-0.5*#102]
G1 X15 Y0 Z[#100 + -1] F96
#102=[#501+0*#506-0*#501]
#101=[#502+0*#507-0*#502]
#100=[#102+1*#101-1*#102]
G1 X20 Y0 Z[#100 + -1] F96
#102=[#502+0*#507-0*#502]
#101=[#503+0*#508-0*#503]
#100=[#102+0.5*#101-0.5*#102]
Hessel Oosten
Posts: 24
Joined: Sat Oct 12, 2013 8:36 pm

Re: NaN in G code

Post by Hessel Oosten »

Hi James,

When doing some experiments this morning with "the other topic"
(keeping Z variables after probing; later on that again if this below has a solution)
I encountered again the reading error in mach3 which is caused by "NaN" produced by AL in the code.

We thought (first message here in the row) that is was caused by the absense of a G21 in the code but it now appears also WITH an existing G21 (and adequate recognising in the AL screen).

Small part of the original code:G90 G21

G90 G21G94
G00 Z-15.000
G00 X0.000 Y0.000
(V-Groove router 45° ø 2,00 mm 2.000 mm)
T01
M1005 (SLOT)
M6
G97 M04 S24000
G00 Z0.000
G00 X3.808 Y8.751
G00 Z-29.000
G01 Z-30.150 F30.000 etc etc.

And part of the AL code: (generated with all default AL settings)

(The program will pause to allow the probe to be detached)
(press cycle start to resume from current line)
M0
(The original mill file is now rewritten with z depth replaced with a)
(bilinear interpolated value based on the initial probing)
(TOOL LIST:)

(T1 - Ø2.000 mm -> V-Groove router 45° ø 2,00 mm)

G90 G21G94
#102=#500
#101=#500
#100=[#102+NaN*#101-NaN*#102]
G0 Z[#100 + -15]
#102=[#500+0.0755*#509-0.0755*#500] etc etc.

Hope this information is helpfull.
Idea's (and even better) solutions ...:-) ?

Hessel
daedelus
Site Admin
Posts: 387
Joined: Tue Oct 01, 2013 1:41 pm
Location: London, UK
Contact:

Re: NaN in G code

Post by daedelus »

Hi Hessel,

I am aware that the NaN issue has arisen again. Ken sent me one of his original gcode files (which caused the NaN problem) and I was going to use that to work on the problem. Unfortunately I lost his file when I changed my web host. Could you please send me your original gcode file to daedelus@autoleveller.co.uk or attach it to a post in this forum.

In the meantime though, there is a very easy workaround...
If you alter the "probe spacing" value in autoleveller then re-generate the AL file then the NaN's should be gone. If not, just repeat with different "probe spacing" values until they are gone.
http://www.autoleveller.co.uk/. Software to probe and adjust a GCode file for PCB's or any probe-able surface.

http://www.autoleveller.co.uk/cnc-probe-guide/. A short guide to setting up the probe.

-James
Hessel Oosten
Posts: 24
Joined: Sat Oct 12, 2013 8:36 pm

Re: NaN in G code

Post by Hessel Oosten »

Hi James,

Thanks for the fast reply !
Will send you within seconds ...:-)the original and generated code to the mentioned mail address.

Hessel
Hessel Oosten
Posts: 24
Joined: Sat Oct 12, 2013 8:36 pm

Re: NaN in G code

Post by Hessel Oosten »

James,

1. File are send.
2. Just to let you know that changing the probe-spacing-value (tried at least 6 different ones) did not resolve the "NaN"
3. Tried after that with v 0.74 and the same Nan's.

Just to let you know, no hurry ! It should be fun !

Hessel
daedelus
Site Admin
Posts: 387
Joined: Tue Oct 01, 2013 1:41 pm
Location: London, UK
Contact:

Re: NaN in G code

Post by daedelus »

I ran the code you sent through my debugger but if I had been smarter I could have worked it out from your previous post.

The problem is that the autoleveller doesnt understand how you can set a negative Z before the X and Y have been set. So the code:

Code: Select all

G90 G21G94
G00 Z-15.000
G00 X0.000 Y0.000
causes problems with the interpolation methods as the X and Y are still set to NaN before the Z changes. To fix this, just set X and Y yourself before the Z. Like this:

Code: Select all

G90 G21
G94
G00 X0.000 Y0.000 (THIS IS THE LINE I ADDED)
G00 Z-15.000
G00 X0.000 Y0.000
then run this through the autoleveller. The NaN's should then be gone.

I hope this helps,
http://www.autoleveller.co.uk/. Software to probe and adjust a GCode file for PCB's or any probe-able surface.

http://www.autoleveller.co.uk/cnc-probe-guide/. A short guide to setting up the probe.

-James
Zig
Posts: 27
Joined: Wed Oct 02, 2013 12:29 pm

Re: NaN in G code

Post by Zig »

I think it might be interesting to just touch upon the meaning of NaN in Java.

Here is a cut and paste contribution:

"...
NaN stands for Not-a-Number. It can arise in a variety of ways, for example as a result of 0./0., sqrt(-1), or as the result of a calculation involving other NaNs.

The easiest way to check whether v is a NaN is by using Double.isNaN(v):

public static double sum(double arr[]) {
double sum = 0.0;
for (double val : arr) {
if (!Double.isNaN(val)) {
sum += val;
}
}
return sum;
}
..."

I hope this helps the reader.
Hessel Oosten
Posts: 24
Joined: Sat Oct 12, 2013 8:36 pm

Re: NaN in G code

Post by Hessel Oosten »

James,

Seems to be BINGO !

The problem was that for my 2 mills there is different G-code.

The Colinbus router mill ( "Profiler") has its Z coordinates in reverse value's in comparison to my standard heavy metal mill.
So when proucing G code I have to switch this every time.

For the (to early) negative Z values I now have the solution.

THANKS a lot for all you work on this sunday !!!

Hessel
Clenn
Posts: 2
Joined: Fri Jan 23, 2015 5:49 pm

Re: NaN in G code

Post by Clenn »

Hi All,
This workaround has already cost me more than two drills.
I have only 17 mm Z workspace on my Bungard CCD.
And Does not work for me even with this simple code.
There must be something wrong in the program or in Java?

This is a modified Coppercam file and output od Autoleveller 0.86

G21
G00 G90 G94 G40 G54 G80
T7 M06 ( Drilling tool )
M03 S10000
M07
G01 F100 X-50 Y0
G00 F800 Z5
G00 F500 Z2
G00 F800 X0 Y-5.46
G00 F300 Z0
G01 F100 Z-6.7
G00 F500 Z2
G00 F800 Y37.72
G00 F300 Z0
G01 F100 Z-6.7
G00 F500 Z5
G00 F500 X-100
M09
M05
M02
%

beginning of the output file 0,86

G21 (millimeters)
G90 (absolute distance mode, not incremental)

(begin initial probe and set Z to 0)
G0 Z5(Move clear of the board first)
G0 XNaN Y-5.46(Move to bottom left corner)
G0 Z2(Quick move to probe clearance height)
G31 Z-1 F100
G92 Z0
G0 Z2
G31 Z-1 F50
G92 Z0
M40 (Begins a probe log file, when the window appears, enter a name for the log file such as "RawProbeLog.txt")
G0 Z2
G0 XNaN Y-5.46
G31 Z-1 F100
#500=#2002
G0 Z2
G0 XNaN Y3.176
G31 Z-1 F100
#501=#2002
G0 Z2
G0 XNaN Y11.812
G31 Z-1 F100
#502=#2002
G0 Z2
G0 XNaN Y20.448
G31 Z-1 F100
#503=#2002
G0 Z2
G0 XNaN Y29.084
G31 Z-1 F100
#504=#2002
G0 Z2
G0 XNaN Y37.72
G31 Z-1 F100
#505=#2002
G0 Z5 (go to Z finish height)
G0 XNaN Y-5.46 Z5 (go to initial position)
M41 (Closes the opened log file)


Regards, Clenn
daedelus
Site Admin
Posts: 387
Joined: Tue Oct 01, 2013 1:41 pm
Location: London, UK
Contact:

Re: NaN in G code

Post by daedelus »

Just been looking at this...

Code: Select all

G21
G00 G90 G94 G40 G54 G80 
T7 M06 ( Drilling tool )
M03 S10000
M07
G01 F100 X-50 Y0
G00 F800 Z5
G00 F500 Z2
G00 F800 X0 Y-5.46
G00 F300 Z0
G01 F100 Z-6.7
G00 F500 Z2
G00 F800 Y37.72
G00 F300 Z0
G01 F100 Z-6.7
G00 F500 Z5
G00 F500 X-100
M09
M05
M02
%
I ran it through the Autoleveller, and it told me the x length was 0, whereas it should be 50 looking at the gcode.

The problem is that the Z height never gets adjusted below or equal to 0 or if it does it immediately gets re-adjusted to some positive number. Autoleveller assumes that Z0 or less is an actual cutting move and above Z0 is not. To illustrate:

Code: Select all

G01 F100 Z-6.7 (moves Z to -6.7)
G00 F500 Z5 (moves Z back to +5)
G00 F500 X-100 (X-100 move is made at Z5)
When Autoleveller tries to get the full probing extents of your piece, it cant because all your cuts are made above Z0 and dont register as significant with Autoleveller and therefore it thinks the X length is 0 and it cant probe there, therefore it replaces nearly all probing and levelled points with NaN. I hope this makes some sort of sense.

If your machine is set up differently to what Autoleveller expects, I think you may need to make some changes in order to use Autoleveller.
http://www.autoleveller.co.uk/. Software to probe and adjust a GCode file for PCB's or any probe-able surface.

http://www.autoleveller.co.uk/cnc-probe-guide/. A short guide to setting up the probe.

-James
Post Reply