Sometimes things go stubbornly wrong
09/08/2024
Programming is a tedious activity, and seldom a straightforward process. Here is a failure report as an example.
As hinted in "An actual golden ellipsoid not of revolution" a simulation is needed before applying a toolpath strategy on a CNC milling machine. Moreover, the milling process costs a lot in time, tools and wood too, hence the huge benefit of simulation. Yet the simulation used before the milling of the first actual ellipsoid mentioned above is very crude indeed. One would have preferred something at least like that:
It is achieved by a succession of views of .stl files. In itself this is not a totally trivial project but immensely simple compared to the production of the .stl files for each step thus viewed.
In the field of solid modelling, Constructive Solid Geometry (CSG) is a technique very well suited to simulate milling. Indeed, each milling step is similar to the difference operation of a CSG process.
The simple idea is to convert a G-code program in a succession of CSG difference operations.
The proof of concept was rather easy to produce. Surprisingly, rendering fails on a MacBook pro although it is successful on a Raspberry Pi (model 5)! At least it fails faster on the mac than it succeeds on the Raspberry Pi.
On a Raspberry Pi
On a Mac
Unfortunately, the software used to produce this POC does not allow to save each step as a .stl file.
Another solution ingeniously written in C allowed it but the .stl files it produces are crude, huge and faulty.
Another software was used but the production of intermediary files bugged after a rather small number of steps, depending on the format used for these intermediary files, as soon as 41 steps for .stl and up to 74 steps with .3mf. For information, the G-code needed to actually produce the POC above has 4100 lines that would require more than 4000 .stl files for a simple simulation.
Eventually, the only process that worked enough to produce the video above was using this last software while restarting the CSG process from the beginning for each intermediary .stl files. It is not only inefficient but also desperately slow and goes significantly slower at each step.
CSG is an active and modern field of research. Many applications are already available to achieve even complex solid structures but none was found that allows to save each step as an .stl file. Some of these applications are "open source" but, as usual, if the sources are indeed available, they are seldom actually given in a modifiable form if not intentionally obfuscated. Needless to say, the underlying data model nor the mathematics beneath are even hinted at.
At last, there remains the possibility to work at the core level of CSG, re-writing the process of triangularisation of solids and the computation of the difference operation between to meshes. As for this remaining solution, the best clue was a very interesting and rather recent publication made at the SIGGRAPH Asia 2022 Conference by no less than four researchers from an Italian university who even shared their demonstrative code under the MIT licence but with a notice stating that financial supports are welcomed for any enhancement or just addressing issues…
All this hints that this simple idea of the simulation of G-code instruction for a milling process is a rather complex subject.