Where to insert code to issue G4 command after spindle start?

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!
sebste
Posts: 25
Joined: Tue Sep 01, 2015 9:23 am

Where to insert code to issue G4 command after spindle start?

Post by sebste »

Hi Folks!
With great pleasure I was discovering all the improvements the PATH module has made recently. It is just awesome! Thanks to all the contributors - you rock!

I am using grbl_post and was wondering, how I could get it to insert an "G4 5" command to wait 5 seconds for the spindle to get up to speed, every time a "M3" Command was issued. Do I need to edit the post processor? I could not find any related code sections there. Any suggestions?

This would also be a good place to switch on coolant, etc.

Thanks, guys.
Sebastian

P.S. Adaptive tool paths are a dream come true! I am really excited.
mlampert
Veteran
Posts: 1772
Joined: Fri Sep 16, 2016 9:28 pm

Re: Where to insert code to issue G4 command after spindle start?

Post by mlampert »

yes I think a personalised post processor is the way to go here.
User avatar
roerich_64
Veteran
Posts: 1465
Joined: Thu May 21, 2015 7:00 pm
Location: Ostfriesland

Re: Where to insert code to issue G4 command after spindle start?

Post by roerich_64 »

Those setting should be do in the global settings and there define the preamble and postamble ;)
Global_Pre-Postamble.jpg
Global_Pre-Postamble.jpg (141.25 KiB) Viewed 2122 times
BR
Walter
Die Liebe wird siegen, denn sie ist unzerstörbar :) ;)
chrisb
Veteran
Posts: 53920
Joined: Tue Mar 17, 2015 9:14 am

Re: Where to insert code to issue G4 command after spindle start?

Post by chrisb »

It belongs neither in preamble nor postamble. This G4 command is to be issued after each toolchange. Pre- and postamble are executed only once.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
herbk
Veteran
Posts: 2657
Joined: Mon Nov 03, 2014 3:45 pm
Location: Windsbach, Bavarya (Germany)

Re: Where to insert code to issue G4 command after spindle start?

Post by herbk »

Hi

hm, after a bit thinking about it. - It would be not a bad thing to have option buttons at the UI for switching coolant and spindle on and off (and pause, if needed) at each OP...
Gruß Herbert
sebste
Posts: 25
Joined: Tue Sep 01, 2015 9:23 am

Re: Where to insert code to issue G4 command after spindle start?

Post by sebste »

Thank you guys for your answers, so far.
I agree with herbk. Just to have an option to insert custom g code before and after each op, to be defined in the setup sheet would give the most flixibility, I guess. This was the way I could set it up in Estlcam for instance.

So if i solve in the postprocessor, I was thinking, doing it similar to the way the toolchange is handled would be a working approach, right?

But I really think, having "hooks" before and after each op for custom code in the setup sheet could kill a lot of birds with one stone. Haven't looked at the source for ages, so I have no clue how hard this is to implement...
User avatar
sliptonic
Veteran
Posts: 3457
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: Where to insert code to issue G4 command after spindle start?

Post by sliptonic »

Take a look at the linuxcnc post. It has a pre_op and post_op global that does exactly this.
sebste
Posts: 25
Joined: Tue Sep 01, 2015 9:23 am

Re: Where to insert code to issue G4 command after spindle start?

Post by sebste »

Thanks for the hint! I tried this and ran into another problem.
I want to insert the G4 command right after the M3 command to wait for the spindle to get up to speed. This is not necessarily before or after every operation but just for the tool change operation. Including it in post_op would lead to adding G4s up unnecessarily. So using pre_ope and post_op does not really work. Any Ideas how I can intercept the spindle start command? It would work, of the spindle start commands would be issued by the pre_operation code, but they seem to be part of the operations itself. Any suggestion of how I can get hold of the spindle that command? Can I filter for it in the postprocessor?

Thank you once more.
User avatar
sliptonic
Veteran
Posts: 3457
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: Where to insert code to issue G4 command after spindle start?

Post by sliptonic »

There's this: https://github.com/FreeCAD/FreeCAD/blob ... ost.py#L96

If you want to insert a command AFTER a tool change, you could do something similar
sebste
Posts: 25
Joined: Tue Sep 01, 2015 9:23 am

Re: Where to insert code to issue G4 command after spindle start?

Post by sebste »

Hey guys!
While investigating the options for my problem here, I went down the rabbit hole and discovered another but related potential issue.

As far as I see, the Spindel start (M3 S0.000) is always initiated by a toolchange operation(M6). In my opinion this can be really problematic. Something like starting a spindle, laser, waterjet, etc. should always be done explicitly before an operation and not by a toolchange. Also keep in mind, that some machines ignore the spindle speed (S0.000) and switch on the spindle, as soon as they see the M3 command. So M3 S0.000 is really not the same as not starting the spindle at all. Not fun if the tool that happens to be in on the spindle is a drag knife for instance.

I would suggest, that the tool controller determines whether the spindle start command is issued or not. Maybe it can be a checkbox besides the spindle speed field. (Maybe If we could get hold hold of the M3/M4 command in the postprocessor (as operation), the postprocessor could eliminate the M3/M4 command if S is 0 so we would not need a checkbox in the tool controller. There we could also include the G4 command.)

Also I don't see, why a toolchange is an operation and starting the spindle is not. If it would be an operation, we could probably put some spindle specific code pre or post it in the postprocessor, just like it is done (pre) with the toolchange.

In any case, starting the spindle should happen right before the operation that needs it and not after the operation of changing a tool.

What do you guys think?

P.S. I tried to catch the M3 / M4 commands in the postprocessor, just like it is done with M6, but had no luck. I think this is because M3/M4 is not an operation, right? Also I can not see any output / error messages from the post processor in the python console. How do you handle this?
Thanks again for your help
Post Reply