Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Penguin on January 02, 2018, 10:29:52 AM

Title: Enable output at startup and disable output at EStop
Post by: Penguin on January 02, 2018, 10:29:52 AM
Hi

For the turret toolchanger of my Emco C5 CNC the motor is set to reverse all the time to lock the turret. It is controlled by two direction and one PWM output.
The direction output and PWM is set in the M6 script after the toolchange and is working well so far.
Now I would like that on first startup / enable the PWM frequency and direction of the toolchange motor are set to the correct value. Also when an EStop occurs i would like to disable both direction outputs for the toolchanger so it stops immediately.
Is there a easy way to do this? As a motion controller I use PoKeys 57 CNC.

Thanks,
Martin
Title: Re: Enable output at startup and disable output at EStop
Post by: Penguin on January 02, 2018, 10:50:34 AM
I forgot to mention that during toolchange the direction of the motor must be reversed to change the tools. If that was not the case I would just add it to the PLC script. Or is there a way to check if a toolchange is running?
Title: Re: Enable output at startup and disable output at EStop
Post by: Penguin on January 03, 2018, 03:54:45 AM
After reading every post that I think has something to do with this topic I think what I want can be done with a signal script.
However I don’t know where all the available signals are documented. If someone could give me an example (see description below) it would help a lot and I think
I can do the rest from there.

-   Machine is disabled via Mach4 button or Estop (is it the same signal internally?
-   Output 1 and 2 are disabled

Martin
Title: Re: Enable output at startup and disable output at EStop
Post by: joeaverage on January 03, 2018, 05:53:02 AM
Hi Martin,
that idea will work, the signal is ISIG_EMERGENCY. If you include it in your signal library you could easily set/reset outputs.

What happens in other situations is not clear. For instance if a limit switch goes active it is common for Mach to stop and disable. Whether that is the same as an
Estop I don't know but if it is then your outputs would not be set/reset as you desired because it was a signal OTHER than ISIG_EMERGENCY that caused it.

There are a couple of API calls that may be of use:
Quote
rc = mc.mcCntlEStop(
   number mInst)
which allows you to invoke an Estop programatically.

Quote
rc = mc.mcCntlEnable(
   number mInst,
   number state)
which allows you to enable/disable Mach at will.

Quote
mcState, rc = mc.mcCntlGetState(
      MINSTANCE mInst)
which allows you to read Machs state at any given time.

It should be easy enough to monitor signals like ISIG_EMERGENCY or maybe others signals which you have attached to screen buttons or physical switches
and they could directly cause the outputs to change in a manner that you determine. In addition it would be necessary to monitor Machs state to see if some other
event caused Mach to disable, like a limit event. The problem would be that once you detect Mach has been disabled its too late to set/reset outputs....I think!

My suggestion would be to experiment with some cut down code to determine what if any functionality remains active when Mach is disabled. If this phase/mode of
operation still allows you to set/reset outputs at will then the most problematic part of your proposal will achievable.

Craig
Title: Re: Enable output at startup and disable output at EStop
Post by: joeaverage on January 03, 2018, 06:26:04 AM
Hi,
I tried this small piece of code:

Code: [Select]
function m100()
local inst=mc.mcGetInstance()
local hsig=mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT1)
mc.mcSignalSetState(hsig,1)
wx.wxMessageBox('enabled, output set')
mc.mcCntlEnable(inst,0)
mc.mcSignalSetState(hsig,0)
wx.wxMessageBox('disabled, output reset')
end
if (mc.mcInEditor()==1)then
    m100()
end

It seems to work. In order to run m100 as MDI mach must be enabled. Output#1 is set as seen on the machine diagnosics page and the message box is displayed.
When the message box is dismissed then Mach disables AND THEN Output#1 is reset and a new message box is displayed.

It would appear therefore that you could indeed monitor Machs Enable state and on Disable set/reset outputs at will despite Mach being disabled. Nifty!!

Craig
Title: Re: Enable output at startup and disable output at EStop
Post by: Penguin on January 03, 2018, 06:58:12 AM
Hi Craig,

You are great, thank you very much for the information. I will try it as soon as i get home tonight.
Do you also know if there is a signal like  ISIG_EMERGENCY for ENABLE? When i press the estop Mach is also disabled at the same time but when i press the disable button mach is not in estop.
Therefore i would rather use the enabled signal. Maybe i don't get it and these signals are the same, i will try  :)

Martin
Title: Re: Enable output at startup and disable output at EStop
Post by: joeaverage on January 03, 2018, 07:16:31 AM
Hi Martin,
no there is to my knowledge no signal like that. Enabled is a 'state' not a signal.

I suspect that Estop causes Mach to disable but I would also suspect that you cannot change outputs for instance when Mach is in Estop. You can however
change outputs when Mach is disabled as the little piece of code establishes. You could monitor a signal including ISIG_EMERGENCY and have it disable Mach,
change the required outputs AND THEN Estop. If however you allow the internal function to proceed the machine will Estop before you can set the outputs.

You will in effect have to monitor the Enable state.

Craig
Title: Re: Enable output at startup and disable output at EStop
Post by: Penguin on January 03, 2018, 07:48:32 AM
Ok, i think I will start with monitoring mach's enable state.
Is there any documentation about what

mcState, rc = mc.mcCntlGetState(
      MINSTANCE mInst)

returns in enabled or disabled state

About the estop behaviour: Is there even a way to change the behaviour when an estop occurs like you described it?
I'm sorry to ask so many questions but I'm more of a mechanics guy and Mach4 and the different functions are quite overwhelming...
If nothing works, i will disable the signals with a relay :)

Martin

Title: Re: Enable output at startup and disable output at EStop
Post by: Chaoticone on January 03, 2018, 09:23:11 AM
Would this work?

Motor control
Use a relay or relays to swap rotation direction. It would be wired so that when the relay/s are off it rotates in the default direction (no output required). To change direction you fire a single output (which if I'm not mistaken will deactivate in an estop).

Motor power should come from or be made available to motor only if estop loop is closed. If estop loop opens for any reason (estop button, onscreen button, servo fault, etc.) an estop contactor should drop out removing power from the motor so that even if the control side was telling it to rotate, it couldn't.

Remember, no software should be involved in any way in an estop (or other safety) loop. Hardware and wiring strategy should put the machine in a safe state if the estop loop is broken. Only use an estop input from estop contactor to simply notify Mach an estop has occurred and stop it from running.

Title: Re: Enable output at startup and disable output at EStop
Post by: Fledermaus on January 03, 2018, 09:32:04 AM
Another way you can test Mach's enabled state is to use:

   local machEnbld = mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.OSIG_MACHINE_ENABLED))

This returns 0 or 1.

Allan
Title: Re: Enable output at startup and disable output at EStop
Post by: Penguin on January 03, 2018, 10:41:22 AM
Motor control
Use a relay or relays to swap rotation direction. It would be wired so that when the relay/s are off it rotates in the default direction (no output required). To change direction you fire a single output (which if I'm not mistaken will deactivate in an estop).

This would not work because Mach4 in combination with PoKeys does not deactivate the output in case of an estop. If you know how to change that, please let me know :).
By the way all other drives are deactivated via Safe Torque Off that is controlled by a PNOZ safety relay. The DC Motor driver does not offer such a funcionality and I think it is unnessecary because it has very little power. It can easily be stopped by hand. Also one second after the estop a contactor cuts the power supply to all drives and also the toolchanger. The contactor is monitored by the safety relais.
However, when the estop is cleared and the power is reconnected, the toolchanger starts turning again, because the output of mach is still enabled.
I will try your suggestions and let you know. Thank you very much for the help so far.

Martin
Title: Re: Enable output at startup and disable output at EStop
Post by: Cbyrdtopper on January 03, 2018, 11:08:20 AM
If you want to de activate an output with the e stop, you can put the estop in the signal library.  That's what I do with machines here in our shop.  If the Estop state = 1 then turn off outputs. 
Title: Re: Enable output at startup and disable output at EStop
Post by: Penguin on January 03, 2018, 02:12:34 PM
If you want to de activate an output with the e stop, you can put the estop in the signal library.  That's what I do with machines here in our shop.  If the Estop state = 1 then turn off outputs.  

Can you tell me where you edited the code? I tried adding the following lines to the screen load script but and then executed a macro to start an estop. The output stays enabled unfortunately...

Quote
[mc.ISIG_EMERGENCY] = function (state)
        if( state == 1) then
        local hReg = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1)
        mc.mcSignalSetState(hReg, false)
        end
end,

Quote
function m155 ()
      local inst = mc.mcGetInstance()
      rc = mc.mcCntlEStop(inst)
end
Title: Re: Enable output at startup and disable output at EStop
Post by: Penguin on January 03, 2018, 02:26:45 PM
Found the problem: The M155 does not trigger the Emergency Input. I added a button for estop to the screen and now its working perfectly fine. When the estop is pressed, the output is disabled.

Thanks for the help, now i can continue writing the code for the toolchanger.  :)

Martin
Title: Re: Enable output at startup and disable output at EStop
Post by: Cbyrdtopper on January 03, 2018, 04:49:28 PM
Okay.  Good deal.  I will need to get the code from a machine to remember exactly how I turn off outputs.  Just for a reference.