I have a complex M6 script for a mill. The script moves over to the tool rack and releases the current tool, then moves over to the requested tool and grabs it.
Sometimes the script just seems to jump over the "move" part of itself - it doesn't execute G-code, but does set (some) outputs as if nothing had happened. This is weird, as I do actually check the return value of all mcCntlGcodeExecuteWait() statements I issue and essentially halt if it's anything but 0.
Here's the G-code execution wrapper function I use:
function toolchange_callGcode(gcode)
if toolchange_is_action_allowed()==true then
local inst = mc.mcGetInstance()
mc.mcCntlSetLastError(inst, gcode)
--wait for the machine to be
local rc = mc.mcCntlGcodeExecuteWait(inst, gcode)
if rc ~=0 then
toolchange_stop_safely()
mc.mcCntlSetLastError(inst, "Something went wrong with executing G-code from within M6. The machine was disable for safety. Error state: "..rc)
end
end
end
toolchange_stop_safely() is a function that sets a global variable toolchange_action_allowed_flag to false. I read that flag in toolchange_is_action_allowed(), before any calls that impact the machine (like switching output signals or executing G-code, as shown above):
function toolchange_is_action_allowed()
local inst = mc.mcGetInstance()
if (toolchange_action_allowed_flag==true and toolchange_machine_enabled()==true) then
--mc.mcCntlSetLastError(inst, "Action allowed")
return true
else
--mc.mcCntlSetLastError(inst, "Action not allowed")
return false
end
end
I've had a similar issue in the past (
https://www.machsupport.com/forum/index.php?topic=36577.20), where the script didn't stop execution after a "stop" or "disable" but that behaviour was completely deterministic and always happened. This was solved and the complete solution is in the last post.
The current issue, however, only happens rarely, both in MDI and from G-code programs, and Mach seems to get stuck in this state. It keeps jumping over the G-code calls until I restart the whole machine (including the DSMPC motion controller). Mach4 is version 4.2.0.2872, which is quite old. Here's the whole M6 script, for which I'm happy to provide additional explanations for:
https://pastebin.com/244jsUyR.
Are there any other errors I should check for, or am I missing something basic? I'd also be thankful for any other suggestions for making my script error-proof.