ok...two hours later but I gott'er done the way you suggested. I left all the messages for flag tracking purposes so anyone can see how the flags are changed from btn script / PLC scan & global function calls / and screen load up script.
Attached is the StatusList history report. You can see how the PLC, GUI, and global variables and functions interact and will not execute unless conditions are met (as if there are three different states with interlacing conditional statements that are nested to synchronize gCode, Lua, GUI, and signal events. Remember, this is only "a" way to do this. There are many more ways to accomplish the same endstate. Add to it, subtract whatever you like. I'm tired. forgot the following:" for i=0, 11 do if mc.mcAxisIsHoming(inst, i) then mc.mcSoftLimitSetState(inst, i, 0) end end" and mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_SOFTLIMITS_ON),0) signal is turned off while homing in case you deref your axes and need to re-reference. G'nite.
Task: auto set soft limits after homing for all enabled axes
Conditions: set soft limit state to on 'after' referencing all axes is complete, continue to use soft limit button toggle to turn on/off soft limits manually
Standard: use lua scripting in a emulated PLC environment
Assumptions: you must have soft enable checked for your axes in mach config, homing order: Zaxis = 1, Xaxis = 2, Yaxis = 2
CONOPS:
flagON SignalOFF = SignalON
1 0 1
flagOFF SignalON = SignalOFF
1 1 0
flagOFF SignalOFF = SignalON
1 0 1
Button script: "btnSoftLimits"
--take the SoftLimits Toggle option off; we will code our own toggle button
--Left Down Script
flagSoftLimitsOff = 1
Button script: "btnRefAll"
local inst = mc.mcGetInstance();
mc.mcAxisHomeAll(inst);
flagSoftLimitsOn = 1
Screen Load Up script:
--Define global variables.
flagSoftLimitsOn = 0
flagSoftLimitsOff = 0
--Soft limits set for all referenced axes after homing.
function setMySoftLimits()
local inst = mc.mcGetInstance()
local a = 0
local b = 0
for i = 0, 11 do if mc.mcAxisIsEnabled(inst, i) == 1 then a = a + 1 end end
mc.mcCntlSetLastError (inst, tostring(a) .." axes enabled.")
for i = 0, a do if mc.mcAxisIsHomed (inst, i) == 1 then b = b + 1 end end
mc.mcCntlSetLastError (inst, tostring(b) .." axes homed.")
if flagSoftLimitsOn == 1 then
if a == b and b ~= 0 then
for i = 0, b-1 do
mc.mcSoftLimitSetState(inst, i, 1)
mc.mcCntlSetLastError (inst, "Axis " ..tostring(i) .." soft limit value is " ..tostring(mc.mcSoftLimitGetState(inst, i)))
end
flagSoftLimitsOn = 0
end
elseif flagSoftLimitsOff == 1 then
for i = 0, b-1 do
mc.mcSoftLimitSetState(inst, i, 0)
mc.mcCntlSetLastError (inst, "Axis " ..tostring(i) .." soft limit value is " ..tostring(mc.mcSoftLimitGetState(inst, i)))
end
flagSoftLimitsOff = 0
end
end
PLC script:
--SoftLimts scan
if machState == mc.MC_STATE_IDLE and mc.mcSignalGetState(mc.mcSignalGetHandle(inst, mc.OSIG_SOFTLIMITS_ON)) == 0 and flagSoftLimitsOn == 1 then
mc.mcCntlSetLastError (inst, "(PLC send, btnRefAllHome) flagSoftLimitsOn = " ..tostring(flagSoftLimitsOn) .." flagSoftLimitsOff = " ..tostring(flagSoftLimitsOff))
setMySoftLimits()
mc.mcCntlSetLastError (inst, "(PLC return) flagSoftLimitsOn = " ..tostring(flagSoftLimitsOn) .." flagSoftLimitsOff = " ..tostring(flagSoftLimitsOff))
elseif machState == mc.MC_STATE_IDLE and mc.mcSignalGetState(mc.mcSignalGetHandle(inst, mc.OSIG_SOFTLIMITS_ON)) == 1 and flagSoftLimitsOff == 1 then
mc.mcCntlSetLastError (inst, "(PLC send, btnSoftLimits toggle off) flagSoftLimitsOn = " ..tostring(flagSoftLimitsOn) .." flagSoftLimitsOff = " ..tostring(flagSoftLimitsOff))
setMySoftLimits()
mc.mcCntlSetLastError (inst, "(PLC return) flagSoftLimitsOn = " ..tostring(flagSoftLimitsOn) .." flagSoftLimitsOff = " ..tostring(flagSoftLimitsOff))
elseif machState == mc.MC_STATE_IDLE and mc.mcSignalGetState(mc.mcSignalGetHandle(inst, mc.OSIG_SOFTLIMITS_ON)) == 0 and flagSoftLimitsOff == 1 then
flagSoftLimitsOn = 1
flagSoftLimitsOff = 0
mc.mcCntlSetLastError (inst, "(PLC send, btnSoftLimits toggle on) flagSoftLimitsON = " ..tostring(flagSoftLimitsOn) .." flagSoftLimitsOff = " ..tostring(flagSoftLimitsOff))
setMySoftLimits()
mc.mcCntlSetLastError (inst, "(PLC return) flagSoftLimitsOn = " ..tostring(flagSoftLimitsOn) .." flagSoftLimitsOff = " ..tostring(flagSoftLimitsOff))
end
--j