CAM simulation for the Path Workbench

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
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: CAM simulation for the Path Workbench

Post by realthunder »

shaise wrote: Fri Sep 15, 2017 3:30 pm
ickby wrote: Fri Sep 15, 2017 11:51 am I think some CAM simulations works with voxels. OCC has some basic support for that
Thanks!
Indeed voxels is the fastest way. It seems that OCC visualization of voxels is not that good, but it is definitely a path I will explore.

shai
Some brainstorm regarding this voxel idea. You can actually achieve similar effects in FC. First, you need to obtain the Path wires. Basically, just grab the Edges from the Path object's Shape property. You probably need to sort it manually, by playing around with Path.sortWires(). Then checkout how Draft.PathArray generates an array of shapes along a given wire. The code is in Draft.py, class _PathArray. I'd recommend using a simple Cube, which may be the fastest primitive for rendering. You can't really use PathArray directly, because FC is not designed to handle large amount of objects. You CAN directly use Coin3D rendering to duplicate the cube Coin node along the path. If you are not familiar with Coin3D, take a quick look at FC wiki here.

Okay, so if you mange to pull the stunt, and make the above working, you will be getting a large amount of cubes in milling order. If the cubes are small enough, it may actually look nice from a distant (hint, use 'Shaded' display mode). Then simulation is just a matter of hiding/showing those cubes in forward/reversed order.
Try Assembly3 with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
mlampert
Veteran
Posts: 1772
Joined: Fri Sep 16, 2016 9:28 pm

Re: CAM simulation for the Path Workbench

Post by mlampert »

realthunder wrote: Thu Sep 21, 2017 3:00 am
mlampert wrote: Wed Sep 20, 2017 6:22 am I checked that file and the pockets are - weird. Some of them get milled from the bottom up, and two of them get milled in two parts, first upwards from about 3/4 of the total depth to the starting depth, and then downwards from 3/4 to the final depth. It's also changing the patterns on those boundaries (you can see it clearly if you switch to "top view", very noticeable on the cylinder and square holes on the bottom left
The problem is caused by enabling 'MinTravel', which uses 3D sort mode of PathArea. This mode is an experimental attempt for 3D milling. It's half finished and not really tested. I wasn't aware that you guys are using it. The problem is that 3D sorting pretty much ignored retraction path when searching for the next nearest path starting point. That's why you see it reach to the middle of the cylinder. Because if you ignore the retraction, the middle part is the next nearest entry. I'll see what I can do to fix it.
you give sliptonic a feature - he will use it ;)
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: CAM simulation for the Path Workbench

Post by realthunder »

mlampert wrote: Thu Sep 21, 2017 4:36 am I checked that file and the pockets are - weird. Some of them get milled from the bottom up, and two of them get milled in two parts, first upwards from about 3/4 of the total depth to the starting depth, and then downwards from 3/4 to the final depth. It's also changing the patterns on those boundaries (you
I added a new SortGreedy. It's like Sort2D5, which tries to go layer by layer, but will also search the layer below, and goes down even though the current layer is not finished, as long as the path jump is within a 'threshold'. It should be safe to use the tool diameter as the threshold. This is a tricky fix. Please test it thoroughly, to ensure that the path generated is correct and it doesn't break any existing stuff. I've already modified PathPocket.py to reflect the change. My branch is at https://github.com/realthunder/FreeCAD/ ... SortGreedy
Try Assembly3 with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
User avatar
shaise
Posts: 470
Joined: Thu Jun 11, 2015 8:11 am

Re: CAM simulation for the Path Workbench

Post by shaise »

ickby wrote: Wed Sep 20, 2017 3:40 pm Definitely not, but it would still be interesting how much gain you can achieve.
Made some tests with the less accurate cut, I thinks it gives more or less 20 per cent faster performance, however it crashes in mid way:

Code: Select all

Base.FreeCADError: {'swhat': 'Multi cut failed', 'sfunction': '', 'btranslatable': False, 'sfile': '', 'sclassname': 'class Base::RuntimeError', 'breported': True, 'sErrMsg': 'Multi cut failed', 'iline': 0}
I will now investigate other ways. Will take some time, but I don't plan to give up...
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: CAM simulation for the Path Workbench

Post by ickby »

.Will take some time, but I don't plan to give up...
thats the right spirit! Good luck
User avatar
shaise
Posts: 470
Joined: Thu Jun 11, 2015 8:11 am

Re: CAM simulation for the Path Workbench

Post by shaise »

Hi Everyone,

Just a small update on my progress. I decided to move to C++ programming, and work on the mesh directly instead of using OCC's (slow) booleans.
I started from csgjs BSP tree based boolean library. (https://github.com/dabroz/csgjs-cpp)
I worked on it quite a bit as it was very inefficient and slightly buggy, but finally I came up with a solution that is about 10 times faster then FC.
Result after 200 gcode lines (in 30 seconds):
bsp_test1.png
bsp_test1.png (30.51 KiB) Viewed 2173 times
However, this algorithm is inherently problematic as the bsp trees create extremely complex meshes making it memory hungry:
bsp_test2.png
bsp_test2.png (190.18 KiB) Viewed 2173 times
(see the vert counts)

So now I am tackling the algorithm itself to see if its possible to generate less fragmented meshes. Hopefully I find a way, if not, I will go for the easier (and much uglier ) volumetric system.
chrisb
Veteran
Posts: 53939
Joined: Tue Mar 17, 2015 9:14 am

Re: CAM simulation for the Path Workbench

Post by chrisb »

Sounds like lots of work, keep the head up!
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
shaise
Posts: 470
Joined: Thu Jun 11, 2015 8:11 am

Re: CAM simulation for the Path Workbench

Post by shaise »

Hi All,

Ok, after poking around the boolean algorithm, I decided that its too complicated to optimize. So I went for the 'ugly' solution of something like voxels. Since this is relative simple algorithm I have written everything from scratch, so no additional code is needed.

The good news are: it is blazing fast! I managed to reduce the original FC simulation time from 1 hour 25 minutes to a mere 1 second! (for about 3000 G-Commands):
vol_test1.png
vol_test1.png (180.34 KiB) Viewed 2076 times
I have also worked on the final object tessellation so it will not use too many polygons:
vol_test2.png
vol_test2.png (289.36 KiB) Viewed 2076 times
Now for the hard part: This code was written entirely in C++ and hence can not be used as a macro or stand alone workbench. I will probably need to integrate it into the FC code. Any pointers or docs of how to do that, and specially how to write the c++ side of Python objects will be appreciated.

shai
cox
Posts: 971
Joined: Wed Nov 26, 2014 11:37 pm

Re: CAM simulation for the Path Workbench

Post by cox »

wow :-)
Need help? Feel free to ask, but please read the guidelines first
User avatar
shaise
Posts: 470
Joined: Thu Jun 11, 2015 8:11 am

Re: CAM simulation for the Path Workbench

Post by shaise »

Hi Sliptonic,

I have managed to integrate my C++ voxel simulation into FreeCAD. The thing is, since it has C++ code, it can not be a separate module or macro.
I would like to integrate it into main freecad, but before issuing a pull request, I would like to talk to developpers in charge of the Path workbech, to ask some questions and make sure my code is acceptable by them.

Here is a small video of my progress (this is realtime):
phpBB [video]
Last edited by shaise on Thu Oct 26, 2017 2:08 pm, edited 1 time in total.
Post Reply