3D Surface: 4th-axis Integration and more...

Here's the place for discussion related to CAM/CNC and the development of the Path module.
User avatar
Russ4262
Posts: 249
Joined: Sat Jun 30, 2018 3:22 pm

3D Surface: 4th-axis Integration and more...

Postby Russ4262 » Tue Apr 30, 2019 12:57 am

Hello fellow FreeCAD users.
In case you have not been keeping up with some of the advancements here in the PathWB, I am here to tell you about a few. There are exciting improvements being made to a number of the PathWB tools. I have been working on the 3D Surface op, and recently the Path Pocket Shape op.

Much of the discussion for the 3D Surface op improvements has been taking place in an adjacent topic, CNC Lathe and 4th-axis milling.... Considering the length of many topics here on the forums, I understand that some of the new developments can be buried in the depths of the forum pages. Fret not! FYI, the 3D Surface op has been undergoing some major changes. Although these are not committed to the master branch of FreeCAD, you can still access them and try them out. Feedback is greatly appreciated.

The most recent version of the 3D Surface op script can be found at a posting in the aforementioned topic. Also, additional background information and feature details is in the discussion leading up to that post. In short, the best features in development for 3D Surface are the multi-pass (aka layering or step-down) support and rotational (4th-axis) scans.

If you have not toggled on the experimental features in the PathWB, perhaps the new developments in the area of 4th-axis availability will change your mind. We will be glad to help you install the available scripts for testing. Attached are a couple of images to demonstrate what is available - or at least what we are aiming for.

If you find a bug, please let me know. I'll work to remove any found... As far as I am capable.

UPDATE: 2019-04-30 This topic is also related to PR #2114.
UPDATE: 2019-05-02 Script, and future updates will be attached here, rather than aforementioned topic at link above. Script updated to Rev. 3u Usable: Made changes to mesh generation, suggested by @sliptonic in Gitter.im chat today.
UPDATE: 2019-05-11 Script updated to latest PR #2159, Rev. 3v Usable
UPDATE: 2019-05-14 Script updated to Rev. 3w Testing. @LMH identified path error on terminal side of planar OCL Dropcutter scan. Issue addressed in this update.

Installation:
  • download the attached script
  • navigate to your FreeCAD binary folder
  • navigate to 'Mod/Path/PathScripts'
  • rename your current PathSurface.py script - to save should you wish to revert
  • paste the downloaded version into the same folder
  • rename the downloaded version to the same as the original, PathSurface.py
  • Re-start FreeCAD
Russell
Attachments
PathSurface_r3w-testing.py
PathSurface_r3w-testing.py
(82.56 KiB) Downloaded 111 times
Example_Lathe_Eyelet - 4th axis - perpendicular(circular).png
Example_Lathe_Eyelet - 4th axis - perpendicular(circular).png (433.19 KiB) Viewed 1718 times
Example_multi-pass_fixed-stepover.png
Example_multi-pass_fixed-stepover.png (228.8 KiB) Viewed 1718 times
Example_Lathe - 4th axis.png
Example_Lathe - 4th axis.png (341.89 KiB) Viewed 1718 times
3D_Surface_multi-pass.png
3D_Surface_multi-pass.png (289.07 KiB) Viewed 1718 times
Last edited by Russ4262 on Thu May 16, 2019 3:31 am, edited 4 times in total.
User avatar
sliptonic
Posts: 1596
Joined: Tue Oct 25, 2011 10:46 pm

Re: 3D Surface: 4th-axis Integration and more...

Postby sliptonic » Wed May 01, 2019 7:26 pm

Hey Russ,
I was trying the waterline function on this model.

I kept getting really jaggy results. Cranking down the sampling interval didn't seem to help and REALLY slowed it down.
2019-04-30_10-33.png
2019-04-30_10-33.png (30.29 KiB) Viewed 1559 times
I made the following change around line #278

Code: Select all

                #base.Shape.tessellate(0.5) # 0.5 original value
                #mesh = MeshPart.meshFromShape(base.Shape, Deflection=deflection)
                mesh = MeshPart.meshFromShape(Shape=base.Shape, LinearDeflection=0.0025, AngularDeflection=0.523599, Relative=False) 
image.png
image.png (41.38 KiB) Viewed 1559 times
So I think this is more evidence that we should find a better way to generate our meshes
User avatar
JoshM
Posts: 419
Joined: Thu Oct 05, 2017 5:34 pm
Location: New Hampshire

Re: 3D Surface: 4th-axis Integration and more...

Postby JoshM » Thu May 02, 2019 7:47 pm

I've continued work on an alternative mesh sampling approach. I've been attempting to implement a non-linear sampling algorithm. The concept is relatively simple, the execution requires care.

For a moderately large mesh--around 3k facets, 6k facet edges--it is possible to analyze the relationship of all facet edges to the Tool-Path edges in less than 30s where a relatively large number of tool-path edges exist.

The idea is to treat each facet edge as a line-segment and to calculate the equation of the line and whether it intersects with a plane formed with the tool-path as the top-edge of the plane. The line equation tells us where a line passing through the line-segment intersects the plane. Results of the calculation are one of the following:
1. Line is parallel to plane and in the plane.
2. Line is parallel to plane and disjointed.
3. Both P_Start and P_End of the facet-edge are on the negative side of the plane.
4. Both P_Start and P_End of the facet-edge are on the positive side of the plane.
5. The plane intersects the line-segment at a unique point.

In case-1, the entire length of the line-segment encroaches on the plane and must be accounted for.
In case-2, if the points of the line-segment are within the tool-radius, they form a line that encroaches on the plane, otherwise can be disregarded.
In case-3, the end-point marks one limit of encroachment, at a point on the line-segment, at the tool-radius distance along the plane normal. The other limit is at the similar point for the start-point, or if shorter than that, at the point on the plane along the normal closest to the start-point
In case-4, the start-point marks one limit of encroachment, at a point on the line-segment, at the tool-radius distance along the plane normal. The other limit is at the similar point for the end-point, or if shorter than that, at the point on the plane along the normal closest to the end-point
In case-5, the points on either side of the plane, on the line-segment, at the tool-radius distance along the plane normal define the limits of the encroachment of the facet on the tool-path.

For each calculated point, the XY portion of the vector from the start-point of the tool-plane to the point of encroachment on the plane represents the sort distance for that toolpath segment. The radial distance from the point to the plane allows square/ball/chamfer/etc... calculations. For example, a point of intersection on the toolpath plane resulting from a case-5 unique intersection is fully weighted for any tool tip. But, a point that is offset from the toolpath-plane would impose a lower calculated z value for a ballnose or chamfer tool. By using the facet normal, and the radial offset, a minimum allowable z offset can be calculated.

The benefit of non-linear sampling is that for larger flat sections, the facets are larger triangles. Where more changes occur on a model, there are more facets, and all of them get an opportunity to be included in the z calculation if a facet edge is within the tool-radius of the toolplane.

At the moment, I have the calculations for a zig-zag toolpath imposed on a mesh model. The results are simply output to the Report window ATM. Printing takes more time than calculating. I am still trying to sort out the results. I believe--but I'm not positive--that I need to also constrain results only to points within range of the individual toolpath section bounds.

Best,
Josh
Attachments
aMeshSurfaceMilling.FCMACRO
(29.9 KiB) Downloaded 38 times
User avatar
Russ4262
Posts: 249
Joined: Sat Jun 30, 2018 3:22 pm

Re: 3D Surface: 4th-axis Integration and more...

Postby Russ4262 » Fri May 03, 2019 5:36 am

sliptonic wrote:
Wed May 01, 2019 7:26 pm
So I think this is more evidence ...
Agreed, Sir. I have integrated the improved meshFromPart() parameters to the new 3D Surface script and uploaded it to the opening post for this topic.

Yes, the waterline changes I have in the 3D Surface op now were designed to make it more usable than previous results. It was quite choppy and rough, but the improvements at least rendered a waterline without the undesirable artifacts of the previous version. Thanks to your tests with the mesh generation options, that will make it even better.

Again, the script has been updated to Rev. 3u Usable, to include the better mesh generation code. No other changes were made from previous version.

Thanks.
Russell
User avatar
Russ4262
Posts: 249
Joined: Sat Jun 30, 2018 3:22 pm

Re: 3D Surface: 4th-axis Integration and more...

Postby Russ4262 » Sun May 12, 2019 3:38 am

Evening all,
I found an error in the last release of the 3D Surface script. I failed to activate the cutter profile in the last release. For some reason I thought I should comment out that function call! Who knows why! Anyhow, I would like to say I sent a PR (now committed to master) for the fix and have posted that updated code to the initial post in this topic for all those using this new 3D Surface op.

Script updated to latest PR #2159, Rev. 3v Usable. See initial post in this topic for the download.

I apologize for the inconvenience; but, I thank you for the feedback in developing the new, more feature-packed version.

Russell
User avatar
roerich_64
Posts: 793
Joined: Thu May 21, 2015 7:00 pm
Location: Ostfriesland

Re: 3D Surface: 4th-axis Integration and more...

Postby roerich_64 » Tue May 14, 2019 10:59 pm

Hi Russ,

Nice to see how great the steps around PathSurface does :-)

Now i come back for testing ;-)
I read between the lines that we can now use PathSurface with Python 3x. Right?

I am here:

Code: Select all

OS: Windows 7 SP 1 (6.1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.16699 (Git)
Build type: Release
Branch: master
Hash: e484a52e9d4ccaa360952cd8755b4a8ee6ad2ea1
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Germany (de_DE)
Experimental.jpg
Experimental.jpg (56.9 KiB) Viewed 1263 times
Where can we found the ocl libraries for Python 3x ?

BR
Walter
Last edited by roerich_64 on Wed May 15, 2019 1:01 am, edited 1 time in total.
User avatar
sliptonic
Posts: 1596
Joined: Tue Oct 25, 2011 10:46 pm

Re: 3D Surface: 4th-axis Integration and more...

Postby sliptonic » Tue May 14, 2019 11:26 pm

There's a recent bug that's causing the experimental features to not show up.
A fix is pending.
https://forum.freecadweb.org/viewtopic. ... 9&start=20
User avatar
roerich_64
Posts: 793
Joined: Thu May 21, 2015 7:00 pm
Location: Ostfriesland

Re: 3D Surface: 4th-axis Integration and more...

Postby roerich_64 » Tue May 14, 2019 11:40 pm

Thank you for the quick answer, @Sliptonic :-)

Ok the PathGuiInit_ocl_patch.py have i updated. But:
Experimental_I.jpg
Experimental_I.jpg (193.84 KiB) Viewed 1247 times
I think i need the OCL_Lib for Py3x...

Edit:
I found the OCL_LIB for Py3x... :oops:
Experimental_III.jpg
Experimental_III.jpg (40.04 KiB) Viewed 1239 times
Ok. I have to wait for the newest FreeCAD Version that solved the issue that the OCL_Lib was not found... ;-)
Last edited by roerich_64 on Wed May 15, 2019 7:40 pm, edited 1 time in total.
User avatar
Russ4262
Posts: 249
Joined: Sat Jun 30, 2018 3:22 pm

Re: 3D Surface: 4th-axis Integration and more...

Postby Russ4262 » Wed May 15, 2019 3:17 pm

Roerich_64,
Good morning, Sir.
roerich_64 wrote:
Tue May 14, 2019 11:40 pm
:oops:
I apologize for the problem. I am looking in to it. My work computer will not properly run the Py3 Qt5 releases. I think it is a video card compatibility issue (nVidia). So, I'm downloading on a separate laptop the latest 0.19.16699 release from your screenshot posted above.

I want to see if the release works correctly [PathWB, import ocl, and display experimental features workbench] on a machine with no FreeCAD history.

I'll let you know my findings.

UPDATE: Well, that didn't go well. The laptop apparently has the same incompatibility as my work computer. FreeCAD opens, but all there is only a white screen with the FreeCAD 0.19 title. Hmmm.. Sorry, mate. I'll have to wait until I am back at the house.

Russell
jbi
Posts: 54
Joined: Sun Apr 24, 2016 3:28 pm

Re: 3D Surface: 4th-axis Integration and more...

Postby jbi » Wed May 15, 2019 4:39 pm

Hello,
I am just following this topic and i am curious how you do the sampling of the mesh. Are you using the shape to STL export? I have used in the past:

Code: Select all

solid.exportStl(filename,0.3) #search exportSTL" from https://github.com/FreeCAD/FreeCAD/blob/4664e5bb483404b064e8de59ce0ca3161482e9a1/src/Mod/Part/App/TopoShapePyImp.cpp
As far as a understand with the second parameter you can specifiy how much the tesselated contour can deviate from the ideal one.
Wouldn't this be sufficient to generate the mesh or is a more sophisiticated algorithm needed?