G-Code to turn machine OFF
- ElectroNick
- Offline
- New Member
- Posts: 4
- Thank you received: 0
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.
[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.
- ElectroNick
- Offline
- New Member
- Posts: 4
- Thank you received: 0
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.
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.
- ElectroNick
- Offline
- New Member
- Posts: 4
- Thank you received: 0
You were not kidding about this being less trivial!Possibly.
linuxcnc.org/docview/devel/html/remap/structure.html
it's a fair bit less trivial, though.
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.
On many systems doing that will drop the head onto the table, or the knee onto the floor.As a side question though: why would you NOT want to turn the amps OFF when you've stopped the program for good?
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.
- ElectroNick
- Offline
- New Member
- Posts: 4
- Thank you received: 0
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.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.
Thanks!
Please Log in or Create an account to join the conversation.
- MasterSpoon
- Offline
- New Member
- Posts: 10
- Thank you received: 0
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.
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
Please Log in or Create an account to join the conversation.
That's how I use my g540
Please Log in or Create an account to join the conversation.