Hello Guest it is May 14, 2021, 10:33:38 PM

Author Topic: Multiple inputs in LUA script  (Read 8003 times)

0 Members and 1 Guest are viewing this topic.

Re: Multiple inputs in LUA script
« Reply #20 on: October 15, 2016, 08:43:11 PM »
Bob: I have been following your progress.  Glad to hear of your success.  I would like to see how your put it together if you would not mind posting your final screen script.  I am working on a similar set of controls to update an machine from Mach3 to Mach4.  Any other words of wisdom are appreciated. 

Thanks, Jim

Offline Bob49

*
  •  57 57
    • View Profile
Re: Multiple inputs in LUA script
« Reply #21 on: October 15, 2016, 11:15:02 PM »
Not a problem.  Words of wisdom?  I got none.  But I can tell ya what works and what doesn't in this script.  RRO, FRO and SRO all work 100% and work quickly.  I set the values to match the graphics I created for my console back when I built it.  Those step values came from a commercial control I bought to get the switches.  Good thing is you can change them in the script to whatever you like.  Just follow the whole or decimal values where they appear.

The jogging is still a mystery to me though.  The first two chunks are to control the jog type, either continuous or incremental.  But I've not cracked the values needed to set them in the jog panel.  So that's a work in progress yet.  The increment values all work to change the text window DRO where they appear in the jogging panel.  But none of them will toggle the CycleIncrementValue function to make the button active in the jog panel.  And I've found that's required with the version of Mach4 I have, that might be 3124.  I personally don't like how the jog panel works due to that.  It's a bit quirky I think.  So if you set the increment value via a hard switch, then used the mouse to make the CycleIncrementValue active and had jogging set to incremental, then you could jog the value that's showing in that text window DRO.  But if you change that value via the hard switch, the jog increment value will still be what it was before you just changed it.  You would have to go back with the mouse and make that CycleIncrementValue button active again to use the new increment value.

So I'm still trying to sort through that.  And me, I'd like to change the jogging panel to eliminate the need to make that button active.  Just make it do what it says it's supposed to do, cycle the value, nothing more.  If incremental jogging is already selected, why would I need another button to activate anything.  Mach3 never worked like that and I think now that early versions of Mach4 didn't either.

So that's about the extent of my knowledge so far.  I do have another opinion on jogging though,  I don't like the method that's required to setup the keyboard keys for jogging.  The manual hints that the keyboard is already set for using the old standard Mach3 keys for jogging.  That's not the case, you have set that up in the keyboard plugin.  And then they're tied to mach and can't be used for other uses.  I think Daz has a work around for that, but I've not explored any of that to much depth.  So it remains a work in progress while I sort it all out.

In the signal table, you'll see some inputs that don't appear to be being used.  And they aren't right now.  I think there are 4 of them.  All the rest of the 31 or 32 inputs work for their intend functions.  And the way the script for each are written, they either leave a function active or toggle it.  Most of my switches are momentary switches, like cycle start, feed hold, single step and so forth.  The way the statements are written deal with the need to either leave the function persistent or toggle it off.  Spindle range is one such.  Range 0 stays 0, range 1 stays range 1.

Hope that helps you get where you want to go.

Bob
Re: Multiple inputs in LUA script
« Reply #22 on: October 16, 2016, 03:38:59 PM »
Bob: Thanks so much.   I got my Cycle Start and Feed Hold buttons working. A good start!
FRO and SSO are next.  Are you using a rheostat for analog voltage or some kind of encoder for those?
I am using a Pokeys57CNC board and using their plugin which includes the MPG control and axis and step value selectors.
I'll study some LUA for dummies to make some sense of what is going on.  The last programming for me was a little C in the previous century.
Thanks again
Jim

Offline Bob49

*
  •  57 57
    • View Profile
Re: Multiple inputs in LUA script
« Reply #23 on: October 16, 2016, 03:49:35 PM »
My switches for FRO, RRO, Jogging and SRO are all multi position rotaries that use a combination of the internal contacts for each position.  They are Fuji AC09 real binary switches.  Some just have more positions than others.  Hence the additional inputs in the script.  So for each input, it's just a question of is the state 1 or 0. 

Bob
Re: Multiple inputs in LUA script
« Reply #24 on: October 16, 2016, 05:25:05 PM »
Bob: I reread the postings and checked out the switches (very interesting) as well as your code.  Starting to make sense. (sorry for the stupid questions) That is a very clever way to control the overrides!
Thanks, Jim

Offline Bob49

*
  •  57 57
    • View Profile
Re: Multiple inputs in LUA script
« Reply #25 on: October 16, 2016, 08:48:03 PM »
Thanks Jim. 

The switches are nice and pretty industrial.  Actually until Friday morning I had no clue how to do them.  Then in an instant it was crystal clear.  Do them just like the RRO.  Don't know why I couldn't see that before then.

I messed with the mill today to make a couple of parts.  And in doing that had to mess with jogging.  Verified there is no keyboard jogging without setting that up in the keyboard plugin.  The standard x and y jogging keys only move the jog rate slider if nothing is set up in the plugin.  In the plugin you have to set up const jogging, or incremental jogging or by using more key combo's you can have both.  Same goes for rapid jogging.  So I'm a ways from having jogging control via my console and the keyboard like I had in Mach3.

And there ain't no stupid questions.  We weren't born with this knowledge and if you don't ask, you may never have it.  That's how I got over the hump on it.  And a couple kind soles threw me a clue or two.

Bob

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Multiple inputs in LUA script
« Reply #26 on: October 17, 2016, 02:52:31 AM »
you can use a num keypad for a jogging keypad then you can use it like a pendant

Offline Chaoticone

*
  • *
  •  5,626 5,626
  • Precision Chaos
    • View Profile
Re: Multiple inputs in LUA script
« Reply #27 on: October 17, 2016, 08:16:47 AM »
Guys, here are some signals I added to the sig library and the function it runs if any of their states change. You might find it helpful. But remember, this is out of the screen load script and inst is defined at the beginning of it.

Code: [Select]
--------------------------------------
-- CNC4PC Pendant --
--------------------------------------
-- These simply run the CNC4PCPendant function if their state changes.
[mc.ISIG_INPUT10] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT11] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT12] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT13] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT14] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT15] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT16] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT17] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT18] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT19] = function (state)
    CNC4PCPendant()
end

}

---------------------------------------------------------------
-- CNC4PC Pendant function.
---------------------------------------------------------------
function CNC4PCPendant()
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 hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT18)    -- Is mapped to Port 2 Pin 12 *B Selection
local BSelection, rc = mc.mcSignalGetState(hSig)
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT19)    -- Is mapped to Port 2 Pin 13 *C Selection
local CSelection, 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)
elseif BSelection == 1 then
mc.mcMpgSetAxis(inst, 0, 4) --B Axis
mc.mcCntlSetLastError(inst, "B Selected")
mc.mcSignalSetState(PenJogOn, 1)
elseif CSelection == 1 then
mc.mcMpgSetAxis(inst, 0, 5) --C Axis
mc.mcCntlSetLastError(inst, "C 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
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline Bob49

*
  •  57 57
    • View Profile
Re: Multiple inputs in LUA script
« Reply #28 on: November 30, 2016, 08:13:10 PM »
you can use a num keypad for a jogging keypad then you can use it like a pendant

Took me a while to come to grips with this jogging thing.  I did end up using the number pad for continuous and rapid jogging of X, Y and Z, then used the standard arrow keys and page up and down keys for incremental jogging.  No idea what I'll use when I get the 4th axis mounted back on the mill, probably just the mouse and jog panel.

So I do have console control of the incremental value, but still no control on selecting incremental or continuous jogging from the console switch.  And I still don't understand what the enable or disable keyboard jogging button is supposed to do.  It does still allow the keyboard jogging, only it seems it's all continuous in spite of what the keys have been set up for.

Maybe adding a pendant would be the way to go.  Put it all in one hand held devise.  May have to look into that. 

Bob

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Multiple inputs in LUA script
« Reply #29 on: November 30, 2016, 10:48:38 PM »
pendants make life very easy