G-Code to turn machine OFF

More
05 Jan 2012 22:54 #16361 by ElectroNick
Hi all, my first post in this great forum!

Been using EMC2 for a couple of years but never actually needed this feature before. But I'm tinkering with a very small router now that has motor heating issues and it's so quiet (cutting with a laser diode) that I no longer hear the cutting process complete.

I would love to be able to turn the power to the machine off automatically upon completion of the program but neither M2 nor M30 seem to accomplish what the F2 (Toggle machine power) button in EMC2 interface does.
I have Pin 17 in the parallel interface defined as "Amplifier Enable" and it works just fine with the F2 button but I need to be near the machine to press it, obviously.

is there a G-code already for doing something like that automatically? Or should I define a user M-code for that? I'd have to admit I never did custom codes before and some pointers would be greatly appreciated.

Thanks!

Please Log in or Create an account to join the conversation.

More
05 Jan 2012 23:58 #16364 by andypugh
ElectroNick wrote:
[quoteis there a G-code already for doing something like that automatically? ![/quote]

No.

However, I think that you could easily do it with a custom M-code.

You will need HALUI=halui in the [HAL] section of the INI file.
Then create an executable file called (for example) M101 as described here
www.linuxcnc.org/docview/html/gcode_main.html#sec:M100-to-M199
That needs to contain a command to set the machine state as described here
www.linuxcnc.org/docview/html/gui_halui.html#r1_2_10

so, try this:
#!/bin/sh
halcmd setp halui.machine.off true
exit 0

Please Log in or Create an account to join the conversation.

More
06 Jan 2012 04:28 #16370 by ElectroNick
Thank you andypugh, that sounds easy enough to do. I was just wondering if similar command could be added to the part of EMC2 code that responds to a regular "program end" code like M2 or M30. Is standard G and/or M-code processing accessible in a similar way in EMC?

Also, speaking of custom M codes: does anyone think that there may be codes to stay away from, i.e. ones that are already frequently used by various G-code converters and such? I've looked into some 3D printing G-Code and there's a whole lot of M commands that are from within the user-defined range 101-199 but are used pretty regularly.

Thanks!

Please Log in or Create an account to join the conversation.

More
06 Jan 2012 10:40 #16374 by andypugh
ElectroNick wrote:

Thank you andypugh, that sounds easy enough to do. I was just wondering if similar command could be added to the part of EMC2 code that responds to a regular "program end" code like M2 or M30. !


Possibly.
linuxcnc.org/docview/devel/html/remap/structure.html
it's a fair bit less trivial, though.

Please Log in or Create an account to join the conversation.

More
06 Jan 2012 17:58 #16381 by ElectroNick
andypugh wrote:

Possibly.
linuxcnc.org/docview/devel/html/remap/structure.html
it's a fair bit less trivial, though.

You were not kidding about this being less trivial! :S
Also, after reading this, it looks like remapping is not supported for the modal group 4 codes, which all program stops belong to. And, digging even deeper into Axis internals would be a foolish move. I guess I'll just add a user-defined M-code.

As a side question though: why would you NOT want to turn the amps OFF when you've stopped the program for good? Sounds like what I'm looking for should have been a default behavior? After all, it does turn spindle and coolant off without additional M9 or M5 upon encountering an M2 or M30. Why not also throw amps into OFF? What am I missing?

Please Log in or Create an account to join the conversation.

More
06 Jan 2012 18:01 #16383 by andypugh
ElectroNick wrote:

As a side question though: why would you NOT want to turn the amps OFF when you've stopped the program for good?

On many systems doing that will drop the head onto the table, or the knee onto the floor.
You also tend to lose home positions etc.

Bear in mind that at program-end most machines get reloaded and run the next part.

Please Log in or Create an account to join the conversation.

More
06 Jan 2012 18:23 #16384 by ElectroNick
andypugh wrote:

On many systems doing that will drop the head onto the table, or the knee onto the floor.
You also tend to lose home positions etc.

Bear in mind that at program-end most machines get reloaded and run the next part.

I see, it does make sense. Anyway, thanks for the tip on the custom M code. To add one at the end of the program is not a big deal, I'll just go that route.
Thanks!

Please Log in or Create an account to join the conversation.

More
28 Jun 2019 00:57 #138069 by MasterSpoon
Figured rather than starting a new topic would ask in this one as it's the top search result however most of the links are dead.

I am trying to do similar to what the OP was wanting to do, have a desktop machine that I'm planning to have running while I'm not near it and might not be back to check on it for hours at a time so want it to power down the stepper motors once it's finished. Have just finished installing relays for the cooling and spindle so turning them off in G-code is easy.

Running a Gecko G540 stepper controller, have it setup using a charge pump (Pin 16) to enable the stepper drivers. If it has charge pump signal the steppers are powered regardless of if the Machine Power (F2) is on or off. Without charge pump the controller sends an E-stop.

hal file entry for charge pump if it makes any difference is
loadrt charge_pump
net estop-out charge-pump.enable iocontrol.0.user-enable-out
net charge-pump <= charge-pump.out

Ideally I would want to be able to pop an M300 at the end of my Gcode file if I'm not hanging around and have it power off the steppers once it's done. I have been able to get part of what I want done, just stuck on the final piece of the puzzle.

So far with reading the Wiki and also following this topic
forum.linuxcnc.org/38-general-linuxcnc-q.../31909-custom-m-code
I have created a sub routine to power off the coolant, spindle, wait 5 seconds but don't know how to send an E-Stop or turn off the charge pump to power down the steppers
o<m300> sub
M9
M5
G4 P5

m30
o<m300> endsub

If turning off the coolant, spindle, wait 5 seconds then power down is to hard, it will also work by just sending an E-stop or turning off the charge pump as their relays are controlled through the G540 so a E-stop will turn them off also. I'm not sure if the subroutine was the right way or if I should have been creating an executable ?

Please Log in or Create an account to join the conversation.

More
28 Jun 2019 01:04 - 28 Jun 2019 01:04 #138070 by andypugh
The M100-M199 codes can be any executable file.

Without any testing my first guess would be
#! /bin/bash
halcmd setp halui.machine.off 1
exit 0

This is very similar to the M101 and M102 examples here:
linuxcnc.org/docs/2.7/html/gcode/m-code.html#mcode:m100-m199
Last edit: 28 Jun 2019 01:04 by andypugh.

Please Log in or Create an account to join the conversation.

More
28 Jun 2019 01:05 #138071 by bevins
So why don't you simply have a relay follow machine-is-on , and supply charge pump signal to g540 with the relay.

That's how I use my g540

Please Log in or Create an account to join the conversation.

Time to create page: 0.086 seconds
Powered by Kunena Forum