Translate imported gcode?

Here's the place for discussion related to CAM/CNC and the development of the Path module.
etrombly
Posts: 80
Joined: Thu Dec 05, 2019 6:50 pm

Translate imported gcode?

Post by etrombly » Thu Mar 12, 2020 12:20 pm

Lately I've been using F-Engrave to do vcarving. I still like to use freecad to do the rest of the operations, like cutting the border and surfacing. It would be nice if I could import the gcode from f-engrave, then center it in the stock. (I was thinking of making my own tool to merge multiple gcode files like this, but someone on reddit recommended to post here, it makes sense to be able to do it all from freecad)
User avatar
sliptonic
Posts: 1753
Joined: Tue Oct 25, 2011 10:46 pm

Re: Translate imported gcode?

Post by sliptonic » Thu Mar 12, 2020 2:15 pm

Hi etrombly,

I've been thinking about this as well. I think it would make a good feature and isn't too difficult to implement. It sounded from your Reddit post like you're a programmer. Are you interested in working on this? If so, I can give you some direction.

When we built the Path workbench, we built the capability to import external gcode. There's even a mechanism comparable to a post-processor that can be tailored to import specific dialects of gcode. Nobody has ever done much with it. Right now, we only have a single preprocessor that works pretty well for generic gcode. If you do file->import, select gcode as the filetype and pick your file, you'll get a dialog to select a pre-processor. Pick example_pre and it should import your file.

This is implemented in /Mod/Path/PathScripts/post/example_pre.py. the insert() method is what actually sticks the object into a document.

There's two problem with this. First it will create a new node in the tree but outside any Path job. Second, it just creates a generic Path::Feature "Path" object. IMHO, what should happen is that a new 'Custom' operation should be created and it should be added to whichever job you select. 'Customs' are just very basic operations that can contain any arbitrary gcode. Customs are actual operations however, so they can have tool controllers and are added to jobs. The custom implementation is in /Mod/Path/PathScripts/PathCustom.py

Actually translating the gcode is pretty straightforward. We could do this with a Dressup or possibly have a boolean property of the Custom operation to 'Use Operation Placement' which would add the translation to the imported commands. I need to think about this part a bit more.

There's one more thing that could be added to the example_pre.py that would really also improve it:
- Tool Controller handling. Imported gcode will assume a tool and possibly have an M6 Tn command. But the job it's imported to will already have tool controllers and might not have one that corresponds to the tool. So, should the importing preprocessor suppress those commands and assume a tool controller will be assigned to the Custom operaton? Or should it throw an error and only allow import if a corresponding TC exists? I'm not sure.
etrombly
Posts: 80
Joined: Thu Dec 05, 2019 6:50 pm

Re: Translate imported gcode?

Post by etrombly » Thu Mar 12, 2020 2:23 pm

I can take a look at it. I don't have a ton of free time, so it may take me a little while to get up to speed though.
User avatar
sliptonic
Posts: 1753
Joined: Tue Oct 25, 2011 10:46 pm

Re: Translate imported gcode?

Post by sliptonic » Thu Mar 12, 2020 2:45 pm

etrombly wrote:
Thu Mar 12, 2020 2:23 pm
I don't have a ton of free time, so it may take me a little while to get up to speed though.
Looking at the news today, I think we're all going to have more free time. Maybe that's good for open-source software but kinda sucks for every other aspect of life.

Give me a shout if you have questions. There's also a Path channel on gitter where we chat. https://gitter.im/FreeCAD/Path
etrombly
Posts: 80
Joined: Thu Dec 05, 2019 6:50 pm

Re: Translate imported gcode?

Post by etrombly » Thu Mar 12, 2020 2:48 pm

Thanks, downloading all the build deps now, I usually use the appimage. I'll take a look at the gitter if I have any questions.
User avatar
sliptonic
Posts: 1753
Joined: Tue Oct 25, 2011 10:46 pm

Re: Translate imported gcode?

Post by sliptonic » Thu Mar 12, 2020 3:02 pm

etrombly wrote:
Thu Mar 12, 2020 2:48 pm
Thanks, downloading all the build deps now, I usually use the appimage. I'll take a look at the gitter if I have any questions.
Everything we're talking about so far is Python code so you can directly modify the files in /Mod/Path/PathScripts and restart FreeCAD.
Development should be pretty easy
etrombly
Posts: 80
Joined: Thu Dec 05, 2019 6:50 pm

Re: Translate imported gcode?

Post by etrombly » Thu Mar 12, 2020 6:39 pm

So I got example_pre to load the gcode as a custom and attach it to a path job (mostly cut and paste from PathCustom to example_pre). I would prefer to use the translation to modify the placement, my only hesitation would be whether it's easy to figure out for a new user. For the tool controller I'm fine with manually setting which to use and wiping out any M6 commands, but I'm pretty new to CNC.
User avatar
sliptonic
Posts: 1753
Joined: Tue Oct 25, 2011 10:46 pm

Re: Translate imported gcode?

Post by sliptonic » Thu Mar 12, 2020 9:47 pm

etrombly wrote:
Thu Mar 12, 2020 6:39 pm
So I got example_pre to load the gcode as a custom and attach it to a path job (mostly cut and paste from PathCustom to example_pre). I would prefer to use the translation to modify the placement, my only hesitation would be whether it's easy to figure out for a new user. For the tool controller I'm fine with manually setting which to use and wiping out any M6 commands, but I'm pretty new to CNC.
Awesome! I agree with wiping out the existing M6 tool commands and letting the Custom use whichever toolcontroller is used. That's more Path-ish and actually provides a better solution.

On translating the gcode position, I'm still of two minds.

Using the placement of the custom may not be intuitive for a greenhorn unfamiliar with FreeCAD but will make complete sense to anyone who already knows freecad. It's the same way you would move anything around the coordinate system.

Except....for Path things. If you've spent anytime with Path, you know that adjusting the placement of a path object only moves the viewprovider. It doesn't change the underlying Path commands at all. All other Path operations calculate their command coordinates within the reference frame of the Job and relative to the base object.

So if we use the placement of the Custom, we're very FreeCAD-ish and very not Path-ish :lol:

I think the Custom should have a new boolean property to 'use placement'. The default value would be False. The commands of the imported gcode would be as-is and relative to the job origin. Setting the property to True, would add the placement value to each command when post-processed to generate the final commands.

I'll ask @mlampert and @Russ to weigh in.
mlampert wrote: ping
Russ4262 wrote: ping
User avatar
sliptonic
Posts: 1753
Joined: Tue Oct 25, 2011 10:46 pm

Re: Translate imported gcode?

Post by sliptonic » Thu Mar 12, 2020 9:54 pm

Here's something else to think about. It depends how deep down the rabbit hole you want to go...

What if the imported gcode has an M6 Tn command followed by some gcode, then ANOTHER M6 Tx followed by more gcode? In that case, it would make sense to create multiple customs.

At a minimum, I think your improved preprocessor should give lots of helpful output in the report window.
* Mulitple tools detected
* Unknown or unsupported gcodes used
* Tool Length Offset or Tool Compensation commands detected
* etc
Russ4262
Posts: 427
Joined: Sat Jun 30, 2018 3:22 pm

Re: Translate imported gcode?

Post by Russ4262 » Fri Mar 13, 2020 4:01 am

Evening Gentlemen,
@ETrombly, welcome to the forum. Glad to have you, your skills, and your coding involvement!
@Sliptonic, thanks for the invite.

sliptonic wrote:
Thu Mar 12, 2020 9:47 pm
... I think the Custom should have a new boolean property to 'use placement'. The default value would be False. The commands of the imported gcode would be as-is and relative to the job origin. Setting the property to True, would add the placement value to each command when post-processed to generate the final commands.
  • Perhaps instead of `Use Placement`, consider `Apply Placement` or `Apply Current Placement`. Or, I see Sliptonic's initial suggestion of `Use Operation Placement`.
  • @Sliptonic, is the current FC post-processing work flow already setup to apply this placement across the board to all post-processors? Will we only need to insert code into the post-processing work flow to apply the translation before exporting data to a specific post module? Or, will we have to update each post individually to apply the translation?
  • On the tool controller issue, I suggest we consider allowing the user to choose to
    • leave them in tact,
    • wipe the tool controller commands from the imported code, or
    • replace them with an existing tool controller in the target Job
    I am out on a limb here, so perhaps this idea of choice would be more of a long-term goal than an initial alpha version. I understand it would be a lot more work. However, the imported g-code will likely see the benefit for each of these choices as more people use the PathWB.
If I am off base here, please forgive my misunderstanding. I don't have much to offer on this one. It looks like you two have a firm grasp on the topic at hand.

Russ
Post Reply

Who is online

Users browsing this forum: Thorhian, Wsk8 and 2 guests