Adding CAM simulation to Path workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Adding CAM simulation to Path workbench
Hi FreeCad team,
For the past few weeks I was playing around with programming CAM simulation to work with Path workbench. I feel this is an important feature as it lets you make sure the rendered gcode indeed delivers what you intended to get.
At first I tried to do it with python and boolean operations. The results were nice, but it was extremely slow. As a test I used one of sliptonic's torture models, and it took about 1 hour and 20 minutes to complete.
(See following thread for images and videos: https://forum.freecadweb.org/viewtopic.php?f=15&t=24422)
I then tried to do the same using external BSP tree boolean library in C++. This helped a bit but still too slow.
Then I decided to go for something like 2.5D voxels (ugly but fast), wrote everything from scratch (no external libraries) and the simulation dropped down to a mere 1 second.
Right now its a stand alone c++ application. I want to integrate it into freecad's path workbench so it can work seamlessly.
Unfortunately as far as I know I can not create an external c++ module, I have to integrate it into FC code. There is lots of info of how to add Python code, but I didnt find enough docs of how to add C++ code. Specially how to write all the python interface to C++ objects. I saw some xml files, suggesting a code generator perhaps?
Any links to docs and samples will be appreciated.
OCC Boolean simulation: C++ 2.5D Voxel sim :
For the past few weeks I was playing around with programming CAM simulation to work with Path workbench. I feel this is an important feature as it lets you make sure the rendered gcode indeed delivers what you intended to get.
At first I tried to do it with python and boolean operations. The results were nice, but it was extremely slow. As a test I used one of sliptonic's torture models, and it took about 1 hour and 20 minutes to complete.
(See following thread for images and videos: https://forum.freecadweb.org/viewtopic.php?f=15&t=24422)
I then tried to do the same using external BSP tree boolean library in C++. This helped a bit but still too slow.
Then I decided to go for something like 2.5D voxels (ugly but fast), wrote everything from scratch (no external libraries) and the simulation dropped down to a mere 1 second.
Right now its a stand alone c++ application. I want to integrate it into freecad's path workbench so it can work seamlessly.
Unfortunately as far as I know I can not create an external c++ module, I have to integrate it into FC code. There is lots of info of how to add Python code, but I didnt find enough docs of how to add C++ code. Specially how to write all the python interface to C++ objects. I saw some xml files, suggesting a code generator perhaps?
Any links to docs and samples will be appreciated.
OCC Boolean simulation: C++ 2.5D Voxel sim :
Re: Adding CAM simulation to Path workbench
Looks impressive! I think voxels might be the way to solve the real life problems where you don't need some crazy angstrom accuracy. Or handling models made in kilometers and micrometers in the same file.
Have you seen this?
https://www.freecadweb.org/wiki/index.p ... e_Creation
https://www.freecadweb.org/wiki/index.p ... h_creation
Have you seen this?
https://www.freecadweb.org/wiki/index.p ... e_Creation
https://www.freecadweb.org/wiki/index.p ... h_creation
Re: Adding CAM simulation to Path workbench
very nice work!
For making an python exposed c++ object I recommend to have a look at Part Workbenchs TopoShape class, it is a very good example of how to do it.
First step is to derive your c++ class from a FreeCAD base object, maybe ComplexGeoData is also appropriate for you. Than your write a xml file, which defines your objects python methods and attributes, like this. Afterwards you cna implement the defined methods in a c++ file like this
In the CMakeList you than call generate_from_xml on the xml file and make sure that the c++ implementation file is also compiled. This creates your python wrapper.
For making an python exposed c++ object I recommend to have a look at Part Workbenchs TopoShape class, it is a very good example of how to do it.
First step is to derive your c++ class from a FreeCAD base object, maybe ComplexGeoData is also appropriate for you. Than your write a xml file, which defines your objects python methods and attributes, like this. Afterwards you cna implement the defined methods in a c++ file like this
In the CMakeList you than call generate_from_xml on the xml file and make sure that the c++ implementation file is also compiled. This creates your python wrapper.
Re: Adding CAM simulation to Path workbench
ickby and PrzemoF,
Thanks a lot! this is very helpful.
Lets start coding...
As soon as I have a basic working version I will post the code on github
shai.
Thanks a lot! this is very helpful.
Lets start coding...
As soon as I have a basic working version I will post the code on github
shai.
Re: Adding CAM simulation to Path workbench
Waiting for it ...
Chris
Chris
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Re: Adding CAM simulation to Path workbench
Hi, Need some experts help here:
I have almost completed the c++ side of the voxel path simulator. Here is a compilation Issue I could not resolve:
I have created a new module: PathSimulator and I am trying to access objects from Path module. I have no issue accessing the object classes but i get unresolved item for the ::Type structs:
These objects reside in the Path module. I checked the Path.lib file and listed its contents, and indeed it exports those 2 types:
I have included the ToolPy.h and CommandPy.h. Libraries are also included in the cMakeLists.
I have no problem accessing objects from Part library including its ::Type objects.
The file: https://github.com/shaise/FreeCAD/blob/ ... mPyImp.cpp
Anyone have a guess why?
I have almost completed the c++ side of the voxel path simulator. Here is a compilation Issue I could not resolve:
I have created a new module: PathSimulator and I am trying to access objects from Path module. I have no issue accessing the object classes but i get unresolved item for the ::Type structs:
Code: Select all
Error 13 error LNK2001: unresolved external symbol "public: static struct _typeobject Path::CommandPy::Type" (?Type@CommandPy@Path@@2U_typeobject@@A) D:\shai\FreeCAD\dev\build\src\Mod\Path\PathSimulator\App\PathSimPyImp.obj PathSimulator
Error 12 error LNK2001: unresolved external symbol "public: static struct _typeobject Path::ToolPy::Type" (?Type@ToolPy@Path@@2U_typeobject@@A) D:\shai\FreeCAD\dev\build\src\Mod\Path\PathSimulator\App\PathSimPyImp.obj PathSimulator
Code: Select all
?Type@ToolPy@Path@@2U_typeobject@@A (public: static struct _typeobject Path::ToolPy::Type)
?Type@CommandPy@Path@@2U_typeobject@@A (public: static struct _typeobject Path::CommandPy::Type)
I have no problem accessing objects from Part library including its ::Type objects.
The file: https://github.com/shaise/FreeCAD/blob/ ... mPyImp.cpp
Anyone have a guess why?
Re: Adding CAM simulation to Path workbench
Hi Everyone,
I have finally managed to integrate the C++ code into FreeCAD. Here is the result - this time it is Realtime:
right now it still uses external macro, but soon I will embed the Python side as well.
If anyone can help me, I still need answers for my previous post (right now I skip type checking as a workaround)
The C++ code can be found here: https://github.com/shaise/FreeCAD/tree/ ... hSimulator
The Macro is here (With many errors for now): https://github.com/shaise/FreeCAD_Macro ... sh.FCMacro
on for the details....
shai
I have finally managed to integrate the C++ code into FreeCAD. Here is the result - this time it is Realtime:
right now it still uses external macro, but soon I will embed the Python side as well.
If anyone can help me, I still need answers for my previous post (right now I skip type checking as a workaround)
The C++ code can be found here: https://github.com/shaise/FreeCAD/tree/ ... hSimulator
The Macro is here (With many errors for now): https://github.com/shaise/FreeCAD_Macro ... sh.FCMacro
on for the details....
shai
Re: Adding CAM simulation to Path workbench
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
- microelly2
- Veteran
- Posts: 4688
- Joined: Tue Nov 12, 2013 4:06 pm
- Contact:
Re: Adding CAM simulation to Path workbench
wow, interesting.
a very good performance for this kind of simulation.
a very good performance for this kind of simulation.
Re: Adding CAM simulation to Path workbench
I feel the simulation is an essential tool to make sure the G Code is valid before actual deployment on the CNC. Thats why its important to have it integrated into the Path workbench.