Question on using FP numbers in python 2

G

Gene Heskett

Greetings;

Is there something I can search for and fix in some python code that is
giving me bogus answers that get good only when there is a valid digit to
the left of the decimal point?

Cheers, Gene
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page <http://geneslinuxbox.net:6309/gene>

NOTICE: Will pay 100 USD for an HP-4815A defective but
complete probe assembly.
 
S

Steven D'Aprano

Greetings;

Is there something I can search for and fix in some python code that is
giving me bogus answers that get good only when there is a valid digit
to the left of the decimal point?

Er, yes? Anything which involves floating point maths?

Your question is to vague to really answer. You are basically saying "I'm
doing some calculations [what sort of calculations?] with floats [how
many floats? of what values?], and they're wrong [wrong in what way? how
badly wrong?] unless there is a valid digit [which digits count as valid
and which as invalid?] to the left of the decimal point in some number."

Can you extract the float calculations and show us, together with some
sample data, expected result, and actual result?
 
G

Grant Edwards

Is there something I can search for and fix in some python code that
is giving me bogus answers that get good only when there is a valid
digit to the left of the decimal point?

Yes.

Search for incorrectly written code and fix it. I'd start part way
down in that one file, and then also look in that other file, but not
as far down.

At least he doesn't think he's using real numbers...
 
G

Gene Heskett

Greetings;

Is there something I can search for and fix in some python code that
is giving me bogus answers that get good only when there is a valid
digit to the left of the decimal point?

Er, yes? Anything which involves floating point maths?

Your question is to vague to really answer. You are basically saying
"I'm doing some calculations [what sort of calculations?] with floats
[how many floats? of what values?], and they're wrong [wrong in what
way? how badly wrong?] unless there is a valid digit [which digits
count as valid and which as invalid?] to the left of the decimal point
in some number."

Can you extract the float calculations and show us, together with some
sample data, expected result, and actual result?

Not extract, but let you get & look at the code, its the top entry on this
page:

<http://wiki.linuxcnc.org/cgi-bin/wiki.pl?Simple_LinuxCNC_G-
Code_Generators#Counterbore_Software>

Assume no bolt size is clicked on, but a wanted diameter is entered in the
lower left pair of boxes, and its to carve .700" deep in the other box.
The cutting tool is .250 in diameter, its to do a stepover of 25% of the
tool diameter, while carving an additional .015" out of the .850" hole with
the tool bit turning 2000 rpm as it spirals down.

But the hole it will cut will only be .650" in diameter, And the backplot,
shown in the axis interface, shows no spiral, its doing what it thinks is
full diameter in one circular plunge cut. That would leave a big post of
steel in the center, so I will have to drill it to perhaps a half an inch
just to keep from pinching & breaking a $20 bit. But that is a separate
problem.

So, I added a .2" offset to the hole diameter, making that entry 1.05".

Then I do get the spiral outward feed, but to make a hole 1.05" in
diameter.

As for me fixing it, that 30+ kilobytes of python may as well be Navajo.

IOW, help please?

Cheers, Gene
 
C

Chris Angelico

Not extract, but let you get & look at the code, its the top entry on this
page:

<http://wiki.linuxcnc.org/cgi-bin/wiki.pl?Simple_LinuxCNC_G-
Code_Generators#Counterbore_Software>

Interesting. At the top of the file, it says GPL3 or later; but then
it puts a requirement on making money off the software. I'm not sure
that's a good thing (what if someone lifts a small part of that code
out and into another GPL project?), and I'm not sure it's
legal/enforceable anyway.

The GUI creation code calls to mind the discussion we had a little
while ago about an alternative way to create a GUI in Python.
Especially compare the GTK2Table() function that I posited - I'm sure
it wouldn't be hard to make a Python (and Tkinter) equivalent.
Massively complicated code for laying out a grid/table.

But check out these comments:

def GeneratePath(self):
# If ToolDiameter > HoleDiameter then Complain
# If ToolDiameter == HoleDiameter then Plunge to HoleDepth
# If (ToolDiameter*1.25) <= HoleDiameter then Plunge to each
Level and Spiral out to HoleDiameter
# If (ToolDiameter*1.25) > HoleDiameter then Spiral to each
Level and Spiral out to HoleDiameter

(Also, owwww! The GeneratePath function is indented with a mixture of
spaces and tabs. Most of it is indented "four spaces and then a tab",
but some lines use other mixtures. Ow ow ow!)

Does all that make sense, and are you seeing those boundaries
correctly? I strongly suspect you're not seeing a floating-point
error, but a deliberate piece of code and maybe some other form of
bug. I very much doubt the boundary is anything to do with going over
1" in diameter; the numbers you're working with here are easily within
Python's capability (you get roughly 15 decimal digits of accuracy
with the default float type).

I'm afraid I can't really help more, as I don't speak CNC. But have a
look at GeneratePath(); it does have comments, and for all of being
two hundred lines of code, it's reasonably segmented into sections.
Manually step through it, see where it's going wrong. Standard Python
debugging, nothing to do with floats AFAICT.

ChrisA
 
G

Gene Heskett

Interesting. At the top of the file, it says GPL3 or later; but then
it puts a requirement on making money off the software. I'm not sure
that's a good thing (what if someone lifts a small part of that code
out and into another GPL project?), and I'm not sure it's
legal/enforceable anyway.

The GUI creation code calls to mind the discussion we had a little
while ago about an alternative way to create a GUI in Python.
Especially compare the GTK2Table() function that I posited - I'm sure
it wouldn't be hard to make a Python (and Tkinter) equivalent.
Massively complicated code for laying out a grid/table.

But check out these comments:

def GeneratePath(self):
# If ToolDiameter > HoleDiameter then Complain
# If ToolDiameter == HoleDiameter then Plunge to HoleDepth
# If (ToolDiameter*1.25) <= HoleDiameter then Plunge to each
Level and Spiral out to HoleDiameter
# If (ToolDiameter*1.25) > HoleDiameter then Spiral to each
Level and Spiral out to HoleDiameter

(Also, owwww! The GeneratePath function is indented with a mixture of
spaces and tabs. Most of it is indented "four spaces and then a tab",
but some lines use other mixtures. Ow ow ow!)

Does all that make sense, and are you seeing those boundaries
correctly? I strongly suspect you're not seeing a floating-point
error, but a deliberate piece of code and maybe some other form of
bug. I very much doubt the boundary is anything to do with going over
1" in diameter; the numbers you're working with here are easily within
Python's capability (you get roughly 15 decimal digits of accuracy
with the default float type).

I'm afraid I can't really help more, as I don't speak CNC.

Actually, the output is RS-274-D, originally from NIST. But it has
developed some pretty distinct "accents" in the 20 some years its been in
the wild. The NIST version was, shall we say, quite incomplete but a lot
of the stuff shoved in to scratch this or that itch is often vaguely
incompatible with the next vendors version of that particular function.
But have a
look at GeneratePath(); it does have comments, and for all of being
two hundred lines of code, it's reasonably segmented into sections.
Manually step through it, see where it's going wrong. Standard Python
debugging, nothing to do with floats AFAICT.

ChrisA

I'll do that when next I have both eyes open at the same time. That is
usually about halfway thru the third cuppa. :)

Thanks Chris A.

Cheers, Gene
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page <http://geneslinuxbox.net:6309/gene>

NOTICE: Will pay 100 USD for an HP-4815A defective but
complete probe assembly.
 
C

Chris Angelico

Actually, the output is RS-274-D, originally from NIST. But it has
developed some pretty distinct "accents" in the 20 some years its been in
the wild. The NIST version was, shall we say, quite incomplete but a lot
of the stuff shoved in to scratch this or that itch is often vaguely
incompatible with the next vendors version of that particular function.

Ehh, I don't speak that either, but now I feel like a guy who's told
"Polly voo Fronsay?" and says that he don't speak no Eyetalon. :)

ChrisA
 
S

Steven D'Aprano

Not extract, but let you get & look at the code, its the top entry on
this page:

<http://wiki.linuxcnc.org/cgi-bin/wiki.pl?Simple_LinuxCNC_G-
Code_Generators#Counterbore_Software>

Here is the direct link to the Python code:

http://wiki.linuxcnc.org/uploads/counterbore.py

Assume no bolt size is clicked on, but a wanted diameter is entered in
the lower left pair of boxes, and its to carve .700" deep in the other
box. The cutting tool is .250 in diameter, its to do a stepover of 25%
of the tool diameter, while carving an additional .015" out of the .850"
hole with the tool bit turning 2000 rpm as it spirals down.

If I've understood the purpose of this program correctly, it generates
code in some language called "G-code", presumably to control some sort of
actual physical cutting machine. So the first thing you ought to do is
have a G-code expert look at the generated code and tell you it does what
it is supposed to do. Or perhaps your cutting machine is buggy.
But the hole it will cut will only be .650" in diameter, And the
backplot, shown in the axis interface, shows no spiral, its doing what
it thinks is full diameter in one circular plunge cut.


Scroll to the GeneratePath method, and read the comments at the top of
the method. They tell you that the *intention* is:

* If the tool diameter equals the hole diameter, then just Plunge
down to the hole depth.

* If the tool diameter is less than 80% of the hole diameter,
then Plunge to each Level and Spiral out.

* If the tool diameter is greater than 80% of the hole diameter,
then Spiral to each Level and Spiral out.

But a little later, we see this code:

# Figure out what kind of entry into the hole
if (self.ToolDiameter * 1.25 <= self.HoleDiameter):
self.CutType = 'Spiral Down to Depth of each Pass and Spiral Out'
else:
if (self.ToolDiameter < self.HoleDiameter):
self.CutType = 'Plunge Down to Depth of each Pass and Spiral
Out'
else:
self.CutType = 'Plunge Down to Hole Depth'


Assuming that the comments are correct, the CutType is wrong. It looks
like a simple logic error, and should be something like this:

# Figure out what kind of entry into the hole
if (self.ToolDiameter * 1.25 <= self.HoleDiameter):
self.CutType = 'Plunge down and spiral out'
elif (self.ToolDiameter * 1.25 > self.HoleDiameter):
self.CutType = 'Spiral down and spiral out'
else:
self.CutType = 'Plunge down'

CutType is, I believe, merely a comment, but it leads me to believe that
there are probably similar logic errors in the rest of the GeneratePath
method. In fact, the description states:

"At this time there is a bug if you have a path that does not require a
spiral... working on it"
 
G

Gene Heskett

Here is the direct link to the Python code:

http://wiki.linuxcnc.org/uploads/counterbore.py


If I've understood the purpose of this program correctly, it generates
code in some language called "G-code", presumably to control some sort
of actual physical cutting machine.

More or less standard cNC machine control language.
So the first thing you ought to do
is have a G-code expert look at the generated code and tell you it does
what it is supposed to do.
I think I might qualify for that expert label. Looking at the output code,
take the maximum X values it outputs plus and minus, add, then add the tool
diameter to get the size of the pocket it will cut. I don't need a
graphical backplot to check that.
Or perhaps your cutting machine is buggy.

Not impossible, but that part of the scaling code is 20+ years mature. It
knows exactly how many times to step the motor to move the tables 20 feet
with micron accuracy if there is no mechanical backlash between the motor
and the table. Unfortunately there is in my toy mill, which is whats
driving me to install ball screws in the table drives, which can have
backlashes well under .0001" if properly made.
Scroll to the GeneratePath method, and read the comments at the top of
the method. They tell you that the *intention* is:

* If the tool diameter equals the hole diameter, then just Plunge
down to the hole depth.

* If the tool diameter is less than 80% of the hole diameter,
then Plunge to each Level and Spiral out.

* If the tool diameter is greater than 80% of the hole diameter,
then Spiral to each Level and Spiral out.

But a little later, we see this code:

# Figure out what kind of entry into the hole
if (self.ToolDiameter * 1.25 <= self.HoleDiameter):
self.CutType = 'Spiral Down to Depth of each Pass and Spiral
Out' else:
if (self.ToolDiameter < self.HoleDiameter):
self.CutType = 'Plunge Down to Depth of each Pass and Spiral
Out'
else:
self.CutType = 'Plunge Down to Hole Depth'


Assuming that the comments are correct, the CutType is wrong. It looks
like a simple logic error, and should be something like this:

# Figure out what kind of entry into the hole
if (self.ToolDiameter * 1.25 <= self.HoleDiameter):
self.CutType = 'Plunge down and spiral out'
elif (self.ToolDiameter * 1.25 > self.HoleDiameter):
self.CutType = 'Spiral down and spiral out'
else:
self.CutType = 'Plunge down'

CutType is, I believe, merely a comment, but it leads me to believe that
there are probably similar logic errors in the rest of the GeneratePath
method. In fact, the description states:

"At this time there is a bug if you have a path that does not require a
spiral... working on it"

And I just heard back, he is looking at it again.

Thanks Steven.

Cheers, Gene
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page <http://geneslinuxbox.net:6309/gene>

NOTICE: Will pay 100 USD for an HP-4815A defective but
complete probe assembly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,610
Members
45,254
Latest member
Top Crypto TwitterChannel

Latest Threads

Top