3d milling algo

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!
User avatar
JoshM
Posts: 456
Joined: Thu Oct 05, 2017 5:34 pm
Location: New Hampshire

3d milling algo

Post by JoshM »

I think I have figured out a method that I believe can be expanded to add some further 3d milling functionality.

This method can be readily expanded to handle more shapes. It's still fairly preliminary, and (among other things) I don't think I have vertical cylinders bounded, but here's the gist.

Here's an example of generating "roughing" passes for a Square Endmill on a cuboid placed at an angle with two adjacent filleted angles.

1. For the selected Job,
Job.png
Job.png (166.85 KiB) Viewed 2082 times
a Stock Model, and a Tool Stock Model that expands the Stock Model by the Mill Radius in XY.

2. For each Face the sections that are accessible to mill from the Top-Z direction are determined from the intersection of a local Face Boundbox3d, aligned with the axis of the Face.

3. For each Face section, the OuterWire edges are discretized. For each discrete point I get the normalAt( Surface.parameter(discrete_point)). I zero the Z of that vector, and multiply by the MillRadius,and that generates the ideal
Job1.png
Job1.png (175.48 KiB) Viewed 2082 times
Job2.png
Job2.png (175.99 KiB) Viewed 2082 times
"Finish Cut" surface covering all points where the center of the Mill tip can pass to mill an Operation. While generating that outline, its projection onto the StockTop is created, and the Loft of the two Faces is the ToolPathEnvelope.

4. A Path.Feature.Area is generated, with minimal Tool Radius specified because this assumes center of tool pocketing.
Job3.png
Job3.png (167.16 KiB) Viewed 2082 times
Job4.png
Job4.png (165.17 KiB) Viewed 2082 times
The PocketMode is set at Offset, but can be changed to any other mode--ZigZag, etc...

5. This is proof of concept of a "roughing" mode, because it still operates on discrete Z heights. To create a "proper" 3d milling profile, the non-planar Finish-Face requires dividing in 3d like FeatureArea does for 2d. I tried the extruding the 2d top paths downward and getting intersection, but no never calculated.

Calculating shape and calculating Paths are about equal for this shape, vary for others...
User avatar
JoshM
Posts: 456
Joined: Thu Oct 05, 2017 5:34 pm
Location: New Hampshire

Re: 3d milling algo

Post by JoshM »

Here, I've changed the PocketMode to ZigZagOffset--and 5-6 seconds later...
Job5.png
Job5.png (183.6 KiB) Viewed 2081 times
Attachments
SquareEndmillMillingToolpath.FCMACRO
(16.66 KiB) Downloaded 41 times
User avatar
JoshM
Posts: 456
Joined: Thu Oct 05, 2017 5:34 pm
Location: New Hampshire

Re: 3d milling algo

Post by JoshM »

Here's a separate example, a simple partial cylinder, at an angle.
Job2_1.png
Job2_1.png (176.71 KiB) Viewed 2081 times
User avatar
JoshM
Posts: 456
Joined: Thu Oct 05, 2017 5:34 pm
Location: New Hampshire

Re: 3d milling algo

Post by JoshM »

I've worked further on this, and made some progress.

1--I've added in Plane Objects to Cylinders.
2--I realized I misunderstood the Feature.Area PocketMode settings. I had set the Tool-Radius very small because unlike typical operations, I am calculating referenced to Center of Tool. The result is that the very center gets a TON of offset lines calculated, filling the inner Step size. I moved that to match the Step-over size. This makes the "roughing' demo much faster, and I believe it adds utility in its own right.
3--For prototyping this script, I am now selecting a Job, and a Tool-Controller and running the script. If only a Job is selected, the default tool-controller is used.

Here's the same Job Model. The 2.37 second time is only generating the roughing Pocket on top--add a couple more seconds when I set the Section Count to -1 to get the roughing paths.
Job10.png
Job10.png (266.39 KiB) Viewed 1985 times
The gaps observed between Face sections are because the algo generates a Face claim that gets an edge of the mill tangential to all points of the Face OuterWire. The tool mills by its radius past the response envelope/surfaces that I am generating.
Job11.png
Job11.png (274.46 KiB) Viewed 1985 times
The model generated allows bounded face by face control--very atomic--of the Job Model. Next Image, switches to Zig-Zag Outline PocketMode.
Job12.png
Job12.png (279.77 KiB) Viewed 1985 times
4--I implemented the response for BallEndMills along with the SquareMill tool responses I have been working on. It's relatively trivial to work with Square and Ballnose endmills because the normalAt() function provides the basis for each. For Square, the z-component is zeroed. For the Ballnose, an offset in Z of the Mill radius is added so that it is Tool Tip referenced--same as with square...

BTW, I already researched months ago, and Rounded Edge mills will fall out of the same calculation as a combination square and ballnose geometries where the Corner Radius and Flat Radius generate radial offset paths to the OuterWire. I just haven't gotten it done yet.
Attachments
Dev000.FCStd
(572.71 KiB) Downloaded 36 times
SquareEndmillMillingToolpath.FCMACRO
(17.5 KiB) Downloaded 35 times
User avatar
JoshM
Posts: 456
Joined: Thu Oct 05, 2017 5:34 pm
Location: New Hampshire

Re: 3d milling algo

Post by JoshM »

What appeals to me about this scheme is that it leverages existing PathWB tools--and I believe, philosophy--so the added time required to provide current functionality to more geometry is small.

I plan to add more geometry--torus and sphere should be a relatively straight forward add. Sphere as well. Cone I think is like cylinder but gets tricky because the available surface to mill from top depends on cone axis and cone angle.

I think the SurfaceWB may hold key to providing a True surface path generation. I'm also curious to try taking the existing top Feature.Area path generation, and project it onto the bottom Face that I have. I need to look at existing functions, and if the answer isn't there, then I think discretizing the path, and finding the intersection point on the bottom finish surface, and placing a point there, etc...

This is still very primitive. Very limited bounding is in place currently. For example, a mill claim will be generated for Face-A, without regard for incursion into Face-B. Also, inner wires are not yet considered.

I attached the project file and script if anyone cares to check it out.

Best,
Josh
User avatar
JoshM
Posts: 456
Joined: Thu Oct 05, 2017 5:34 pm
Location: New Hampshire

Re: 3d milling algo

Post by JoshM »

I took a first pass at projecting the Top generated Pocket onto the Surface of the ideal finish cut, and it looks very promising. I have a minor bug in there where some extra faces and thus cuts are generated on the model, but otherwise, it looks very encouraging.

Here is with Outline Pocket Mode selected, with 0.5 mm step size, for a 3.175mm square-mill.
Job13.png
Job13.png (280.99 KiB) Viewed 1970 times
I still need to determine how to project upward, bounded by tool envelope, but in short run, coupled with roughing, it would generate milling paths same as usual, but with 3d roughing/finishing...
Attachments
SquareEndmillMillingToolpath.FCMACRO
(17.85 KiB) Downloaded 33 times
User avatar
JoshM
Posts: 456
Joined: Thu Oct 05, 2017 5:34 pm
Location: New Hampshire

Re: 3d milling algo

Post by JoshM »

Here, I've shifted to a ZigZagOutline, for a 3.175mm BallEndMill. The issue I need to fix is that an extra internal face--violating the upper fillet--is generated, and then paths for it fall out... Tomorrow.
Job14.png
Job14.png (303.59 KiB) Viewed 1969 times
herbk
Veteran
Posts: 2660
Joined: Mon Nov 03, 2014 3:45 pm
Location: Windsbach, Bavarya (Germany)

Re: 3d milling algo

Post by herbk »

Hi Josh,
looks promising... :D
Gruß Herbert
mlampert
Veteran
Posts: 1772
Joined: Fri Sep 16, 2016 9:28 pm

Re: 3d milling algo

Post by mlampert »

I agree - this is looking really good!
User avatar
JoshM
Posts: 456
Joined: Thu Oct 05, 2017 5:34 pm
Location: New Hampshire

Re: 3d milling algo

Post by JoshM »

Thanks for the encouragement guys. I pushed forward today and mostly fixed those extra face issues. I still see an extra section generated on the upper fillet, but it's on the outside at least. I still need to run that down.
Job15.png
Job15.png (195.11 KiB) Viewed 1913 times
@mlampert,I'd take any advice from you. I don't know anything about integrating a script so that it can be used from the GUI. BTW, I think this can be used to take care of the chamfer unable to operate on modeled chamfers you'd mentioned--assuming you have not resolved that already.

I also notice what I believe is a small bug in the PathFeatureArea PocketMode = Outline. My use of that is unconventional because I am using for a center-justified (0mm diameter) mill as opposed to insetting on a face outer wires. So, I set the Tool Radius as low as I can get away with, and am using the step-over distance alone to determine pocket shape.
Job16.png
Job16.png (254.71 KiB) Viewed 1913 times
ZigZagOutline works perfectly. Outline works well, with step-over distance path offsets, until the inner-most area where it is shifted down to the Tool-Radius setting, causing a TON of small paths.
Attachments
SquareEndmillMillingToolpath.FCMACRO
(18.57 KiB) Downloaded 46 times
Last edited by JoshM on Mon Oct 01, 2018 1:08 am, edited 1 time in total.
Post Reply