I don't pretend to be a programmer all that often anymore, but this was needed I believe. This will set Soft Limits off before a RefAllHome(). And after the RefAllHome() is done set it back on so you don't forget to do it.
create a mcSoftLimits.lua in your modules directory with the following
-- mcSoftLimits.lua
-- local CDFuncs = {}
function autoSoftLimitsToggle (togglevalue)
local mInst = 0
local rc = 0
local inst = mc.mcGetInstance (mInst)
-- mc.mcCntlSetLastError(inst, string.format('In Auto Soft Limits Toggle = ' .. togglevalue));
for i=0, 11 do
if mc.mcAxisIsEnabled (inst,i) == 1
then
mc.mcSoftLimitSetState (inst,i,togglevalue)
end
end
end -- of mcSoftLimits.lua
Now in your screenset load script. This script is only run once, and we need an initial value for the variable.
machSoftLimits = -1 -- add this near the top of the script
Now find RefAllHome() and add the two lines to it.
function RefAllHome()
autoSoftLimitsToggle(0) -- ****** ADD we want to make sure and turn this off at this point.
mc.mcAxisDerefAll(inst) --Just to turn off all ref leds
mc.mcAxisHomeAll(inst)
coroutine.yield() --yield coroutine so we can do the following after motion stops
----See ref all home button and plc script for coroutine.create and coroutine.resume
wx.wxMessageBox('Referencing is complete')
machSoftLimits = 1 -- ******* ADD this line to your RefAllHome() function
end
Add this in the section that loads required modules.
package.loaded.SoftLimits = nil
sl = require "mcSoftLimits"
Finally at the bottom of your PLC script add the following
if ((machSoftLimits == 1) and (machState == mc.MC_STATE_IDLE)) then -- after we finish the toggle, set machSoftLimits to 0 so we don't come back here until needed.
autoSoftLimitsToggle(1);
machSoftLimits = 0; -- RefAllHome() set's this for us when we need it
end
if (machSoftLimits == -1) then -- Don't care what the state of Mach4 is here. We just are disabling them for first run.
autoSoftLimitsToggle(0);
machSoftLimits = 0;
end