Adaptive Path/CAM Operation

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
kreso-t
Posts: 115
Joined: Sat Aug 04, 2018 2:32 pm

Adaptive Path/CAM Operation

Post by kreso-t »

Hi,

If someone is interested in Adaptive toolpaths, you may check the mod: https://github.com/kreso-t/FreeCAD_Mod_Adaptive_Path

This is the first version entirely written in python (it is using pyclipper lib), so there is a potential for performance improvements. However it also seem quite usable as is. If you are interested check it out and tell me what you think.

Thx,
BR,
Kreso
roivai
Posts: 117
Joined: Thu Feb 02, 2017 5:29 pm
Location: Oulu, Finland

Re: Adaptive Path/CAM Operation

Post by roivai »

WWWOW! Out of the blue, this comes out. The screenshots you have there look really amazing! That feature - clearing the area between the stock and the object is the thing everyone has been waiting for, I think! Great job! Wow!
kreso-t
Posts: 115
Joined: Sat Aug 04, 2018 2:32 pm

Re: Adaptive Path/CAM Operation

Post by kreso-t »

Thx roivai, I am glad you like it.

I've been working on this for some time trying different approaches, but never posted anything so far :)
The most difficult part was to make it fast enough to be usable, at this point porting the parts of the algorithm to C/C++ would be the next step to make it faster.

If you have any improvement suggestions please let me know.
For now I plan to add the "extra offset" feature (as supported by some other operations) when I again get some free time.

Thx,
BR,
Kreso
User avatar
sliptonic
Veteran
Posts: 3457
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: Adaptive Path/CAM Operation

Post by sliptonic »

Amazing work!

I'm curious about the user use of pyclipper. I've not used this library before. However, Angus Johnson's clipper lib is the basis of libarea/PathArea which underlies all of our current 2D operations.

I would encourage you to chat with @realthunder about extending PathArea rather than starting over from scratch on a C/C++ implementation of anything clipper related.

Really cool stuff though!
roivai
Posts: 117
Joined: Thu Feb 02, 2017 5:29 pm
Location: Oulu, Finland

Re: Adaptive Path/CAM Operation

Post by roivai »

If you have time to write, I would be very interested in hearing details about the algorithm you use. Documentation will also be useful if (and I sincerely hope) it does get integrated into FreeCAD at some point. Is there some published theory about the algorithm or is it completely yours? I quickly read parts of the code and I see you kind of collect the cleared areas to a polygon and increase that until full area is covered? As the user sets the step over percentage, I suppose that is the maximum stepover which is practically achieved when cutting straight and that defines the tool engagement angle which is maintained when cutting arcs/corners? How do you choose where to go next when you complete a trochoidal cut, i.e come to an area where there is nothing to cut anymore? How do you choose the starting point?

Lot's of questions which I could probably partially answer myself if I tried to use it, sorry about that.. :) I will try to test this out tonight.
kreso-t
Posts: 115
Joined: Sat Aug 04, 2018 2:32 pm

Re: Adaptive Path/CAM Operation

Post by kreso-t »

Hi,

I didn't use any special theory, just the combination of usual computational geometry alorithms (most important provided by clipper lib, like point in poligon, poligon clipping, area of polygon, and some additional functions for finding the intersection of line segments, centroid, etc.) and relatively basic linear algebra. The basic idea is, as you already found out, to keep track of the cleared area (desribed as paths/polygons) and then through small enough steps trying to move the tool so that the area of tool shape crossing outside the cleared area is constant over distance travelled (with feedrate and depth of cut beeing constant that should give the constant material removal rate). Each step goes through iterations of different deflection angles and for each iteration the cutting area is calculated, next iteration is guessed by interpolating previous results until the cut area is within the defined error/allowed deviation from the optimal cut. In majority of steps there are only 1-2 iterations per step as the deflection agle tends to be relatively constant (except in the beginning and end of the cut line). The first/starting point is chosen by finding the largest circular area not crossing the boundary of regions being cut. This is done by using clipper offset algorithm (i.e. incremetaly offseting inwards the boundary paths (in steps aprox. to tool radius) until point when all offset paths disapear, then you take the offset paths just right before that point and calculate the centroid for one of them, that gives the center point of one of the largest areas to clear). When the tool reaches the boundary (checked by clipper's "point in polygon" function and then finding the exact intersection point) i.e. at the end of trochoidal cut, the cut is ended and a new start point is calculated. This is done simply by moving (in CCW direction for most outer boundary path and CW direction for inner islands/holes) accros the boundary line until we find first/closest not cleared area in the tool radius span (i.e. where area to cut is above some defined threshold), and then start again stepping from this point. When there are no more such points, the algorithm finishes and generates the GCode for helix ramp and in each step down (i.e. in Z direction) adds the same previously calculated toolpaths with appropriate Z coord.

I hope this makes it a bit clearer, unfortunately I don't have time at the moment to make more detailed documentation (maybe in a week or two)

Thx,
BR,
Kresimir
kreso-t
Posts: 115
Joined: Sat Aug 04, 2018 2:32 pm

Re: Adaptive Path/CAM Operation

Post by kreso-t »

@sliptonic:

Thank you for your interest and encoragement.

I used pyclipper because it gives the python access to all operations of excellent Angus Johnson's clipper lib which is the base for this implementation. I would use Path.Area but it seem to expose the higher level API and not the clipper API directly. I wanted this first version (PoC) to be pure python without any modification to FreeCAD's codebase, and if that works good enough, then it can be optimized further if necessary. It turned out to work better than I initially expected so it may not even need the porting to C/C++.

The only thing is that FreeCAD does not include the pyclipper module by default so it requires additional installation (it's acctually a very small library in terms of footprint) , maybe Path.Area could be extended to provide access to lower level clipper operations (and perhaps some other low level 2d geometry operations - like finding instersection points of path and line segment, etc.) then dependency to pyclipper would not be needed. The other approach would be to entirely implement adaptive alg. within the Path.Area and expose the high level API for it (i.e. like it currenlty does for Pocket operation) - however this would require much more efforts.

Thx,
BR,
Kreso
User avatar
sliptonic
Veteran
Posts: 3457
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: Adaptive Path/CAM Operation

Post by sliptonic »

realthunder wrote: Pinging
User avatar
dubstar-04
Posts: 698
Joined: Mon Mar 04, 2013 8:41 pm
Location: Chester, UK
Contact:

Re: Adaptive Path/CAM Operation

Post by dubstar-04 »

kreso-t wrote: Sat Aug 04, 2018 5:32 pm Hi,

If someone is interested in Adaptive toolpaths, you may check the mod: https://github.com/kreso-t/FreeCAD_Mod_Adaptive_Path

This is the first version entirely written in python (it is using pyclipper lib), so there is a potential for performance improvements. However it also seem quite usable as is. If you are interested check it out and tell me what you think.

Thx,
BR,
Kreso
Fantastic work!!
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: Adaptive Path/CAM Operation

Post by realthunder »

kreso-t wrote: Tue Aug 07, 2018 7:23 am The only thing is that FreeCAD does not include the pyclipper module by default so it requires additional installation (it's acctually a very small library in terms of footprint) , maybe Path.Area could be extended to provide access to lower level clipper operations (and perhaps some other low level 2d geometry operations - like finding instersection points of path and line segment, etc.) then dependency to pyclipper would not be needed.
The path shown in the screenshot is so nice! Great work!

Just name the API you want, maybe a little document. I'll add it to Path.Area.
Last edited by realthunder on Wed Aug 08, 2018 12:25 am, edited 1 time in total.
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
Post Reply