Hello Guest it is April 25, 2024, 06:38:25 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - MrPuhur

Pages: 1
1
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:
Code: [Select]
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):
Code: [Select]
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.

2
Mach4 General Discussion / Lua script detect when the cycle is running
« on: February 12, 2018, 01:27:44 PM »
I have an M6 lua script set up to automatically do everything required to switch tools on a 2 spindle (main spindle + drill spindle) machine, and it has got to the point of being rather complex and therefore hard to debug and even harder to keep reliable.

There's one thing that 's been coming up recently, which is that, if the machine is disabled or the G-code cycle stopped during M6, the script just keeps on being executed, save the G-code calls from within the lua script through mc.mcCntlGcodeExecuteWait(). This results in the machine's movement stopping as expected, but then signals being set as if it wasn't disabled or stopped at all possibly causing tools to fall out of the spindle among others. I do understand that this is a requirement for some scripts, such as ones meant to act to turn off spindles after a disable command, but for M6 this is not the case.

I have somewhat managed to fix it by calling a function to check if the machine is enabled each time a signal change occurs in the code, so it only proceeds if the function returns true. The function is as follows:

function toolchange_machine_enabled()
    local inst = mc.mcGetInstance()
    local hsig=mc.mcSignalGetHandle(inst, mc.OSIG_MACHINE_ENABLED)
    local val=mc.mcSignalGetState(hsig)
    if val==1 then
        return true
    else
        return false
    end
end


(It's intentionally non-compact and readable.)
I'd like to hear from you suggestions to make it better so that it would return true only if mc.mcCntlGcodeExecuteWait() would execute. OR, if there's another way of solving the problem that is more correct, I'd be happy to hear on those.

Pages: 1