face mill div zero

Here's the place for discussion related to CAM/CNC and the development of the Path module.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
freman
Veteran
Posts: 2198
Joined: Tue Nov 27, 2018 10:30 pm

face mill div zero

Post by freman »

Hi,

I did a new pull from master yesterday and I'm getting a div zero error when I try to create a face milling operation:

Code: Select all

06:11:11  Free SelectOS: Fedora 31 (Thirty One) (LXDE/LXDE)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22808 (Git)
Build type: Release
Branch: master
Hash: 72eb41b24f12b572d55081042160954b93f4614c
Python version: 3.7.9
Qt version: 5.13.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United Kingdom (en_GB)

06:11:11  Traceback (most recent call last):
  File "/~/freecad-build/Mod/Path/PathScripts/PathUtils.py", line 62, in new_function
    res = function(*args, **kwargs)
  File "/~/freecad-build/Mod/Path/PathScripts/PathOp.py", line 525, in execute
    result = self.opExecute(obj)  # pylint: disable=assignment-from-no-return
  File "/~/freecad-build/Mod/Path/PathScripts/PathAreaOp.py", line 389, in opExecute
    self.axialFeed = 360 / safeCircum * self.horizFeed # pylint: disable=attribute-defined-outside-init
<class 'ZeroDivisionError'>: float division by zero
I think I saw PathAreaOp.py as one of the files which got updated so this may be a recent regression.

OS: Fedora 31 (Thirty One) (LXDE/LXDE)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22808 (Git)
Build type: Release
Branch: master
Hash: 72eb41b24f12b572d55081042160954b93f4614c
Python version: 3.7.9
Qt version: 5.13.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United Kingdom (en_GB)
Attachments
path-div-zero.FCStd
(24.95 KiB) Downloaded 24 times
User avatar
freman
Veteran
Posts: 2198
Joined: Tue Nov 27, 2018 10:30 pm

Re: face mill div zero

Post by freman »

Also enableRotation is off for this path and this code should not be getting called at all.

If set enableRotation to A(x) I do get what looks like a correct face mill path that I would expect without rotation but still get the div zero.

I think I've found the trigger for this bug. In this file the stock top Z is at -2 , ie the stock is smaller than the modelled part. This is not normally expected however this should be possible. There may be some assumption in the code.

It certainly should not be setting enableRotation on a traditional 2.5D facing op.
Russ4262
Posts: 941
Joined: Sat Jun 30, 2018 3:22 pm
Location: Oklahoma
Contact:

Re: face mill div zero

Post by Russ4262 »

Got you covered.

Added fix to existing PR #3916, Path: Pocket_Shape - Improved fixes for FinalDepth and rotational issues, since it touches the PathAreaOp module. It will likely be a few days or longer for merger due to existing Travis CI issues.

Russell
User avatar
freman
Veteran
Posts: 2198
Joined: Tue Nov 27, 2018 10:30 pm

Re: face mill div zero

Post by freman »

nice work Russ.

So that bug was just an indentation issue , LOL. That is one of the most insane aspects of python, where the entire structure of a program can be changed by a missing or incorrect indentation. This often makes it very hard to work out where the real cause of the syntax error is.

It seems this wacko feature has no reason to exist apart from just being done to be different. They were trying make a new language so had to play at Bill Gates and change stuff for the sake of it.

My favourite for this remains Algol-68 where all blocks had their own terminator keywords if .... fi ; while .... wend; etc. a great idea. A stack of closing curly brackets is not much help in C either.

Anyway, thanks for the quick fix. I'll make a local correction until it filters through. Hopefully Travis folks will do less of the identity politics and fix the software.
warnerjonn
Posts: 2
Joined: Thu Jun 16, 2022 6:03 am

Re: face mill div zero

Post by warnerjonn »

freman wrote: Thu Oct 22, 2020 5:16 am

Code: Select all

<class 'ZeroDivisionError'>: float division by zero
The super class of ZeroDivisionError is ArithmeticError. This exception raised when the second argument of a division or modulo operation is zero. In Mathematics, when a number is divided by a zero, the result is an infinite number. It is impossible to write an Infinite number physically. Python interpreter throws “ZeroDivisionError: division by zero” error if the result is infinite number. While implementing any program logic and there is division operation make sure always handle ArithmeticError or ZeroDivisionError so that program will not terminate.

try:

Code: Select all

    z = x / y
except ZeroDivisionError:
    z = 0
Or check before you do the division:

Code: Select all

if y == 0:
    z = 0
else:
    z = x / y
The latter can be reduced to:

Code: Select all

z = 0 if y == 0 else (x / y) 
Post Reply