Making 3D Surface more efficient

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!
acp693
Posts: 126
Joined: Wed Dec 15, 2021 7:41 pm

Making 3D Surface more efficient

Post by acp693 »

Hi, I'm working on a project that has a large 3d surface to mill. The attached model is a much smaller model with similar features to illustrate the problem that's small enough to attach here.

I'm using the 3D Surface function, multipass, Optimize linear Paths and Optimize Stepover Transitions are enabled, cut pattern is Offset.

The calculated path shows some large loops that are raised to a 'Safe' height that is neither the safe height or clearance height specified in the Heights dialogue. These paths are very inefficient as they are G1 moves in the exported G-Code. Is there a way to simply move from A to B as marked on the attached image as a G0 Move? In my real model, these extra moves add considerable time to the machining. I've looked at Surface.py several times and simply don't understand enough about the code to optimize these moves.

Any idea, thoughts will be much appreciated!
Loops2.png
Loops2.png (502.43 KiB) Viewed 820 times

Code: Select all

OS: Windows 10 build 19045
Word size of FreeCAD: 64-bit
Version: 0.21.2.33771 (Git)
Build type: Release
Branch: (HEAD detached at 0.21.2)
Hash: b9bfa5c5507506e4515816414cd27f4851d00489
Python 3.10.13, Qt 5.15.8, Coin 4.0.0, Vtk 9.2.6, OCC 7.6.3
Locale: German/Germany (de_DE)
Installed mods: 
  * CurvedShapes 1.0.4
  * Curves 0.5.3
  * ExtremeProLight 1.4.3
  * FeedsAndSpeeds 0.5.0
  * Manipulator 1.5.0
  * Marz 0.0.26-alpha
  * Silk 1.0.0
Attachments
Loops.FCStd
(446.49 KiB) Downloaded 13 times
Dimitrios2
Posts: 103
Joined: Tue Feb 21, 2023 9:30 pm

Re: Making 3D Surface more efficient

Post by Dimitrios2 »

The best I can do without making it too heavy to process... Still no Rapid but, at least the lines are straight and shorter.

Send me your Surface.py file to modified for you.

Test the Code before use it. Appears to be OK but...
Attachments
Screenshot from 2024-02-12 12-50-51.png
Screenshot from 2024-02-12 12-50-51.png (205.29 KiB) Viewed 672 times
acp693
Posts: 126
Joined: Wed Dec 15, 2021 7:41 pm

Re: Making 3D Surface more efficient

Post by acp693 »

Hi @Dimitrios2 Thank you so much, this looks like a really useful improvement!

I've sent you my file in a PM

Could this code be incorporated officially into Freecad Path workbench?

Thanks again!
Dimitrios2
Posts: 103
Joined: Tue Feb 21, 2023 9:30 pm

Re: Making 3D Surface more efficient

Post by Dimitrios2 »

Hi,

I think I'm seeing is a better way to fix these, rapid included and possibly make faster. If have time I may try it...

There is also an issue with Spiral Pattern and Multi-Pass. A piece of Code is missing in SurfaceSupport.py file.

That's a temp fix. You should report this as a bug.

I've already send you a PM.
Dimitrios2
Posts: 103
Joined: Tue Feb 21, 2023 9:30 pm

Re: Making 3D Surface more efficient

Post by Dimitrios2 »

Hi,

I think I may have something but, not fully tested yet. Try it very carefully!!! The Spiral Cut Pattern is not working, needs a bit more work.

Not recommended for finishing pass

let's hope for the best
Attachments
Surface.py
(106.18 KiB) Downloaded 6 times
Screenshot from 2024-02-17 14-52-25.png
Screenshot from 2024-02-17 14-52-25.png (254.28 KiB) Viewed 438 times
acp693
Posts: 126
Joined: Wed Dec 15, 2021 7:41 pm

Re: Making 3D Surface more efficient

Post by acp693 »

@Dimitrios2 Just downloaded. Many thanks for this, it looks very promising!
Dimitrios2
Posts: 103
Joined: Tue Feb 21, 2023 9:30 pm

Re: Making 3D Surface more efficient

Post by Dimitrios2 »

acp693 wrote: Sat Feb 17, 2024 2:28 pm @Dimitrios2 Just downloaded. Many thanks for this, it looks very promising!
You may get an error from time to time. Try a bigger or smaller step over. There is a way to become rock solid but, it will be heavy and I tried to minimize looping through code as much as possible.. There is room for improvement thought. I will get back on it when I have more time...
User avatar
freman
Veteran
Posts: 2152
Joined: Tue Nov 27, 2018 10:30 pm

Re: Making 3D Surface more efficient

Post by freman »

Thanks for digging into this Dimitrios.

I think the big problem with 3dSurface is its inefficient use of the underlying openCascade library.

Someone did some profiling a few years back and showed that the vast majority of run time was spent in the c code, not the python which is calling it.

I did spend some time trying to parse the openCascade code but it's horribly convoluted.

My conclusion was that 3dSurface is repeatedly calling the code which does the heavy lifting of the geometry but recalculates the same geometry hundreds if not thousands of times, for each microstep of the 3D path.

It seems there needs to be a way to return and the store the C language object and pass back a pointer instead of redoing it all every time. Since the code is going through nested calls and is hard to follow , I never got the stage where is could locate a specific solution. I guess this is why they went for a full rewrite and made the original code OSS.

If this could be cracked I'm fairly convinced that 3DSurface could become about two or three orders of magnitude faster !

I've had some paths take 25min to return and some I just had to dump because of insane CPU time. I'd prefer 25s.
acp693
Posts: 126
Joined: Wed Dec 15, 2021 7:41 pm

Re: Making 3D Surface more efficient

Post by acp693 »

@Dimitrios2 After spending some time just using the attached test model (because calculation times are bearable) I've found that Small step downs (less than about 2.2mm and samll stepovers (less than 50) cause the error you mentioned. In any case, thank you for your effort, it's already a big improvement.

@freman That is very interesting. Yes, with large models it's painfully slow, On the model I'm working on, calculation is taking around 65 minutes for a multipass 3d surface whereas other softwares can generate similar paths in less than a minute.
User avatar
freman
Veteran
Posts: 2152
Joined: Tue Nov 27, 2018 10:30 pm

Re: Making 3D Surface more efficient

Post by freman »

Yes, that confirms my impression there is something fundamentally wrong with the way the library is being used.

Two orders faster would make it liveable. I suspect the gain in speed in this case could be nearer 3 orders.

Russ did some outstanding work bringing 3D to FreeCAD Path. Unfortunately I think he's more of pythonist, with not that much C skill. Hopefully someone with those skills can fix the log-jam and this feature would finally come of age.
Post Reply