Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Cbyrdtopper on December 27, 2016, 04:48:18 PM

Title: Toggle Coolant on/off in SigLib
Post by: Cbyrdtopper on December 27, 2016, 04:48:18 PM
I'm setting up a new machine and I have 2 buttons on my control panel, one to toggle the spindle and one to toggle the coolant.  I haven't figured out how to toggle them on and off in the signal library.  
  
Button1 is set to input 1
Here is what I am wanting:
Input1 triggered ----> turn on coolant
Input1 triggered again ----> turn off coolant

I keep referencing the scripting manual but I can't figure out what the signal table is or where to put it.  I'm working in the screen load script under Signal Library.  I've made the button turn on the coolant on the press and then it shuts off on the release.

Is this possible in the signal library?


Here is what i've worked on so far and have gotten practically nowhere


----Input 1 Coolant On/Off --------------> THIS KEEPS COOLANT ON BUT DOESN'T TURN IT OFF 12/27/16
--[mc.ISIG_INPUT1] = function (on_off)
    
--     if mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON, 0) then
--         if (on_off == 1)  then
--         local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
--         mc.mcSignalSetState(OSigCool,1)
--         mc.mcCntlSetLastError(inst, "Coolant On")
--         end
--     else
--         if (on_off == 1)  then
--         local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
--         mc.mcSignalSetState(OSigCool,0)
--         mc.mcCntlSetLastError(inst, "Coolant Off")
--         end
--     end
--end,

----------------------> this turns on with press and turns off with release
--Input 1 Coolant On/Off
--[mc.ISIG_INPUT1] = function (on_off)
--    if (on_off == 1) then
--         local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
--         if mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON, 0) then
--         mc.mcSignalSetState(OSigCool,1)
--         mc.mcCntlSetLastError(inst, "Coolant On")
--         end
--    else
--         local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
--         if mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON, 1) then
--         mc.mcSignalSetState(OSigCool,0)
--         mc.mcCntlSetLastError(inst, "Coolant Off")
--         end
--     end
--end,

Any help would be great.

Title: Re: Toggle Coolant on/off in SigLib
Post by: Chaoticone on December 28, 2016, 07:46:05 AM
Look at the default screens that come with Mach4 (wx4 and wx6) and see how they are done. That is how they work.
Title: Re: Toggle Coolant on/off in SigLib
Post by: Cbyrdtopper on December 28, 2016, 11:33:55 AM
I hadn't thought about that Chaoticone, Thanks!

I took the code from the spindle cw button and it worked great!  The Coolant button didn't have code in it but I put together something that works well.


------------Input0----------------
--------Toggle SpinCW()-----------
[mc.ISIG_INPUT0] = function (state)
if (state == 1) then
     local inst = mc.mcGetInstance();
     local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
     local sigState = mc.mcSignalGetState(sigh);
     if (sigState == 1) then
         mc.mcSpindleSetDirection(inst, 0);
     else
         mc.mcSpindleSetDirection(inst, 1);
     end
end
   
end,


----------Input 1------------
------Toggle Coolant---------
[mc.ISIG_INPUT1] = function (state)
if (state == 1) then
     local inst = mc.mcGetInstance();
     local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_COOLANTON);
     local sigState = mc.mcSignalGetState(sigh);
     if (sigState == 0) then
         local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
         mc.mcSignalSetState(OSigCool,1)
         mc.mcCntlSetLastError(inst, "Coolant On")
     else
         local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
         mc.mcSignalSetState(OSigCool,0)
         mc.mcCntlSetLastError(inst, "Coolant Off")
     end
end
   
end,
Title: Re: Toggle Coolant on/off in SigLib
Post by: Chaoticone on December 28, 2016, 11:51:44 AM
No problem.

Unless you have some additional functionality you need to add to the buttons you really should not have to do much more than assign the proper left up action to the button (like the default coolant on/off button does). Maybe you can avoid signal script and custom functions all together?

Don't forget you have toggle buttons in screen designer too. So you can make them do one thing on one press and another on a second press (like spin CW and spin stop).

The reason the spindle toggle is done as it is in the default screens is there are 2 spin on/off toggle buttons. One for CW and one for CCW. We wanted both buttons to stop the spindle if it was on and no mater which direction it was running in. We wanted them to individually turn it on in a particular direction though.

Hope that makes sense.
Title: Re: Toggle Coolant on/off in SigLib
Post by: Chaoticone on December 28, 2016, 11:55:50 AM
The script you posted looks fine too BTW.

Title: Re: Toggle Coolant on/off in SigLib
Post by: Cbyrdtopper on December 28, 2016, 12:02:29 PM
Thanks for the reply and for looking at my script!  I truly appreciate the time you took for that!  The screen designer is very powerful and has some really great functions, however I'm using this code for physical buttons on my control panel as well as a foot pedal to toggle a pneumatic clamp for a grinder we are building. 

Also, has the Mach team thought about having Axis Fault inputs integrated into Mach?  Or would that be something that would be controlled via plugins?
Title: Re: Toggle Coolant on/off in SigLib
Post by: Chaoticone on December 28, 2016, 12:19:32 PM
OK, that makes sense. Yes, if using external switches using the signal script is the way to go.

Some motion devices have inputs for drive faults I think. But, if the motion device and its plugin do not have a way to handle drive faults you could just map them to any generic input in Mach and then use the signal script to do whatever is needed. One thing you might want to consider is using the fault output from the drives in your estop loop. I have used an output as an enable signal to one drive and that drives ready signal is the enable input to the next........ daisy chain them together like that. Can even put that daisy chain in the estop loop. That has worked good for me. All depends on your drives and how you need it to work. The machines I have done that on are not huge so having a dedicated input and/or message for each drives fault was not necessary. The operator can glance at the machine and see whats out of place. If it were so big they could not see all axis at once I would do it different.
Title: Re: Toggle Coolant on/off in SigLib
Post by: Cbyrdtopper on January 03, 2017, 10:02:22 AM
I really like your idea of sending the alarm signal through the estop loop, that should work just fine for me and very simple to set up!!  Thanks for the insight, really appreciated over here!
Title: Re: Toggle Coolant on/off in SigLib
Post by: Chaoticone on January 03, 2017, 10:21:50 AM
No problem, hope it helps.

I have attached an example wiring diagram.