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.

More
28 May 2026 21:41 #346716 by MaHa
Replied by MaHa on topic Reset Custom M-codes on Machine Disable?
In my sim,  on_abort.ngc is called when pressing F2, machine off. It also has a bash script, M100 P1 . Machine on doesn't trigger on_abort.

 
The following user(s) said Thank You: spumco

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

More
29 May 2026 00:02 #346720 by rodw
Replied by rodw on topic Reset Custom M-codes on Machine Disable?
You cant use a shutdown.hal file, maybe unlinkp some pins and then use setup to set them to your desired state?
Really left field idea that I have no idea if it would work could be to use loadusr in shutdown.hal to load a python script that does what you want...

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

  • djdelorie
  • Away
  • Senior Member
  • Senior Member
More
29 May 2026 00:20 #346721 by djdelorie
Replied by djdelorie on topic Reset Custom M-codes on Machine Disable?
Is there any way a custom HAL component can change the state of motion's dout pins?  I mean, their actual state, not AND'ing them with something, as if a M65 happened.

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
29 May 2026 16:53 #346740 by Todd Zuercher
Replied by Todd Zuercher on topic Reset Custom M-codes on Machine Disable?
Does a shutdown hal file only run on exiting out of Linuxcnc, or would it run when ever the machine is disabled to the machine off (F2) state? That sounds like the simplest way if it the shutdown hal is exicuted when ever the machine is put to the off state.

Will the on_abort.ngc work without remap? I'm assuming that the file should not have any motion causing codes in it. Are there any restrictions as to what commands can be executed in it? If I can execute some custom M-codes in it, that should be good enough for my purposes.

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

More
29 May 2026 17:50 #346743 by spumco
Replied by spumco on topic Reset Custom M-codes on Machine Disable?
According to the docs, shutdown.ngc only gets run when exiting normally.  Machine-off state does not trigger it, and neither does a PC crash.

I think on-abort.ngc should work without explicitly remapping.  A quick test could confirm:
  • Create a test abort.ngc file with something in it to test (i.e. halcmd to set a pin value)
  • Add the file to you INI
  • Create user M-code (M1xx) which creates some sort of call to the abort.
    • All of my M66 checks in the various tool-change (or similar) sequences have something like:
    • [*]M66 P9 L3 Q2                                        ; Check ATC door open sensor
      O100 if [#5399 LT 0]
            M65 P8                                          ; Turn off ATC door open solenoid
          (abort, ATC door not open)                      ; Abort if the sensor does not activate in 2 seconds
        O100 endif
      [*]
You could make the abort.ngc be the bash script, or you could create another M1xx bash script and use abort.ngc to call that M-code.

Once you've got everything set up, open halshow and add the hal pin you want to twiddle using abort.ngc.  Call the M-code which will abort and see if the hal pin changes state.
The following user(s) said Thank You: tommylight

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

Time to create page: 0.227 seconds
Powered by Kunena Forum