Question on using FP numbers in python 2
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Feb 15 10:27:29 EST 2014
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
More information about the Python-list
mailing list