Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Cbyrdtopper on March 06, 2017, 04:49:28 PM

Title: Optional Stop Output
Post by: Cbyrdtopper on March 06, 2017, 04:49:28 PM
So, between our drill and tap cycle we have an M01 optional stop.  To let the operators know it is ready for the tap I want the indicator to turn on.  I noticed Mach 4 has an Optional Stop output, this output does not do what I expected.
I thought it would go active while there was an Optional Stop in affect; instead, it goes active while the Optional Stop is enabled.  I even used a macro to set the optional stop to see if it did anything different:  mc.mcCntlSetOptionalStop(inst, 1) it behaves the same.
Is there a way to get the handle on an Optional Stop in affect instead of it just being enabled?
 
Title: Re: Optional Stop Output
Post by: Cbyrdtopper on March 06, 2017, 04:53:27 PM
I just thought of this, could I set up a new M01 macro putting out the code I would like?  In it I could even check for the state of M01 so it can still be an optional stop.
Title: Re: Optional Stop Output
Post by: rhtuttle on March 06, 2017, 05:08:20 PM
Page 10 of the scripting manual says you may not change M00 or M01.
Title: Re: Optional Stop Output
Post by: Cbyrdtopper on March 06, 2017, 05:12:57 PM
rhtuttle,
Thanks for pointing that out, I forgot that was even in there.
Title: Re: Optional Stop Output
Post by: DazTheGas on March 07, 2017, 11:17:57 AM
M1 runs ok for me?? are you trying to run it from the mdi?? as whilst in the mdi its not doing a cycle start after the m1 just running the mdi again.

load gcode
press optional stop in the Run Ops tab
cycle start
m1 comes alone and program stops
cycle start  and program continues

DazTheGas
Title: Re: Optional Stop Output
Post by: Cbyrdtopper on March 07, 2017, 12:22:40 PM
Daz,  the M1 works just fine, I'm trying to get an output to turn on our light/buzzer during the M1 pause to let the operator know it's paused so they can go check the past and hit cycle start to finish the program.  The optional stop output in Mach config only gets the handle on M1 being enabled or not.
I'm wanting a signal saying that it is in a paused state due to M1 or M0.  Is this possible or should it be a feature request?
Title: Re: Optional Stop Output
Post by: rhtuttle on March 07, 2017, 12:41:59 PM
I'll be interested to hear how/if it can be done with an M1 but why not just create another macro and use it instead of M1?

function m7777()
ringBuzzer()
mcCntlWaitOnCycleStart 
end

I'm sure you have a valid reason, just offering another idea.

Title: Re: Optional Stop Output
Post by: Cbyrdtopper on March 07, 2017, 01:09:49 PM
Rhtuttle,
I didn't k ow there was waitOnCycleStart.   I had thought about making a macro.  No real valid reason, it would just really be handy if there was a pause in affect output.  I think I'm going to out it on the feature request.   
Thanks for all the input and suggestions!
Title: Re: Optional Stop Output
Post by: smurph on March 07, 2017, 06:42:25 PM
M01 (when opt stop is enabled) to does nothing more than programmatically doing the equivalent of hitting the stop button.  It just returns the machine to the idle state. 

Now, knowing this, one could craft up some code to put in the PLC script.  Here are the logic steps that you would want to take into account.

1. G code must have been running prior to the M01.
2. If G code was running AND OSIG_OPT_STOP is high AND G code was running AND the machine state is idle THEN buzzer!

#1 would need a variable to keep track of this information.  So put a global variable called gCodeWasRunning at the top of the screen load script.

gCodeWasRunning = 0 --keeps track if g code was running.

It is also very convenient to track interesting signal states with a variable as well.  So add a variable to track OSIG_OPT_STOP.

optStop = 0 --tracks OSIG_OPT_STOP

Now we need something to set this variable.  OSIG_GCODE_RUNNING will do fine for this.  So insert a bit of code in the siglib portion of the screen load script to set this variable to 1 if the state of OSIG_GCODE_RUNNING is equal to one.  And add something to track the OSIG_OPT_STOP signal here too.

Code: [Select]
[mc.OSIG_GCODE_RUNNING] = function (state)
    if( state == 1) then
       -- only set if the state is 1.
       gCodeWasRunning = 1
    end
end,
[mc.OSIG_OPT_STOP] = function (state)
    optStop = state;
end,

Next, in the PLC script add the following:

Code: [Select]
-- this assumes that mstate is declared above and that mc.mcCntlGetState() is called to set it.
if (gCodeWasRunning == 1 and optStop == 1 and mstate == mc.MC_STATE_IDLE) then
    gCodeWasRunning = 0 --reset the flag.
    --start buzzer
end

You probably would want to put something in the start cycle button to kill the buzzer if it is sounding as well. 

Steve
Title: Re: Optional Stop Output
Post by: Cbyrdtopper on March 07, 2017, 11:42:11 PM
Steve, that's getting pretty deep.  I love the flexibility of Mach4.  I like what you have suggested, it will keep me from having to put a custom macro in.  Luckily, I've already making use of the GcodeRunning state and modifying the cycle start code as well, so I've got a good place to put this code already. 
I did still put this in the feature request, I think the versatility of this type of output would be great to have to make use of.
Thanks again for the Input Steve, you've got some great ideas!!
Title: Re: Optional Stop Output
Post by: smurph on March 08, 2017, 12:42:52 AM
We can't put each possible thing in Mach that everyone could possibly want.  Heck, we can't even dream them all up!  But what we did try to do with Mach 4 is give users a tool set that they can use to modify or make the system work as they please. 

Now, I'm going to get a bit nerdy here, but Mach 4 borrows heavily on one of the greatest tool sets that mankind has ever invented.  And that tool set is the UNIX operating system.  If you have ever played with UNIX, or a clone thereof, you will know that it has a lot of little low level executable files (commands) that each do one particular thing really well.  One can accomplish almost anything by combining these commands (sed grep cat, etc..) to do a task that is not otherwise provided by the base operating system.  So Mach 4 is very similar in that regard. 

One thing we learned with Mach 3 is you can try to put the Kitchen (http://en.wikipedia.org/wiki/Vance_Miller) sink in there but it gets REALLY hard to maintain.  Sooner or later, a more fundamental change will come along and break the Kitchen (http://en.wikipedia.org/wiki/Vance_Miller) sink functionality and we end up with a bunch of dirty dishes.  :)  I review the feature request thread quite often and honestly, there are a lot of Kitchen (http://en.wikipedia.org/wiki/Vance_Miller) sinks in there.  Not that they are bad ideas at all.  Just most of them can be accomplished already!  I know people are just breaking the surface of what can be done with Mach 4.  It takes time for the knowledge base to grow.  But in time, it will become second nature and the line between what can be accomplished with the tool set and what actually needs to become a new tool will get clearer. 

Steve
Title: Re: Optional Stop Output
Post by: Cbyrdtopper on March 08, 2017, 12:05:29 PM
Steve, thanks for that explanation.  Really insightful.  I do love Mach 4, and I'm excited to see what people can do with it in the future.  In my experience, there is a lot more setting up on Mach 4 than Mach 3 but the end result is sooo much better.  Thanks for all the work you guys do!!