Hello Guest it is March 28, 2024, 11:06:28 AM

Author Topic: Normally Open VS Normally Closed  (Read 20321 times)

0 Members and 1 Guest are viewing this topic.

Offline Hood

*
  •  25,835 25,835
  • Carnoustie, Scotland
    • View Profile
Re: Normally Open VS Normally Closed
« Reply #20 on: August 13, 2016, 01:41:18 PM »
Did you have that or did you have GetOemLED(13) ?

I presume you are using  the coolant output option in Mach?
What I suspect is happening is you have the Coolant  On, you are resetting the output but the coolant button is still on so Mach switches it back as soon as you switch off.
 That is why I suggested the DoOemButton be used..

Your UserLeds should work fine as long as you only ever turn on/off via that script and not by other means. But do you really need to know? What I mean is if your vac pump requires to be switched off you can reset the outbit and if it is already off it doesn't matter a toss.

Hood
« Last Edit: August 13, 2016, 01:51:42 PM by Hood »
Re: Normally Open VS Normally Closed
« Reply #21 on: August 13, 2016, 03:09:59 PM »
Yep, GETOEMLED(13).  That was a typo.  And yes, I enabled the coolant option.

This is not a huge issue except I have things I want to do that are not quite norm for a mill.  In the PLC world, this is easy because it scans the entire program and I am in control of the entire program.  Don't really even need to ask as the only way it could be ON is if I turned it on.

In mach, this is very different.  Coolant function being perfect example.  Mach has control once that option is turned on.  No big deal, just have to deal with that.  So the main idea in this case was to avoid having to turn on and off coolant in the g-code program.  It would have been no big deal to just have my CAM software always add the coolant function before and after tool changes.  And then of course edit program if I didn't really want it on.  Would very much so like to avoid this.

On my machine, I will have an air gun, vacuum, and atleast 3 independant coolant nozzles (6 would be great).  I cut a lot of plastic parts and the chips can be overwelming at times.  Thus the shop vac that is just a suction tube mounted just like the coolant nozzles.  This allows me to suck the chips out as I'm cutting or to make a pass with no tool and clean out pockets and so on.  But 99 percent of the time, if coolant or vac or air gun (or all) was ON before a toolchange, its gonna be ON after the tool change.  But I don't want any of them ON during the tool change (Coolant and compressed air blowing into carosel while its open).  Thus the need to know if they were ON before the change was requested.  I could always just turn them all OFF and require myself to turn the right one back on in the GCode program.  Wheres the fun in that.  I have a programmable controller at my disposal.

Point being, I'm learning how to use MACH.  But with CSLabs hardware, I have a ton of I/O that I want to get real creative with.  I can think of a bunch of cool things that could be done with the extra I/O.

As for using the UserLeds and matching them to particular outputs.  This would allow them to be turned ON or Off, and also just be monitored from any script.  Unless I'm missing something.  A UserLed would stay ON when the script is finished.  And then could be looked at and/or changed later by any other script.  Just have to always do the two step.  Set the UserLed and set the output.

Offline Hood

*
  •  25,835 25,835
  • Carnoustie, Scotland
    • View Profile
Re: Normally Open VS Normally Closed
« Reply #22 on: August 13, 2016, 03:40:32 PM »
What I am saying regarding the coolant is you have it set up in Mach as the coolant and Mach is switching the output on/off. So if you have the coolant on and then switch off by VB using the actual Output (ResetOutBit() ) then it will just get switched right back on because Mach is doing that. If your VB used the Coolant Toggle button to switch it off then it would switch off.
So
If GetOemLED(13) Then
 DoOemButton(13)
End If

That should do exactly what you want.

For other things that are not controlled from Mach you should be fine, for example if you wanted the vacuum from a switch you could do it via either a G Code switch or via  a VB switch and also have a custom macro to do it. You could use the User LEDs.


So say you want the vaccum on output 0 of the IP-A  then you could make a custom macro, lets call it m123.m1s.
In that macro you would have something like

If GetUserLED(1111) = 1 Then
 ReSetOutBit(90,0)
SetUserLED(1111,0)
Else
 SetOutBit(90,0)
 SetUserLED(1111,1)
End If


Now if you call m123 from code or MDI it will look at the state of the LED and switch on/off the output accordingly.

Now if you want a screen toggle button to also do this you add a button with one of the screen designers and make it either a G Code button or a VB button.
So for a  G Code button you would add the code you want when in the screen editor, that would be m123.
When you push that button in Mach it will do the m123 macro and do exactly as above.

If you had set the button as a VB button then you would need to add the VB to the button once back in Mach, Operator menu then Edit Button Script. Click the flashing button and the editor will open and you enter the script.
You could have the above script if you wanted or you could simply have
Code"m123"
either will work.


Now if you want an external toggle  button you would use the macro pump to monitor the input your switch is connected to and either have it run the script from within the macropump or have it do the Code"m123"


If you do not want it to be a toggle then you could do things via two macros. One to switch on, one to switch off.


Hood


























Re: Normally Open VS Normally Closed
« Reply #23 on: August 13, 2016, 03:55:04 PM »
I follow you completely.

Thanks for the quick overview as the soft buttons and actual hard switches are next on my list.  Thanks, this will be a good jump start.

Offline Hood

*
  •  25,835 25,835
  • Carnoustie, Scotland
    • View Profile
Re: Normally Open VS Normally Closed
« Reply #24 on: August 13, 2016, 04:42:28 PM »
Ok was in a bit of a rush when I wrote that and see that would not be the best for a vacuum table if wanting to operate from G code.

So what you would do is have two custom macros, one to switch on, the other off.

So say m123.m1s for On, that would have

SetOutBit(90,0)
SetUserLED(1111,1)


Now m124.m1s for off, it would have

ReSetOutBit(90,0)
SetUserLED(1111,0)


In either macro there is no need to look at the UserLED state as you are switching on or off from the macros regardless and it doesn't matter if it is already on and you call m123  or already off and you call M124.


Now say you wanted to check from the M6 macro and turn it off if on then all you would do is have the VB to look at the LED state and if On then turn the output off and set the LED off, so

If GetUserLED(1111) = 1 Then
ResetOutBit(90,0)
SetUserLed(1111,0)
End If

Then if further on in the macro you wanted it switched back on you would have

If GetUserLED(1111) = 0 Then
SetOutBit(90,0)
SetUserLED(1111,1)
End If


Now for the screen button, you could have two separate buttons and set them as G Code buttons and have code "m123" in the On button and Code"m124" in the off button, same with panel buttons.
However with the buttons themselves it will likely make more sense to have them toggle buttons so you would just set the screen  button as  a VB button and have the code in the previous post in the button.
Same with the macropump looking at the physical buttons input.


So basically the problem you encountered with the coolant was because you had it set in Mach as Machs coolant where the vacuum is set via VB in all cases, so nothing will force it back on if switched off via VB and vice versa. The only important thing you need to remember is that from any VB you wish to control it from that you also remember to set the state of the UserLED accordingly.


Hood
Re: Normally Open VS Normally Closed
« Reply #25 on: August 13, 2016, 04:57:22 PM »
Exactly.

Heres another funny issue.  So coolant is enabled in Mach.  Output 2 on CsLabs.  M8 and M9 control it.

I edited the M8 script and Put in this.
Message "Coolant working"

Simple.  From the Script Editor, I run it and the message "Coolant working" shows on screen and the coolant turns on.  Note I did not have code in M8 to actually turn on the output.  Mach took care of that secretly (and continuously).  Now, I enter M8 in the mdi, coolant comes on but it does not show the message "Coolant working" which means its not running the M8 macro.

My guess, Mach ignored the M8 macro and focused on turning on and off the correct output because it was configured to handle coolant secretly. 

If Mach is doing this, the moral of story is be very careful with outputs that you told Mach to handle.  All those extra inputs and outputs are really unknown to mach and can be controlled.  Until someone tells me I screwed up on this test, I will de-configure coolant and just handle this with M8 script.  Will also help with communication overhead as mach won't be turning on coolant every 100ms or so.
Re: Normally Open VS Normally Closed
« Reply #26 on: August 13, 2016, 05:22:03 PM »
As Stirling stated in another post.
Tis What Tis....
Re: Normally Open VS Normally Closed
« Reply #27 on: August 13, 2016, 05:24:21 PM »
Damn Hood,
I just crossed the .1 of 1% of your total post count.  Yeah baby....

Offline Hood

*
  •  25,835 25,835
  • Carnoustie, Scotland
    • View Profile
Re: Normally Open VS Normally Closed
« Reply #28 on: August 13, 2016, 05:25:06 PM »
I think the M7, M8 and M9 are the real oddball ones simply because it is totally internal to Mach and they have no macros. Things like M3, M4, M5, all have macros and you can customise them to suit.

As an example, on the big lathe I had a 7.5/11 Kw spindle motor which was controlled via a gearbox which had electromagnetic clutches. I controlled these clutches via my PLC and I altered the M3, M4, M5 and Spindle Speed macros in Mach to suit my setup. For example if the  spindle was commanded to switch on and go to 2000rpm I would have the macros step the spindle speed up in increments, changing the clutches as it went, if wanting to go back to zero then the macros  would look at the current rpm and then change the clutches in steps so that I slowed down in a couple of stages rather than just an abrupt stop, same going from a low RPM to a high and vice versa.

Here is a video showing the spindle ramping up at the start  and down at the end via the clutches, that was the days before I had the servo spindle on it.
https://www.youtube.com/watch?v=JvSh6j8x4Gc

Ha ha actually seeing that video is weird as the lathe has changed so much since that initial run, it was via the parallel port so the rapids were, well, not very rapid and the turret had to index one tool at a time and could only go one way, the one I made can index to the next called tool and will take the shortest route.
 Still it was a thrill for me to get it running :)


Hood

Offline Hood

*
  •  25,835 25,835
  • Carnoustie, Scotland
    • View Profile
Re: Normally Open VS Normally Closed
« Reply #29 on: August 13, 2016, 05:29:39 PM »
Damn Hood,
I just crossed the .1 of 1% of your total post count.  Yeah baby....

I have been posting here since the forum started (previously was Yahoo only) so have had a long time to post , and learn Mach, think it was still Mach2 back in these days :D


Hood