Hello Guest it is March 29, 2024, 01:04:34 AM

Author Topic: How to turn off an output when the machine is Not Enabled (Disabled)?  (Read 1749 times)

0 Members and 1 Guest are viewing this topic.

Offline jevs

*
  •  315 315
    • View Profile
I setup a button to turn an output on and off that only works when the machine is enabled.
However, if you leave it on and Disable the machine, the output stays on (button itself is disabled).

I also setup custom M codes to turn it off and on. If you turn it on with the M-Code and disable the machine, it will also still leave the output on.

So, I have no idea where and what to put somewhere to ensure this output gets shut down no matter what when the machine is disabled?

Thanks

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: How to turn off an output when the machine is Not Enabled (Disabled)?
« Reply #1 on: August 01, 2019, 04:29:39 PM »
Sounds like you need to rethink your wiring scheme. If it is that important that the output be off if the machine is disabled I would have the Machine enabled output controlling my estop contactor. If the estop contactor goes to an inactive state, it would disable any outputs I wanted to make sure were off if the machine was disabled.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline jevs

*
  •  315 315
    • View Profile
Re: How to turn off an output when the machine is Not Enabled (Disabled)?
« Reply #2 on: August 01, 2019, 04:52:33 PM »
The wire scheme is pretty basic stuff...output 5 turns on a relay (R4 of BOB) that sends power to the oiler. The oiler has the AC main power fed from the contactor that is only turned on if the enable relay is on. That is pretty much it. It will shut down if the main contractor goes off (E-stop hit or enable relay goes off, etc). It is wired correctly. It even has a proper DIN rail mounted fuse and all!
 
However, I think the indicator in Mach will still show it on anyway (even though it is off in reality). I am only able to play with this today with the simulator and the ESS not on (not at the real machine). I don't think it will kill the indicator LED or the output LED on the screen though? I will try it tonight when I load what I was working on today in there to test.

It is not that important, just how I would like for it to work I think. It would be nice to have the indicator on the mach4 screen go out when it is actually off due to the enable relay being off. I will have to load what I worked on tonight to see how my progress works so far. 

« Last Edit: August 01, 2019, 04:56:27 PM by jevs »

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: How to turn off an output when the machine is Not Enabled (Disabled)?
« Reply #3 on: August 01, 2019, 04:59:14 PM »
Look in the screen load script, sigLib and add a little script.

Code: [Select]
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
    machEnabled = state;
    ButtonEnable()
    if (state == 0) then
         --turn off the output
    end
end,
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline jevs

*
  •  315 315
    • View Profile
Re: How to turn off an output when the machine is Not Enabled (Disabled)?
« Reply #4 on: August 03, 2019, 05:02:29 PM »
It took me awhile to figure out how to "--turn off the output" and to understand the signal library somewhat
I am still a little cloudy on when you would put something in the Signal Script
I know I read or watched a video that say what hsig and rc are/do, but now I cannot find it again. I just know I found something like this elsewhere and modified it and it seems to work

I am not sure if it is the best way, but it does seem to work by putting this in the Screen Load Script as you recommended above...
Code: [Select]
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
    machEnabled = state;
    ButtonEnable()
-- Start P&W Mill Added to turn off oiler & Mist (MicroDrop) if Disabled
if (state == 0) then
local inst=mc.mcGetInstance()
local hsig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_MISTON)
mc.mcSignalSetState(hsig, 0); --sets OSIG_MISTON to False
end
if (state == 0) then
local inst=mc.mcGetInstance()
local hsig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT4)
mc.mcSignalSetState(hsig, 0); --sets OSIG_OUTPUT4 to False
end
    -- End P&W Mill Added to turn off oiler & Mist (MicroDrop) if Disabled
end,

I am trying to add notes in there so when I forget all of this later it might jog my memory. Once I get this machine running the way I want, I don't expect to use any of this until I build another machine, which could be awhile.

Offline jevs

*
  •  315 315
    • View Profile
Re: How to turn off an output when the machine is Not Enabled (Disabled)?
« Reply #5 on: August 03, 2019, 05:22:00 PM »
Do I even need those inst = mc.mcGetInstance() in there since at the begging of the screen load script it says this already. Unless you change this somewhere in the code doesn't it apply this to the entire Screen Load script for any code in there?
I removed it and it still works, but I read that Mach4 is not really even using different instances right now. Just want to make sure my assumption above is correct that it is not needed to keep putting it in there.
« Last Edit: August 03, 2019, 05:23:56 PM by jevs »

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: How to turn off an output when the machine is Not Enabled (Disabled)?
« Reply #6 on: August 03, 2019, 06:22:37 PM »
Quote
Do I even need those inst = mc.mcGetInstance() in there since at the begging of the screen load script it says this already.

Nope. As long as the inst variable is within the scope of the script you are working with and is already properly defined there is no reason to redefine it or create a local copy of it.

But, if there is ever a chance the script may be called for different instances of Mach4 you should write the script with provisions to define the inst from whatever is calling it.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: How to turn off an output when the machine is Not Enabled (Disabled)?
« Reply #7 on: August 03, 2019, 06:48:42 PM »
Hi,
the way you have written it you have created a new scope and I should think that a local definition of
instance is required.

Look at the entry in SigLib:

[mc.OSIG_MACHINE_ENABLED] = function (state)

Thus all the code that follows is an anonymous function....and its own scope.
I would therefore put a local GetInstance statement as the second line.

What is the point of this line?:

machEnabled = state;

You haven't used it in your anonymous function. Worse because its not declared local then it will be a global variable
within the GUI chunk.....with all its attendant problems. Is it required?.

The rule with Lua is NEVER use global variables unless you absolutely have to. If you do you should use a register
rather than a 'global' because a global is only visible within the chunk.......not right throughout Mach and all its modules.

Second issue is that this function will be trigger whenever OSIG_MACHINE_ENABLED changes state. Thus it will trigger
when the machine goes from Enabled to Disabled but also when you Enable the machine again.

You should give some thought as to what you want to happen when you enable the machine.

You may have seen that most of the SigLib entries have formats like:

If (state==0) then
      ..........
      ..........
else
      ..........
      ..........
end

Craig

'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline jevs

*
  •  315 315
    • View Profile
Re: How to turn off an output when the machine is Not Enabled (Disabled)?
« Reply #8 on: August 03, 2019, 07:38:39 PM »
I am a little confused here. All I did was add this to what was already there in the screen load script:
Code: [Select]
pageId = 0
screenId = 0
testcount = 0
machState = 0
machStateOld = -1
machEnabled = 0
machWasEnabled = 0
inst = mc.mcGetInstance()

Tframe = nil --TouchFrame handle

--mobdebug = require('mobdebug')
--mobdebug.onexit = mobdebug.done
--mobdebug.start()

---------------------------------------------------------------
-- Signal Library
---------------------------------------------------------------
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
    machEnabled = state;
    ButtonEnable()
-- Start P&W Mill Added to turn off oiler & Mist (MicroDrop) if Disabled
if (state == 0) then
local hsig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_MISTON)
mc.mcSignalSetState(hsig, 0); --sets OSIG_MISTON to False
end
if (state == 0) then
local hsig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT4)
mc.mcSignalSetState(hsig, 0); --sets OSIG_OUTPUT4 to False
end
    -- End P&W Mill Added to turn off oiler & Mist (MicroDrop) if Disabled
end,

[mc.ISIG_INPUT0] = function (state)
   
end,

[mc.ISIG_INPUT1] = function (state)
   -- if (state == 1) then   
--        CycleStart()
--    --else
--        --mc.mcCntlFeedHold (0)
--    end

You ask:
What is the point of this line?:

machEnabled = state;

I thought that has to be there so it has a value for the state and this was already in the code before I touched it.

Are you saying I should not have touched this original code and added this all somewhere else?

To clarify my intent, I want the oiler and mister to turn off anytime the machine is disabled. I do not want it to come back on when enabled until the button is pressed again or the M-code is used.

As this is written, it seems to work. However, that is not to say I did not do something that is not the best practice. I just want to make sure what I am doing is clear. I do want to fix whatever may still be wrong with this.
« Last Edit: August 03, 2019, 07:44:59 PM by jevs »
Re: How to turn off an output when the machine is Not Enabled (Disabled)?
« Reply #9 on: August 03, 2019, 07:53:22 PM »
Hi,
no, not necessarily. I presume if it was already there  then it has some use.

This occurs at the top of the screen load script:
Code: [Select]
pageId = 0
screenId = 0
testcount = 0
machState = 0
machStateOld = -1
machEnabled = 0
machWasEnabled = 0
inst = mc.mcGetInstance()

Note that all these are global variables and are visible through out the GUI.

I have found where machEnabled is used.....in the PLC script. So it does have a use.
Please disregard my comment about its inclusion in your function.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'