Hello Guest it is August 12, 2020, 09:23:30 PM

Author Topic: M6 ATC macro help  (Read 1336 times)

0 Members and 1 Guest are viewing this topic.

M6 ATC macro help
« on: February 04, 2017, 09:27:41 AM »
I have a working m6 macro for an ATC on a self built 6 axis router (5A with twin Y tables).

I have a moving rack on slides run by an air cylinder to move the rack into and out of the tool change area.  I use a repeat-until loop after turning on the output to wait until the sensor at the end of cylinder stroke goes on.  what I want to do is add some kind of timer to the loop so if the rack gets jammed it won't sit there forever waiting for the sensor to go on.  I can't figure out the lua timer function.  I added a counter to the loop, but trying to figure out the count value that works is tough to do, and I have 6 or so of these loops all needing different time values, would be better if I could use a timer.  Maybe there is another structure I could use instead of repeat-until.  Not really a programmer, just good enough to fumble through examples to figure out how to get it to work.

here is what lua script looks like with the counter:

local OUT1 = mc.mcSignalGetHandle(inst, OSIG_OUTPUT1)
local IN7 = mc.mcSignalGetHandle(inst, ISIG_INPUT7)
local a=0

mc.mcSignalSetState(OUT1,1)

repeat
   local mc.mcSignalGetState(IN7)
   a=a+1
until IN7 == 1 or a==100000000

if a==100000000 then
  mc.mcCntlEStop(inst)
  mc.mcSetLastError(inst, "toolrack jammed")
end
Re: M6 ATC macro help
« Reply #1 on: November 08, 2017, 07:33:18 AM »
Sorry to bump the old post, but have you made any progress?

I'm also looking to set an output and then wait for the corresponding input to change, but with a timeout.

My current plan is to use a G04 for a few seconds to give the drawbar a chance to move and then check the input and either continue the scrip or throw an error.

A timer would be neater though.


Owen.
Re: M6 ATC macro help
« Reply #2 on: November 08, 2017, 01:03:27 PM »
Hi,
that is Lua code, is that what you intended?

If that is the case this post would ideally be in the Mach4 Discussion.

This API call was pointed out to me when working on another matter:
Code: [Select]
rc = mc.mcSignalWait(
number mInst,
number sigId,
number waitMode,
number timeoutSecs);
I stumbled a bit, it turns out the valid range of input signals is 0-63, ie  Input#1 thru Input#64. With a suitable test of the return code a timeout fault
can be indicated/acted on. Note that you don't even have to get the signal handle. A very useful API call.

Craig
My wife left with my best friend...
     and I miss him!
Re: M6 ATC macro help
« Reply #3 on: November 09, 2017, 01:57:58 AM »
Hi,
I coded this, called it m150 to avoid screwing up my m6:
Code: [Select]
function m150();
local inst=mc.mcGetInstance();
local OUT1 = mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT1);
mc.mcSignalSetState(OUT1,1)
local retcode=mc.mcSignalWait(inst,mc.ISIG_INPUT7,mc.WAIT_MODE_HIGH,5);
    if retcode==mc.MERROR_TIMED_OUT then
        mc.mcCntlEStop(inst)
        mc.mcCntlSetLastError(inst, "toolrack jammed")
    end
end
if (mc.mcInEditor() == 1) then
    m150()
end

If Input7 doesn't go high within 5 seconds it times out and Estops Mach.

Is this something like you had in mind?

Craig
My wife left with my best friend...
     and I miss him!
Re: M6 ATC macro help
« Reply #4 on: November 09, 2017, 07:57:10 AM »
Hi Craig,

That's exactly what I'm trying to do! Thanks for the code fragment!

Hopefully I'll get the tool changer up and running soon with this info.

Cheers!

Owen.