Simulate g-code toolpaths from external CAM?

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!
harvie
Posts: 10
Joined: Wed Apr 11, 2018 3:30 pm

Simulate g-code toolpaths from external CAM?

Post by harvie »

Hello. I like the new toolpath simulator and it works well for toolpaths generated in FreeCAD. But i'd also really like to simulate custom g-code generated by external CAM (pretty much like camotics or this online simulator does: http://cncwebtools.com/Apps/GCode_Simulator/index.html ).
I managed to get the imported toolpaths show in the 3D view and even in simulator, but it's not simulated properly (animated mill does not move/cut for imported g-code operations). Not sure, but i think it might be related to fact that simulator don't know which tool to use (but i tried to set it up, i have tooltable with same tool number as in g-code, i have default tool set, etc...).

Do you know how to do this? Can you please write some howto?
User avatar
sliptonic
Veteran
Posts: 3459
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: Simulate g-code toolpaths from external CAM?

Post by sliptonic »

Hi Harvie,

It's funny you mention this as I started looking into it last week. There are several things that need to happen to make this work even a little bit and to make it work well gets tricky fast.

As you found, importing a gcode file creates a Path object in the tree but does not add it to any job. To work at all, imported code has to get into a Job and have a tool controller. I think imported code should become a 'custom' operation in the tree. The 'Custom' object was only meant to insert a few commands into a job. As you noted, it doesn't have a tool controller and it needs one. This is pretty easy fix.

Now we get to the tricky bit. What if there are tool changes in the imported gcode? Do we create multiple 'customs' and Tool Controllers?
What do we do if there's a tool changes to tool numbers that don't exist in the tool table?

The bottom line is that we need a much more sophisticated importer. Fortunately, Path as designed to accommodate this. Import is done with a 'pre-processor' script which is very similar to the post processors. The nice thing is that these can live side-by-side. We can leave the 'example_pre' bare-bones importer untouched and create a new one that does more. Is this something you'd be interested in working on?

Also, in some cases the simulator currently crashes for me -- actually, FreeCAD segfaults. I know @shaise has been looking into crashes related to the simulator.
User avatar
sliptonic
Veteran
Posts: 3459
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: Simulate g-code toolpaths from external CAM?

Post by sliptonic »

Here's a FreeCAD file that has an imported Path, a custom with the same gcodes. Attempting to simulate it causes a segfault for me.
Attachments
importtest.fcstd
(18.07 KiB) Downloaded 107 times
User avatar
shaise
Posts: 486
Joined: Thu Jun 11, 2015 8:11 am

Re: Simulate g-code toolpaths from external CAM?

Post by shaise »

sliptonic wrote: Mon May 07, 2018 2:24 pm Here's a FreeCAD file that has an imported Path, a custom with the same gcodes. Attempting to simulate it causes a segfault for me.
I Will fix the segfault, but the main cause is because there is an operation without any tool assigned.
User avatar
shaise
Posts: 486
Joined: Thu Jun 11, 2015 8:11 am

Re: Simulate g-code toolpaths from external CAM?

Post by shaise »

sliptonic,

also, on the file you posted, if I try to add a new tool controller (using the tool table) I get the following error:

Code: Select all

Traceback (most recent call last):
  File "D:\Downloads\download\freecad\FreeCAD_0.17\Mod\Path\PathScripts\PathToolLibraryManager.py", line 624, in copyTools
    if isinstance(job.Proxy, PathScripts.PathJob.ObjectJob) and job.Label == targetlist:
AttributeError: 'App.DocumentObject' object has no attribute 'Proxy'
User avatar
sliptonic
Veteran
Posts: 3459
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: Simulate g-code toolpaths from external CAM?

Post by sliptonic »

shaise wrote: Mon May 07, 2018 3:52 pm sliptonic,

also, on the file you posted, if I try to add a new tool controller (using the tool table) I get the following error:

Code: Select all

Traceback (most recent call last):
  File "D:\Downloads\download\freecad\FreeCAD_0.17\Mod\Path\PathScripts\PathToolLibraryManager.py", line 624, in copyTools
    if isinstance(job.Proxy, PathScripts.PathJob.ObjectJob) and job.Label == targetlist:
AttributeError: 'App.DocumentObject' object has no attribute 'Proxy'
Noted. Looks like it's the imported path object. Once it's deleted, the TC creates. Will look at it.
harvie
Posts: 10
Joined: Wed Apr 11, 2018 3:30 pm

Re: Simulate g-code toolpaths from external CAM?

Post by harvie »

shaise wrote: Mon May 07, 2018 3:17 pm but the main cause is because there is an operation without any tool assigned.
How do i assign tool to imported g-code? I tried, but i don't really know how this should be done.

I select the Path workbench, click file->open and select my g-code.

Image

Then i want to create some stock. so i click part workbench, create cube and go back to path workbench. I click on "create job", select the cube from dropdown menu and get path job. Then i can add some tools. However the tree on left shows my imported toolpath outside of that job. If i try to import it again with job selected it still lands outside of the job in the tree. I also tried to create "custom" g-code, but that way i had to copypaste g-code directly into atributes menu on the left. it kinda worked, but is bit fiddly and still can't get tools assigned correctly.

I guess i just need some tutorial or video on this.
User avatar
sliptonic
Veteran
Posts: 3459
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: Simulate g-code toolpaths from external CAM?

Post by sliptonic »

harvie wrote: Tue May 08, 2018 5:53 pm
How do i assign tool to imported g-code? I tried, but i don't really know how this should be done.
You can't. The importer creates a simple Path object independent of a job. It can't be added to a job and has no knowledge of tools.

Then i want to create some stock. so i click part workbench, create cube and go back to path workbench. I click on "create job", select the cube from dropdown menu and get path job. Then i can add some tools. However the tree on left shows my imported toolpath outside of that job. If i try to import it again with job selected it still lands outside of the job in the tree. I also tried to create "custom" g-code, but that way i had to copypaste g-code directly into atributes menu on the left. it kinda worked, but is bit fiddly and still can't get tools assigned correctly.

I guess i just need some tutorial or video on this.
That's why I mentioned that the Custom doesn't have an associated tool controller but needs one. This is a change that will have to be made in source. I've entered a bug in Mantis but the work isn't done yet.

I've also added a feature request for an improved import pre-processor to automatically create customs with imported code.

Follow these two issues:

https://www.freecadweb.org/tracker/view.php?id=3464
https://www.freecadweb.org/tracker/view.php?id=3455
harvie
Posts: 10
Joined: Wed Apr 11, 2018 3:30 pm

Re: Simulate g-code toolpaths from external CAM?

Post by harvie »

sliptonic wrote: Tue May 08, 2018 6:25 pm I've entered a bug in Mantis but the work isn't done yet.
I've also added a feature request for an improved import pre-processor to automatically create customs with imported code.
Very cool! Thank you. Do you think it will be possible to import two g-codes and set different coordinate systems for each?

It would be nice if there was way to simulate multiple g-codes on single stock from different sides. Eg. like in this 2 sided milling example:

https://www.youtube.com/watch?v=OZCqtOtJmYk

I know Fusion 360 can work like that. Not sure about camotics, but i guess they cannot do this. So freecad would be first to bring this feature on Linux.
harvie
Posts: 10
Joined: Wed Apr 11, 2018 3:30 pm

Re: Simulate g-code toolpaths from external CAM?

Post by harvie »

Any news on this? :P
Post Reply