Bug : Incorrect GCODE output for 3D surface 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!
Fowler
Posts: 7
Joined: Wed May 31, 2023 10:48 pm

Bug : Incorrect GCODE output for 3D surface operation

Post by Fowler »

Code: Select all

OS: Arch Linux (GNOME/gnome)
Word size of FreeCAD: 64-bit
Version: 0.21.0.33341 (Git)
Build type: None
Branch: master
Hash: 8a3c8258dfe92bdfe5efcfea43b0c1e2a224543c
Python 3.11.3, Qt 5.15.9, Coin 4.0.1, Vtk 9.2.6, OCC 7.6.3
Locale: English/United States (en_US)
Did I find this issue when searching the forum? No.
Did I find this issue when searching the issue tracker? No.

I created a model of a bass guitar fretboard using OpenSCAD. I plan to cut it out on my MPCNC running Marlin.
Running a 3D Surface operation on the fretboard face produces GCODE that has defects (a strange valley running diagonally across the fretboard at fret 4. They're not extremely obvious when looking at the preview in FreeCAD, but with a 3rd party online viewer (https://ncviewer.com/) they stand out a bit more (See the attached image). I ran this GCODE against some test pieces of wood twice and the defects are clearly visible in the cut piece.

I've replicated this on a separate machine with a clean install of FreeCAD (latest weekly image).

Any help much appreciated.
Attachments
Fretboard.FCStd
(617 KiB) Downloaded 23 times
Screenshot from 2023-06-01 09-01-39.png
Screenshot from 2023-06-01 09-01-39.png (52.16 KiB) Viewed 1554 times
GeneFC
Veteran
Posts: 5373
Joined: Sat Mar 19, 2016 3:36 pm
Location: Punta Gorda, FL

Re: Bug : Incorrect GCODE output for 3D surface operation

Post by GeneFC »

Fowler wrote: Thu Jun 01, 2023 8:53 am
I played with this a bit, and I cannot see any problems. The strange visual effects are due to Moire patterns forming between the cutting path and the rapid return path. Since the shape varies along the length of the object these patterns vary as well.

You did not include the "defective" gcode file, so I cannot check that directly.

I use 3D surface a lot, and I have not seen any artifacts like you are reporting. However, the overall performance can be very dependent on the exact parameters used. I tend to set very tight sample interval and stepover to minimize shape errors due to rounding and averaging.

If you attach the gcode file I will take a further look.

Gene
Fowler
Posts: 7
Joined: Wed May 31, 2023 10:48 pm

Re: Bug : Incorrect GCODE output for 3D surface operation

Post by Fowler »

Thanks for the reply! I tried to attach the GCODE the last time and the forum wouldn't allow it. I've zipped it and it seems to allow the upload this time

The patterns are most definitely not Moire effects and visual effects only. Remember, I've used this GCODE to cut two pieces of actual wood and there's a defect in the cut that can be easily seen and felt. The centre line of the board is at approximately 4.75mm high. If you inspect the GCODE, you can see that at the defect site the Z value drops to around 4.1mm

In all cases for the files uploaded I've used the default values for everything on a clean install of FreeCAD.

I've experimented a bit and the cut type (line, zigzag, circular etc.) doesn't make a difference. The defect is still there. In fact, you can see the defect very clearly in some of the cut types in FreeCAD itself.
Attachments
fretboard.zip
(36.9 KiB) Downloaded 17 times
Fowler
Posts: 7
Joined: Wed May 31, 2023 10:48 pm

Re: Bug : Incorrect GCODE output for 3D surface operation

Post by Fowler »

Considering that I'm seeing the same issue with different cut patterns, it makes sense to me that the error is not in the actual GCODE generation, but instead in some intermediary step between FreeCAD and OpenCAMlib

FreeCAD has some internal representation of the relevant face which is probably then turned into some other representation (a triangle mesh maybe?) before it's handed off to OpenCAMlib. Assuming I'm right, I wonder if it's possible to get that mesh or object somehow?
Fowler
Posts: 7
Joined: Wed May 31, 2023 10:48 pm

Re: Bug : Incorrect GCODE output for 3D surface operation

Post by Fowler »

OK, I think I'm on to something here.

I opened the Mesh workbench, selected the model and clicked Meshes -> Create Mesh from Shape. I just used the defaults and hit OK. You can see clear defects here in FreeCAD.
Attachments
Screenshot from 2023-06-01 23-01-32.png
Screenshot from 2023-06-01 23-01-32.png (49.47 KiB) Viewed 1355 times
bmsaus4ax
Posts: 255
Joined: Sat Nov 14, 2020 9:16 pm
Location: Bargara, Queensland, Australia UTC+10

Re: Bug : Incorrect GCODE output for 3D surface operation

Post by bmsaus4ax »

Fowler wrote: Thu Jun 01, 2023 10:04 pm OK, I think I'm on to something here.

I opened the Mesh workbench, selected the model and clicked Meshes -> Create Mesh from Shape. I just used the defaults and hit OK. You can see clear defects here in FreeCAD.
Agreed, i have coming at from the supplied file in which I could not see the original construction.
The tool path shows the paths going below the displayed surface of the job ( a display error?? )

I made a negative image ( "cut" the job from a solid cube in Part WB )
the path for that job follows the surface of the new ( negative ) surface.

I used ball endmill with zig-zag pattern to remove rapid moves from over path image

in the original the paths can be seen going below displayed surface
.
originalFretboard.png
originalFretboard.png (64.17 KiB) Viewed 1341 times
.
in the negative the path follows the surface
.
negativeFretboard.png
negativeFretboard.png (76.65 KiB) Viewed 1341 times
.
.
The fault seems to be in the original mesh, but the solid object created from it is not accurately displayed, and yet the path can see the defect ?
.

Code: Select all

OS: Debian GNU/Linux 11 (bullseye) (X-Cinnamon/lightdm-xsession)
Word size of FreeCAD: 64-bit
Version: 0.21.0.33321 (Git) AppImage
Build type: Release
Branch: master
Hash: 1d61ed187c9633702818c6cc5d7a1f07dd052ca8
Python 3.10.11, Qt 5.15.8, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: English/Australia (en_AU)
Fowler
Posts: 7
Joined: Wed May 31, 2023 10:48 pm

Re: Bug : Incorrect GCODE output for 3D surface operation

Post by Fowler »

Depending on the meshing options I choose in the import mesh dialog I get differing defects in the mesh surface. I haven't been able to product a mesh that looks correct yet.

Here's the original OpenSCAD model I made and imported. I simply open this in FreeCAD and then in the Part Workbench click "convert to solid"
This is my first OpenSCAD model and I may have done things in a severely wrong manner, but the result is exactly what I wanted. :D
Attachments
fretboard.scad
(4.75 KiB) Downloaded 24 times
bmsaus4ax
Posts: 255
Joined: Sat Nov 14, 2020 9:16 pm
Location: Bargara, Queensland, Australia UTC+10

Re: Bug : Incorrect GCODE output for 3D surface operation

Post by bmsaus4ax »

Fowler wrote: Thu Jun 01, 2023 11:15 pm Depending on the meshing options I choose in the import mesh dialog I get differing defects in the mesh surface. I haven't been able to product a mesh that looks correct yet.

Here's the original OpenSCAD model I made and imported. I simply open this in FreeCAD and then in the Part Workbench click "convert to solid"
This is my first OpenSCAD model and I may have done things in a severely wrong manner, but the result is exactly what I wanted. :D
I've had another look at this and the mesh can be repaired in the Mesh WB.
In OpenScad, export the model as an STL
In FreeCAD, open/import the STL, and in Mesh WB go to Meshes -> Analyze -> Evaluate and repair mesh
Select each test
For me the Self Intersections check had problems and repaired ok
Back in Part WB , Create shape from mesh, and Convert to solid. looks ugly but as long as you don't have to select individual areas the Job / Operation
will process as a whole.

The resulting Surface looks clean
.
cleanFretboard.png
cleanFretboard.png (41.89 KiB) Viewed 1248 times
.
.
If you are only in the early stages of this, the Curves WB in Addons combined with other FreeCAD WBs could be an alternate route to OpenScad
( good tutorials at https://www.youtube.com/channel/UCUWhaO ... 7Dw/videos )
.
.
Steveco
Posts: 57
Joined: Wed Aug 29, 2018 11:19 pm
Location: San Diego, CA, USA

Re: Bug : Incorrect GCODE output for 3D surface operation

Post by Steveco »

If you're in the early stages of making fretboards, you might also want to look at Macro Guitar fretboard. It has support for compound radius fretboards and multiscale frets.
Fowler
Posts: 7
Joined: Wed May 31, 2023 10:48 pm

Re: Bug : Incorrect GCODE output for 3D surface operation

Post by Fowler »

bmsaus4ax wrote: Fri Jun 02, 2023 3:11 am Back in Part WB , Create shape from mesh, and Convert to solid. looks ugly but as long as you don't have to select individual areas the Job / Operation
Unfortunately, I really do need to select individual areas. I need to select the fret bottoms and create pockets. The same goes for the fretboard markers and the nut slots. This does however show that a good mesh can be created from the model, albeit at the cost of 10 minutes (on my machine).

I've dug into the code and the path is indeed FreeCAD internal Representation (BREP) -> Mesh -> OpenCAMlib. There are some properties to tune the tesselation parameters for the mesh generation if you view the Data tab of a Surface operation. These are "Angular Deflection" and "Linear Deflection".
Increasing these parameters does help somewhat, but still produces defects and massively increases processing time (from 4 seconds to 30 minutes).
Attachments
Screenshot from 2023-06-03 04-49-12.png
Screenshot from 2023-06-03 04-49-12.png (90.85 KiB) Viewed 1047 times
Post Reply