## CNC Lathe and 4th-axis milling...

Here's the place for discussion related to CAM/CNC and the development of the Path module.
roerich_64
Posts: 1326
Joined: Thu May 21, 2015 7:00 pm
Location: Ostfriesland

### Re: CNC Lathe and 4th-axis milling...

@Herbert:

Now FreeCAD is back from calculating the gCode after around 2 hours
Result:
The file is over 8MB great and have over 226000 lines
The greatest gCode file ever i have generated

This is an example to find the 'mesh issue', not an example for real working with 3D-Surface!!
The real life gCode out of 3D-Surface with OCL is small

Walter
JoshM
Posts: 450
Joined: Thu Oct 05, 2017 5:34 pm
Location: New Hampshire

### Re: CNC Lathe and 4th-axis milling...

There’s a compromise that I’ve been playing with that likely speeds up path calculation.

Linear sampling isn’t ideal for a mesh. If I create a plane from Stocktop to bottom along each zig-zag segment, then iterate through all facets in the mesh, I can use vectors to calculate the distance from each point to the plane. Similarly I can calculate each facet edge segment and determine if the segment intersects the plane, and at what point.

Each tool has a radial “weight” based on proximity to the plane. For a square endmill all points have equal weight. For a ball it’s sinusoidal. For a chamfer it’s linear.

By doing this, you can adjust Z heights to maximum weighted z within tool radius of all facet points and facet edge intersection points. In absence of points, nearestfacetonray() provides facet and intersection point.

This means large facets require minimal probing and all small facet information is included.

The calc time isn’t particularly long.
roerich_64
Posts: 1326
Joined: Thu May 21, 2015 7:00 pm
Location: Ostfriesland

### Re: CNC Lathe and 4th-axis milling...

JoshM wrote:
Sat Mar 30, 2019 6:21 pm

Each tool has a radial “weight” based on proximity to the plane. For a square endmill all points have equal weight. For a ball it’s sinusoidal. For a chamfer it’s linear.
Hi Josh,

I have done more thoughts about your finds and break it down:

Linear (point cloud):
- Each tool has a radial “weight” based on proximity to the plane.
- For a chamfer it’s linear.
- For a square endmill all points have equal weight.

Cubic (depending on pi):
- For a ball it’s sinusoidal.

My result of them:
we can not find an exact result (we have point cloud and pi). We can only ever find an approximation...
But we can live nice with the approximation

Why?
To have a nice toolpath on very little objects or dimensions we have to decrease the triangles of the meshes to scan it

Edit:
Both ways (waterline, dropcutter) to find a smooth path have this issue:

Example: Waterline (quote of Anders Wallin, http://www.anderswallin.net/category/cn ... rline-cam/
tux_waterlines1_WW.jpg (844.66 KiB) Viewed 1043 times

BR
Walter
Russ4262
Posts: 598
Joined: Sat Jun 30, 2018 3:22 pm

### Re: CNC Lathe and 4th-axis milling...

Good morning FC users.
I am sorry for the long delay in posting an updated version of the 3D Surface Op script. I have been working on it. The OCL rotate method is peculiar; it has been a challenge. I have made major improvements and feature advances in general. Not all of the new features are fully functional across all sub-operations - some are merely placeholder inputs for future improvements.

Anyhow, this update includes:
• implemented a fixed step over at each layer for rotational scans. I think I have reached a happy medium between reliability and speed.
• tilt angle adaptation requested by @JoshM. Initial tests look good. Thanks, JoshM. Limits are +- 90 degrees
• start/stop index values: 0-360. No negatives accepted.
• cut patterns: zigzag and line. These are not fully integrated. This feature is only partially implemented.
• cut mode: conventional and climb. This feature is only partially implemented.
• step down(multi-pass/layering) is(should be...) fully available.
• waterline: improvements to stability
• partial implementation of FC tool types mapped to OCL cutter functions: end mill, ball end mill, engraver, bull nose mill, and chamfer. OCL can now use these tool head geometries for scans. Note: adjustments may be necessary in the code - feedback and testing needed.
• fixed bug: upon initializing op, final depth was populated correctly, but upon clicking OK to run op, that value was lost and reset to top of model. This is fixed (at least per my tests).
Things you need to know for usage:
• Only G0 and G1 commands are used in gcode output
• REMINDER: It has bugs!
• Reminder: The smaller the sample interval, the longer to process the operation - ESPECIALLY with rotational operations
• You may need to delete your current surface operations after upgrading to this script version. This version introduces new properties not created with the original/older versions. Recreate the surface operations with the new script installed.
• Based upon great discussion and arguments presented in this thread, I think this script is mostly useful for woodworkers. Due to a number of conditions within this script, and without, it is NOT ready for high accuracy CNC production - certainly not with metals. We have many issues to resolve and improve.
• I ask that if you make corrections/improvements to the code, please share those with me, or point me to an online location where they are available. I can use all the help I can get to eradicate the bugs.
I would like to thank everyone for their support and patience in this endeavor. It has been fun. I look forward to more improvements and features with great feedback from you all. I am attaching the 3D Surface Op, Rev. 3s Usable, to this post. It has also been uploaded to my GitHub FC repo at https://github.com/Russ4262/FreeCAD/blo ... Surface.py

Enjoy,
Russ

Update - 2019 April 8
I discovered errors within the rotational operations not orienting the gcode correctly to the model, and other rotational errors. Also, the cutter tilt feature was incorrect due to the related rotational errors. I have since corrected and completed additional tests with corrected results. I am attaching the corrected and improved, Rev. 3t Usable.

This updated script also has an "ignore waste" feature, for planar operations. The "Release From Waste" option needs more work when used with the multi-pass layering option. The single-pass run works well.

Update - 2019 April 29
Removed Rev. 3s Usable attachment so as to not confuse readers.

Update - 2019 May 02
Moving script to newer, 3D Surface specific topic: 3D Surface: 4th-axis Integration and more.... Script download is available there. 3D Surface discussion suggested to continue there as well.

Cheers,
Russ
Last edited by Russ4262 on Fri May 03, 2019 5:26 am, edited 4 times in total.
Wsk8
Posts: 160
Joined: Fri Dec 07, 2018 6:24 pm

### Re: CNC Lathe and 4th-axis milling...

Made some short tests, Looked good so far. No crashes
Would be great, to have the rotational feature also in the pocket/contour op.
But the simulator is not ready for it
Thanks for your contribution

mfg
RatonLaveur
Posts: 825
Joined: Wed Mar 27, 2019 10:45 am

### Re: CNC Lathe and 4th-axis milling...

Quite impressive! Thank you for your hard work. I'm still figuring out how the cutter tilt and rotational operations work there, but I clearly see the potential. Waterline machining works and other options such as Multi-Layer are just fantastic.

To note, I'm on a windows build (as some have noticed there) https://forum.freecadweb.org/viewtopic. ... 5&start=50
The system often crashes back to desktop without error message when clicking "Apply" in the 3D surface mode, at what point all I have to do is restart FreeCAD and anything saved (even the 3D path) will be there.
I won't yet submit an error report because I have not figured out where it originates.

My first results performing 3D machining using our laser machine are very promising. I'll show results when I can.
Russ4262
Posts: 598
Joined: Sat Jun 30, 2018 3:22 pm

### Re: CNC Lathe and 4th-axis milling...

Evening,
I just updated my previous post. I found major errors with the rotational operations. I attached the corrected script to that post. Please replace the previous version you downloaded.
RatonLaveur wrote:
Mon Apr 08, 2019 11:49 am
I'm still figuring out how the cutter tilt and rotational operations work there, but I clearly see the potential. … I won't yet submit an error report because I have not figured out where it originates.
I believe the rotational issues are corrected, including the affected cutter tilt feature. Please accept my apologies! As for the crashes, I have experienced similar crashes throughout my development of this project. I think part of the issue is the Qt-python interface. I am not certain. I also think it could be a coding error on my part - I AM A NOVICE... lol

I think the crashes may be due to the structure of the script code. I think I need to adjust the structure to allow functions to be smaller, and to make certain each iteration of a loop is completely saved and cleared from memory before starting the next loop. I don't have enough coding knowledge and terminology awareness to express it any better at the moment. I think the data in my loops may be growing too large, thus causing a crash due to strain on system resources - BAD programming. Although, I can say this current version of the script is the best and most stable yet.

Anyhow, I am taking it one step at a time, learning as I go, enjoying the journey along the way, and making something useful for the FC community.
Wsk8 wrote:
Sun Apr 07, 2019 8:08 pm
Made some short tests, … But the simulator is not ready for it
Thanks for doing some testing. I really do appreciate the help and feedback. As for the simulator, yes, it is not fully ready for 4th axis simulation. That is fine. I paste the gcode results from these test operations into https://ncviewer.com/ to see if the code at least looks okay visually. In FC, I toggle visibility of the job model to look for paths that violate the model. I also zoom in with the model and paths visible to inspect possible violations or errors.

I am sure happy with FreeCAD lately. It really has a lot to offer. Thanks to all those developers and maintainers out there in FreeCAD land !

I'm attaching the updated Rev. 3t Usable script here also, for convenience. I will upload to my GitHub account also.

Update - 2019 May 15
Moving script to newer, 3D Surface specific topic: 3D Surface: 4th-axis Integration and more.... Script download is available there. 3D Surface discussion suggested to continue there as well.

'night,
Russ
Last edited by Russ4262 on Thu May 16, 2019 4:30 am, edited 2 times in total.
RatonLaveur
Posts: 825
Joined: Wed Mar 27, 2019 10:45 am

### Re: CNC Lathe and 4th-axis milling...

Russ,

First of all: WOW. Don't know what you've done Sir, but the latest version of your code is much faster. Still crashes, usually if I go too fast between actions or if I ask for too much. But don't worry, it's not just your code: I've noticed that type of crash since I've been playing around with OCL.

Second: I managed to produce code that works with rotations and that's just dandy. I'll be working some and posting bugs.

Question1: Do I have to have my part axially oriented (with transform) with X or Y initially? or am I doing something wrong with the job setup?

Question2: I seem to have trouble figuring out how to perform series of milling operations (example with the surfaces of a Hex nut) with the rotational axis. Of course until now I would have prepared a Job and a position for each face milling, but it looks like the fruits of this more recent work could seamlessly perform that.

Question3: Provided that the answer to question 2 yields the ability (even marginal) to Mill, rotate into position, mill...etc. I wonder if tangential machining could be performed in a similar way. The reason for that is I foresee the ability to perform laser turning with grazing incidence.

Either way, I'll keep exploring the possibilities (in between crashes ) and get back to you. Thank you so much. It's fun!
Attachments
FirstTest.png (142.74 KiB) Viewed 785 times
MachiningType.png (97.88 KiB) Viewed 785 times
Russ4262
Posts: 598
Joined: Sat Jun 30, 2018 3:22 pm

### Re: CNC Lathe and 4th-axis milling...

Morning, RatonLaveur.
I am glad you are enjoying the script. I am excited about it.
RatonLaveur wrote:
Tue Apr 09, 2019 1:04 pm
Question1: Do I have to have my part axially oriented (with transform) with X or Y initially? or am I doing something wrong with the job setup?
Axis of rotation for the operation is fixed at the X and Y axis. Your original part, prior to Job creation does not need to be axial oriented; but, you will have to use the Layout tools in the Setup tab in the Job creation task panel to center the job model on the desired axis of rotation.

RatonLaveur wrote:
Tue Apr 09, 2019 1:04 pm
Question2: I seem to have trouble figuring out how to perform series of milling operations (example with the surfaces of a Hex nut) with the rotational axis. Of course until now I would have prepared a Job and a position for each face milling, but it looks like the fruits of this more recent work could seamlessly perform that.
This type of milling is not available, YET. I believe you are referring to indexed milling (rotate part to a fixed index, perform a set of operations, then rotate to the next desired index to perform another set of operations). I really think this would be easy to add in FreeCAD. I have an idea for simple implementation, I may experiment with one of the other PathWB operations when I get time.

RatonLaveur wrote:
Tue Apr 09, 2019 1:04 pm
Question3: Provided that the answer to question 2 yields the ability (even marginal) to Mill, rotate into position, mill...etc. I wonder if tangential machining could be performed in a similar way. The reason for that is I foresee the ability to perform laser turning with grazing incidence.
I'll have to think about this. I would think so, initially - based upon above response.

Cheers,
Russ
Wsk8
Posts: 160
Joined: Fri Dec 07, 2018 6:24 pm

### Re: CNC Lathe and 4th-axis milling...

Russ4262 wrote:
Tue Apr 09, 2019 2:17 pm
This type of milling is not available, YET. I believe you are referring to indexed milling (rotate part to a fixed index, perform a set of operations, then rotate to the next desired index to perform another set of operations). I really think this would be easy to add in FreeCAD. I have an idea for simple implementation, I may experiment with one of the other PathWB operations when I get time.
Hope you find some time for this feature. That would be great!

If you make changes to your script, how do you reload it in FC for testing? Is there a console command?

mfg