Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66355 > unrolled thread
| Started by | Gene Heskett <gheskett@wdtv.com> |
|---|---|
| First post | 2014-02-14 22:25 -0500 |
| Last post | 2014-02-15 17:08 +1100 |
| Articles | 9 — 4 participants |
Back to article view | Back to comp.lang.python
Question on using FP numbers in python 2 Gene Heskett <gheskett@wdtv.com> - 2014-02-14 22:25 -0500
Re: Question on using FP numbers in python 2 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-15 04:26 +0000
Re: Question on using FP numbers in python 2 Gene Heskett <gheskett@wdtv.com> - 2014-02-15 00:07 -0500
Re: Question on using FP numbers in python 2 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-15 15:27 +0000
Re: Question on using FP numbers in python 2 Gene Heskett <gheskett@wdtv.com> - 2014-02-15 12:27 -0500
Re: Question on using FP numbers in python 2 Chris Angelico <rosuav@gmail.com> - 2014-02-15 16:28 +1100
Re: Question on using FP numbers in python 2 Grant Edwards <invalid@invalid.invalid> - 2014-02-15 04:35 +0000
Re: Question on using FP numbers in python 2 Gene Heskett <gheskett@wdtv.com> - 2014-02-15 00:50 -0500
Re: Question on using FP numbers in python 2 Chris Angelico <rosuav@gmail.com> - 2014-02-15 17:08 +1100
| From | Gene Heskett <gheskett@wdtv.com> |
|---|---|
| Date | 2014-02-14 22:25 -0500 |
| Subject | Question on using FP numbers in python 2 |
| Message-ID | <mailman.6953.1392434770.18130.python-list@python.org> |
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.
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-02-15 04:26 +0000 |
| Message-ID | <52feec65$0$29973$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #66355 |
On Fri, 14 Feb 2014 22:25:59 -0500, Gene Heskett wrote: > 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? -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Gene Heskett <gheskett@wdtv.com> |
|---|---|
| Date | 2014-02-15 00:07 -0500 |
| Message-ID | <mailman.6961.1392440873.18130.python-list@python.org> |
| In reply to | #66362 |
On Friday 14 February 2014 23:47:26 Steven D'Aprano did opine: > On Fri, 14 Feb 2014 22:25:59 -0500, Gene Heskett wrote: > > 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 -- "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>
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-02-15 15:27 +0000 |
| Message-ID | <52ff8760$0$29973$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #66368 |
On Sat, 15 Feb 2014 00:07:49 -0500, Gene Heskett wrote:
>> 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>
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"
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Gene Heskett <gheskett@wdtv.com> |
|---|---|
| Date | 2014-02-15 12:27 -0500 |
| Message-ID | <mailman.7012.1392485263.18130.python-list@python.org> |
| In reply to | #66451 |
On Saturday 15 February 2014 12:13:42 Steven D'Aprano did opine: > On Sat, 15 Feb 2014 00:07:49 -0500, Gene Heskett wrote: > >> 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> > > 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. 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. > > 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" 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.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-02-15 16:28 +1100 |
| Message-ID | <mailman.6963.1392442106.18130.python-list@python.org> |
| In reply to | #66362 |
On Sat, Feb 15, 2014 at 4:07 PM, Gene Heskett <gheskett@wdtv.com> wrote:
> 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
[toc] | [prev] | [next] | [standalone]
| From | Grant Edwards <invalid@invalid.invalid> |
|---|---|
| Date | 2014-02-15 04:35 +0000 |
| Message-ID | <ldmqq2$qeb$2@reader1.panix.com> |
| In reply to | #66355 |
On 2014-02-15, Gene Heskett <gheskett@wdtv.com> wrote: > 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...
[toc] | [prev] | [next] | [standalone]
| From | Gene Heskett <gheskett@wdtv.com> |
|---|---|
| Date | 2014-02-15 00:50 -0500 |
| Message-ID | <mailman.6965.1392443457.18130.python-list@python.org> |
| In reply to | #66355 |
On Saturday 15 February 2014 00:43:53 Chris Angelico did opine: > On Sat, Feb 15, 2014 at 4:07 PM, Gene Heskett <gheskett@wdtv.com> wrote: > > 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. 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.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-02-15 17:08 +1100 |
| Message-ID | <mailman.6967.1392444527.18130.python-list@python.org> |
| In reply to | #66355 |
On Sat, Feb 15, 2014 at 4:50 PM, Gene Heskett <gheskett@wdtv.com> wrote: >> 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. 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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web