Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Zuxztah on September 15, 2018, 05:28:58 AM

Title: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: Zuxztah on September 15, 2018, 05:28:58 AM
Hello! I´ve found a guide online about how to use a Pendant in mach 4 by Shane | Engineer, added the code in screen load script and restarted mach4, has not plugged in and tested since I do not have an MPG / Pendant yet. but will build one soon.

The problem is that it removes on screen jog functions and Ref all home button? They get grayed out? or loose i´ts clickability and I still want to keep those features even if a pendant is installed? maybe if there is a Enable button for the pendant that deactivates jog on screen? or if the pendant only works when a axis is selected and then it deactivates the jog on screen features?

so if the pendant is not enabled the jog functions in mach 4 must be usable, and I don't care if the jog on-screen functions never get disabled, as long as both pendant and jog on screen works?

The Code below is added to the bottom of the screen load script:


--------------------------------------
-- MPG Code --
--------------------------------------
SigLib = {
    [mc.ISIG_INPUT10] = function (state)
        RunPendant()
    end,
    [mc.ISIG_INPUT11] = function (state)
        RunPendant()
    end,
    [mc.ISIG_INPUT12] = function (state)
        RunPendant()
    end,
    [mc.ISIG_INPUT13] = function (state)
        RunPendant()
    end,
    [mc.ISIG_INPUT14] = function (state)
        RunPendant()
    end,
    [mc.ISIG_INPUT15] = function (state)
        RunPendant()
    end,
    [mc.ISIG_INPUT16] = function (state)
        RunPendant()
    end,
    [mc.ISIG_INPUT17] = function (state)
        RunPendant()
    end
}
---------------------------------------------------------------
-- Pendant function.
---------------------------------------------------------------
function RunPendant()
    local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT10) -- Is mapped to Port 2 Pin 4 *X Selection
    local XSelection, rc = mc.mcSignalGetState(hSig)
    local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT11) -- Is mapped to Port 2 Pin 5 *Y Selection
    local YSelection, rc = mc.mcSignalGetState(hSig)
    local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT12) -- Is mapped to Port 2 Pin 6 *Z Selection
    local ZSelection, rc = mc.mcSignalGetState(hSig)
    local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT13) -- Is mapped to Port 2 Pin 7 *A Selection
    local ASelection, rc = mc.mcSignalGetState(hSig)
    local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT14) -- Is mapped to Port 2 Pin 8 *.001 Selection
    local Step001, rc = mc.mcSignalGetState(hSig)
    local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT15) -- Is mapped to Port 2 Pin 9 *.010 Selection
    local Step010, rc = mc.mcSignalGetState(hSig)
    local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT16) -- Is mapped to Port 2 Pin 10 *.100 Selection
    local Step100, rc = mc.mcSignalGetState(hSig)
    local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT17) -- Is mapped to Port 2 Pin 15 *Estop
    local PenStop, rc = mc.mcSignalGetState(hSig)
    local PenJogOn, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT10)-- Is mapped to Port 2 Pin 1 *Jog on LED

    if XSelection == 1 then
        mc.mcMpgSetAxis(inst, 0, 0) --X Axis
        mc.mcCntlSetLastError(inst, "X Selected")
        mc.mcSignalSetState(PenJogOn, 1)
    elseif YSelection == 1 then
        mc.mcMpgSetAxis(inst, 0, 1) --Y Axis
        mc.mcCntlSetLastError(inst, "Y Selected")
        mc.mcSignalSetState(PenJogOn, 1)
    elseif ZSelection == 1 then
        mc.mcMpgSetAxis(inst, 0, 2) --Z Axis
        mc.mcCntlSetLastError(inst, "Z Selected")
        mc.mcSignalSetState(PenJogOn, 1)
    elseif ASelection == 1 then
        mc.mcMpgSetAxis(inst, 0, 3) --A Axis
        mc.mcCntlSetLastError(inst, "A Selected")
        mc.mcSignalSetState(PenJogOn, 1)
    else
        mc.mcMpgSetAxis(inst, 0, -1) --No Axis
        mc.mcCntlSetLastError(inst, "No Axis Selected")
        mc.mcSignalSetState(PenJogOn, 0)
    end

    if Step001 == 1 then
        mc.mcMpgSetInc(inst, 0, .001)
    elseif Step010 == 1 then
        mc.mcMpgSetInc(inst, 0, .010)
    elseif Step100 == 1 then
        mc.mcMpgSetInc(inst, 0, .100)
    end

    if PenStop == 1 then
        mc.mcCntlEStop(inst)
    end
end
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: Zuxztah on September 20, 2018, 02:46:23 PM
No one who has any knowledge or info in the area?
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: Cbyrdtopper on September 20, 2018, 04:36:48 PM
I put this code into Mach4 on my laptop at home, it is just running the SIM but I had no issues with it disabling my jog functions or any buttons for that matter; I am unable to duplicate your issues.

I have MPGs on a mill and a lathe here in the shop.  When the MPG is set to an active state for an axis I still have keyboard and button click jogging available for all axis.
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: Zuxztah on September 20, 2018, 05:07:13 PM
Ohh, Then I’m the only one who’s experiencing this problem at the moment, I can’t remember what is changed with my button scripts or screen load script, it has been a while since anything was changed? There is a whole thread about VFD fix “machtric S800E” that will explain most of the modifications, a few clever guys helped me to sort out the code for it to work, I know that I have custom macros M3 M4 M5 for spindle funciton, and code  for E-stop and so on, I think that something that’s added in to the script interferes with the MPG code?

But what?
As explained in the first post? Everything gets grayed out and not clickable, maybe it’s the copy of “keyboard jog on” button but even when keyboard jog is active it still works to jog with on screen buttons

Sorry about my English, not the best.. understand 89% but type/talk is hard...
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: joeaverage on September 20, 2018, 05:54:43 PM
Hi Zuxtah,
could it be that the jogging functions get greyed out because Mach is still has focus on the Gcode interpreter?

Mach can jog or do Gcode, it can't do both at once.

Craig
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: Zuxztah on September 21, 2018, 12:21:49 AM
Hello Craig! I remember you from last time thinkering with the vfd programming, “machtric S800e”


Gcode interpreter? Did we charge Anything in script? Or Marcos to make Gcode interpreter to behave wrong?
When it comes to mach/programming.. i dont understand the code/function I’ve tried to learn many many times but it’s hopeless
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: joeaverage on September 21, 2018, 05:20:57 AM
Hi,

Quote
Did we charge Anything in script? Or Marcos to make Gcode interpreter to behave wrong?
No, we did not change anything along those lines.

Mach's core has a Gcode interpreter which reads Gcode from your file and it computes the toolpath from the Gcode. It sends the numeric
toolpath data to the motion controller, in your case a 57E.

Mach's core can also accept keyboard and MPG inputs and compute jog moves which it sends to the motion controller.

What Mach's core cannot do is both at the same time. If its computing and executing Gcode then certain functions, including jog functions, will be
disabled (greyed out). If you stop Mach from running Gcode its motion planner could now process jog commands and they would receive focus
which previously they had been denied.

From your description you have one motion mode active (Gcode interpreter for instance) but are expecting to be able to jog (immediate motion mode) at the
same time. Mach does not do that. Its not faulty.

Craig
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: Zuxztah on September 21, 2018, 08:49:35 AM
Ohh, I understand. So it could be the keyboard jog plugin?
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: joeaverage on September 21, 2018, 03:02:02 PM
Hi,
what do you mean?....from what you have described Mach is doing what its supposed to.

Craig
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: Zuxztah on September 21, 2018, 03:10:24 PM
The problem is that I want the on screen jog functions to be enabled when no axis is selected on the MPG/Pendant? “Mpg disabled/inactive”

Ref all home won’t work when the code is added to the screen load script at all? With or without axis selected/keyboard jog on? Is it supposed to do that?

If I choose to use a pendant, Does it permanently disable “ref all home”  fuction? No matter what? I like to reference my machine at every startup of mach,

And don’t want to do it manually every time?

Hard to explain, but you understand the dilemma?
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: joeaverage on September 21, 2018, 03:19:51 PM
Hi,
this is a list of the machine states:

Code: [Select]
mcStateCheck = {
[0] = "MC_STATE_IDLE",
[1] = "MC_STATE_HOLD",
[2] = "MC_STATE_FRUN_SUB",
[3] = "MC_STATE_MRUN_SUB",
[4] = "MC_STATE_JOG",
[5] = "MC_STATE_DRYRUN",
[6] = "MC_STATE_HOME",
[7] = "MC_STATE_CONFIG",
[100] = "MC_STATE_FRUN",
[101] = "MC_STATE_FRUN_FH",
[102] = "MC_STATE_FRUN_PROBE",
[103] = "MC_STATE_FRUN_PROBE_FH",
[104] = "MC_STATE_FRUN_THREAD",
[105] = "MC_STATE_FRUN_THREAD_FH",
[106] = "MC_STATE_FRUN_FH_JOG",
[107] = "MC_STATE_FRUN_TAP",
[108] = "MC_STATE_FRUN_MACROH",
[109] = "MC_STATE_FRUN_MACROH_JOG",
[110] = "MC_STATE_FRUN_SINGLE_BLOCK",
[111] = "MC_STATE_FRUN_RETRACT",
[112] = "MC_STATE_FRUN_HOMING",
[113] = "MC_STATE_FRUN_SINGLE_BLOCK_HOLD",
[199] = "MC_STATE_FRUN_END",
[200] = "MC_STATE_MRUN",
[201] = "MC_STATE_MRUN_FH",
[202] = "MC_STATE_MRUN_PROBE",
[203] = "MC_STATE_MRUN_PROBE_FH",
[204] = "MC_STATE_MRUN_THREAD",
[205] = "MC_STATE_MRUN_THREAD_FH",
[206] = "MC_STATE_MRUN_TAP",
[207] = "MC_STATE_MRUN_MACROH",
[208] = "MC_STATE_MRUN_MACROH_JOG",
[209] = "MC_STATE_MRUN_RETRACT",
[210] = "MC_STATE_MRUN_HOMING",
[299] = "MC_STATE_MRUN_END",
}


Before you can issue jog commands via the keyboard or MPG the machine MUST be in state "MC_STATE_IDLE" or already in state "MC_STATE_JOG".

You can use:
Code: [Select]
LUA Syntax:
mcState, rc = mc.mcCntlGetState(
MINSTANCE mInst)

To get the state of the machine prior to trying to issue any jog commands.

When RefAllHome is active, then jogging is not. When jogging is in progress RefAllHome is disabled.
Whenever the machine is idle then either the keyboard OR MPG can issue jog commands.
What is happening is your MPG is seizing control of Mach and not releasing it so other functions can run.


Have a look at Daz-the-Gaz videos on coroutines. It provides a way for an MPG to 'yield' so that other functions can run without
being blocked.

Craig
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: joeaverage on September 21, 2018, 03:24:44 PM
Hi,

http://www.machsupport.com/forum/index.php/topic,36170.msg247662.html#msg247662 (http://www.machsupport.com/forum/index.php/topic,36170.msg247662.html#msg247662)

Craig
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: Zuxztah on September 22, 2018, 01:48:35 AM
I understand why now, and this it might be the problem. but I don’t understand wich functions to edit?
when the code is added Mach won’t allow any jogging at all.

Why does it change the machine state? Or why would it block gui when the function is not called by axis select?  Maybe it’s enabled by default but before the code is added everything works great?
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: nick952 on September 29, 2018, 11:25:55 AM
Exactly the same problem here, BUT everything was fine until I moved from an earlier build of Mach4 (can't remember the build, but at least 18 months old) to the current 2.0.3804 build.

I have to turn the pendant off (Rotary axis selection switch to OFF position), then shut Mach4 down and re-start Mach4 (with hte pendant still OFF), for the Home All and Jogging functions to be active. As soon as I turn the pendant ON (by selecting an axis with the rotary switch), the Home All and Jogging functions are grayed out.

Nick.
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: Zuxztah on September 29, 2018, 11:29:36 AM
I haven’t tried a pendant, just the code, but it seems like we have the exact same problem.
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: Zuxztah on September 29, 2018, 05:45:37 PM
My Mach 4 won’t lock up the gui when code is added.. so I’m not sure if it’s a coroutine?
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: nick952 on October 11, 2018, 06:23:48 PM
I uninstalled and then re-loaded Mach4 3.0.3804. Everything now working fine again.

Nick
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: Zuxztah on October 14, 2018, 03:56:48 AM
That’s strange? Do you run a non-modified Mach 4 setup? Nothing is changed more than the ports&pins and so on? I doubt that reload would cut it for me due to custom macros and profiles “old files”  and so on. I still need to install and port all the pins for my mpg, then I’ll have a look at the things mentioned above “Coroutines” it may be that’s who’s causing the trouble,
Title: Re: Problem. How to make a generic MPG work with Mach 4 Guide,
Post by: Zuxztah on October 21, 2018, 05:10:25 AM
I’ve put the Mpg together and plugged it in, it works fine, the only thing I didn’t think of is to not use a enable button on the input voltage on the pulse generator wheel, it triggers A-B input every time the button is pressed, it’s a quick fix.

other than that it does what i want it to do? I’ve uploaded a video on YouTube that demonstrates the problem with the flashing buttons and no ref all home button,

https://youtu.be/ynx5scc5eAQ