Reset Custom M-codes on Machine Disable?

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Away
  • Platinum Member
  • Platinum Member
More
28 May 2026 17:18 #346706 by Todd Zuercher
Reset Custom M-codes on Machine Disable? was created by Todd Zuercher
A machine I'm working with uses a couple of M1xx custom M-codes to put the machine in a peculiar state for some machining processes.  This causes some significant problems if they are not properly canceled in the appropriate way.  To help with this, I would like to be able to "reset" the hal pins that the custom M-codes manipulate if the machine is disabled (put in the F2 "machine off" state.)  Is there a way to do this that won't interfear with the way the custom M-codes setp the hal pins they need to manipulate?  Basically I need the machine to setp certain hal pins when it goes to the "Machine Off" state.

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

More
28 May 2026 18:36 #346707 by spumco
Replied by spumco on topic Reset Custom M-codes on Machine Disable?
Are you looking for an 'abort' sequence, or a machine-is-off/tripped sequence?

The abort - i.e. an aborted g-code program - you can do with an on-abort.ngc that calls various M-codes to set the machine in a state you want.

If you need to force hal pins or write specific values to pins, you can create a bash program M-code and directly manipulate the hal pins.

I'm sympathetic to your question because I really, really need to go through all my custom stuff/logic and figure out the same thing you're thinking about now.  What are the various machine states, and what do I want to happen when it turns back on?

Example - I have a pneumatic door cover for my ATC.  If I stop the machine in the middle of a tool change the door stays open.  But when I retract the ATC (manual ATC M-codes) and restart LCNC, the door slams shut the moment the machine is 'on.'  Scares the you-know-what out of me every time.

It's not a graceful error-handling situation.

I'm rambling here, but I suspect all of the machine-state error handling and permissions might be better handled in Ladder.

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

More
28 May 2026 18:56 #346708 by spumco
Replied by spumco on topic Reset Custom M-codes on Machine Disable?
I just re-read what I posted - that was kinda unhelpful of me.  Sorry.

The dirty way to 'turn off' the underlying M-code hal pins is an and2 component.

I assume you're using a motion.digital-out-NN to set the pins (G64 Pnn).  From there, the digital-out-NN pin is connected to something, maybe through some other signals/pins.

At some point downstream of the digital-out-NN pin, you can insert an and2 component that requires motion.motion-enabled (or halui..machine-is-on) be true along with the digital-out-NN pin.

Problem with that method is that an aborted program may leave the digital-out-NN pin true, and the second you turn the machine back on the above and2 component will resolve true and permit the and2.N.out to go true.

What you (and I) need is some way to clear out - reset - any lingering hal pin states left from aborted programs.  And the problem (as far as I know) is that an 'on-abort.ngc' file is only triggered during a program that's aborted on purpose.  If you get a power outage, or just hit the machine-off or estop button, the on-abort.ngc file isn't run and the undesired hal pin states aren't reset.

Some sort of start-up sequence that ensures the machine state is what you want - and it has to be set/run/active before the machine is permitted to enter the ON state.

This is why I'm thinking Ladder is maybe the route.

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

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Away
  • Platinum Member
  • Platinum Member
More
28 May 2026 18:59 - 28 May 2026 19:01 #346709 by Todd Zuercher
Replied by Todd Zuercher on topic Reset Custom M-codes on Machine Disable?
I'm looking for a way to execute a. Bash script or some other way to setp the value of a number of Hal pins or hal signals when the machine goes to the off state. Not when just when aborting a running program. But a situation during a running program that results in machine off, such as hitting a hard limit, I would want to execute this.
Last edit: 28 May 2026 19:01 by Todd Zuercher. Reason: Auto correct messed me up.

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

More
28 May 2026 19:27 - 28 May 2026 19:41 #346711 by spumco
Replied by spumco on topic Reset Custom M-codes on Machine Disable?
The only way I can think of doing something like what you want (without using ladder) is to have the M-codes trigger a one-shot to set the target hal pin rather than using the digital-out pin directly.

If you use a one-shot to set a pin state via M-code then there's nothing 'forcing' the pin to a certain value.  And you can use a 'turn-the-machine-on' sequence to set the value using another one-shot.  Maybe.

Are the hal pins all on/off bits, or do you have S32/U32/floats where you are setting/resetting a specific value?

EDIT - I think we both need to read the manual a bit.  

linuxcnc.org/docs/stable/html/remap/rema...p:sec:error-handling

This looks promising, in that maybe the on-abort isn't just for an aborted program.  Have to do more thinking.
Last edit: 28 May 2026 19:41 by spumco.

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

Time to create page: 0.080 seconds
Powered by Kunena Forum