Ok this doesn't seem totally correct to me. What do you think?
I'm using the limit switches on my Tool Changer to verify that the tool change has completed correctly, those inputs run X101-X106.
I basically took your tool change program and changed it to match what I think is correct.
--Mori Seiki SL-1 ATC
function m6()
local inst = mc.mcGetInstance()
local Requested = mc.mcToolGetSelected(inst)
local Current = mc.mcToolGetCurrent(inst)
if requested == 1 then
local ToolOutput = mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT01) –Y101
end
if requested == 2 then
local ToolOutput = mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT02) –Y102
end
if requested == 3 then
local ToolOutput = mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT03) –Y103
end
if requested == 4 then
local ToolOutput = mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT04) –Y104
end
if requested == 5 then
local ToolOutput = mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT05) –Y105
end
if requested == 6 then
local ToolOutput = mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT06) –Y106
end
if requested == 7 then
local ToolOutput = mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT07) –Y107
end
if requested == 8 then
local ToolOutput = mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT08) –Y108
end
if Requested == Current then
mc.mcCntlSetLastError(inst, "Current tool == Requested tool so there is nothing to do")
else
--Tell the Click to change to requested tool.
local Y101 = mc.mcRegGetHandle(inst,"Clcik PLC/Requested Tool")
mc.mcRegSetValue(Y101,Requested)
end
--Tell the Click to change to requested tool.
local Y102 = mc.mcRegGetHandle(inst,"Clcik PLC/Requested Tool")
mc.mcRegSetValue(Y102,Requested)
end
--Tell the Click to change to requested tool.
local Y103 = mc.mcRegGetHandle(inst,"Clcik PLC/Requested Tool")
mc.mcRegSetValue(Y103,Requested)
end
--Tell the Click to change to requested tool.
local Y104 = mc.mcRegGetHandle(inst,"Clcik PLC/Requested Tool")
mc.mcRegSetValue(Y104,Requested)
end
--Tell the Click to change to requested tool.
local Y105 = mc.mcRegGetHandle(inst,"Clcik PLC/Requested Tool")
mc.mcRegSetValue(Y105,Requested)
end
--Tell the Click to change to requested tool.
local Y106 = mc.mcRegGetHandle(inst,"Clcik PLC/Requested Tool")
mc.mcRegSetValue(Y106,Requested)
end
--Tell the Click to change to requested tool.
local Y107 = mc.mcRegGetHandle(inst,"Clcik PLC/Requested Tool")
mc.mcRegSetValue(Y107,Requested)
end
--Tell the Click to change to requested tool.
local Y108 = mc.mcRegGetHandle(inst,"Clcik PLC/Requested Tool")
mc.mcRegSetValue(Y108,Requested)
end
--Send signal to the Click to start the tool change.
mc.mcSignalSetState(ToolChange,1) –Y101
wx.wxMilliSleep(1000)
mc.mcSignalSetState(ToolChange,0) –Y101
end
--Send signal to the Click to start the tool change.
mc.mcSignalSetState(ToolChange,1) –Y102
wx.wxMilliSleep(1000)
mc.mcSignalSetState(ToolChange,0) –Y102
end
--Send signal to the Click to start the tool change.
mc.mcSignalSetState(ToolChange,1) –Y103
wx.wxMilliSleep(1000)
mc.mcSignalSetState(ToolChange,0) –Y103
end
--Send signal to the Click to start the tool change.
mc.mcSignalSetState(ToolChange,1) –Y104
wx.wxMilliSleep(1000)
mc.mcSignalSetState(ToolChange,0) –Y104
end
--Send signal to the Click to start the tool change.
mc.mcSignalSetState(ToolChange,1) –Y105
wx.wxMilliSleep(1000)
mc.mcSignalSetState(ToolChange,0) –Y105
end
--Send signal to the Click to start the tool change.
mc.mcSignalSetState(ToolChange,1) –Y106
wx.wxMilliSleep(1000)
mc.mcSignalSetState(ToolChange,0) –Y106
end
--Send signal to the Click to start the tool change.
mc.mcSignalSetState(ToolChange,1) –Y107
wx.wxMilliSleep(1000)
mc.mcSignalSetState(ToolChange,0) –Y107
end
--Send signal to the Click to start the tool change.
mc.mcSignalSetState(ToolChange,1) –Y108
wx.wxMilliSleep(1000)
mc.mcSignalSetState(ToolChange,0) –Y108
end
--Wait for the signal from the CLick.
mc.mcCntlSetLastError(inst, "Wait for Click to complete tool change.")
If requested == 1 then
rc = mc.mcSignalWait(inst, mc.ISIG_INPUT03, mc.ISIG_INPUT04, mc.ISIG_INPUT05, mc.ISIG_INPUT06, mc.WAIT_MODE_HIGH, 20) --X103, X104, X105, X106
end
If requested == 2 then
rc = mc.mcSignalWait(inst, mc.ISIG_INPUT01, mc.ISIG_INPUT04, mc.ISIG_INPUT05, mc.ISIG_INPUT06, mc.WAIT_MODE_HIGH, 20) --X101, X104, X105, X106
end
If requested == 3 then
rc = mc.mcSignalWait(inst, mc.ISIG_INPUT01, mc.ISIG_INPUT02, mc.ISIG_INPUT05, mc.ISIG_INPUT06, mc.WAIT_MODE_HIGH, 20) --X101, X102, X105, X106
end
If requested == 4 then
rc = mc.mcSignalWait(inst, mc.ISIG_INPUT01, mc.ISIG_INPUT03, mc.ISIG_INPUT05, mc.ISIG_INPUT06, mc.WAIT_MODE_HIGH, 20) --X101, X103, X105, X106
end
If requested == 5 then
rc = mc.mcSignalWait(inst, mc.ISIG_INPUT02, mc.ISIG_INPUT04, mc.ISIG_INPUT05, mc.ISIG_INPUT06, mc.WAIT_MODE_HIGH, 20) --X102, X104, X105, X106
end
If requested == 6 then
rc = mc.mcSignalWait(inst, mc.ISIG_INPUT01, mc.ISIG_INPUT03, mc.ISIG_INPUT04, mc.ISIG_INPUT06, mc.WAIT_MODE_HIGH, 20) --X101, X103, X104, X106
end
If requested == 7 then
rc = mc.mcSignalWait(inst, mc.ISIG_INPUT01, mc.ISIG_INPUT02, mc.ISIG_INPUT04, mc.ISIG_INPUT06, mc.WAIT_MODE_HIGH, 20) --X101, X102, X104, X106
end
If requested == 8 then
rc = mc.mcSignalWait(inst, mc.ISIG_INPUT02, mc.ISIG_INPUT03, mc.ISIG_INPUT05, mc.ISIG_INPUT06, mc.WAIT_MODE_HIGH, 20) --X102, X103, X105, X106
end
--Error check. If the Click took too long. Alarm out Mach4.
if (rc~= 0) then
wx.wxMessageBox("The Click did not complete the tool change in time. Check for malfunction.")
local Alarm = mc.mcSignalGetHandle(inst,mc.OSIG_ALARM)
mc.mcSignalSetState(Alarm,1)
CycleStop()
else
mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(Requested))
mc.mcToolSetCurrent(inst, Requested)
mc.mcCntlSetLastError(inst, "Tool Change Complete.")
end
end--Request == Current
end --m6
if (mc.mcInEditor() == 1) then
m6()
end