Hello Guest it is April 26, 2024, 01:06:07 PM

Author Topic: Basics on how to change Signal Scrips with Lua in Mach4  (Read 7548 times)

0 Members and 1 Guest are viewing this topic.

Offline $cott

*
  •  36 36
    • View Profile
Basics on how to change Signal Scrips with Lua in Mach4
« on: May 12, 2016, 09:31:02 PM »
Is there any videos or more documentation on how to change the signals scrips for Mach4.  I read in the manual how i can change the signal scrips for having an external switch to do a cycle start.  But it does not tell me were tese scrips are located, or how i can change it.  I have never done scripting so i am very green.  Can some one give me some helps on how i can do this.  I basically want Input1 (pin15) tied to a switch and when i push it i want to have a cycle start done.
 Thanks  Scott

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Basics on how to change Signal Scrips with Lua in Mach4
« Reply #1 on: May 13, 2016, 01:32:26 AM »
From the screen editor have a look at the siglib within the startup script, this should put you on the right track.

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Basics on how to change Signal Scrips with Lua in Mach4
« Reply #2 on: May 13, 2016, 10:11:25 AM »
Adding a little more (very basic) detail to DazTheGas's post:

First make sure you are using the wx4 screen set, or one derived from it.  The wxMach screen set does not have the code to support the signal scripts.  If you started with a PMDX sample profile you are using the wxMach screen set unless you specifically changed that (this will be changed in our next release).  To change screen sets go to the "View" menu and select "Load Screen".  In the file selector dialog, change into the "Screens" directory and select "wx4.set".

To edit the screen go the to "Operator" menu and select "Edit Screen".  The FIRST THING you should do is save this screen set to a different name!!!  Otherwise, when you install a new version of Mach4 it *may* overwrite the default wx4.set screen set and you will loose all of your custom changes.  To save the screen set, go to the "Screen" menu (while in the screen editor) and select "Save Screen As".

To get to the startup script, in the upper left corner of the screen is a section labeled "Screen Tree Manager".  Click on the top-most line, which should be the name of your screen set.  Then in the lower left corner of the screen is a section labeled "Properties".  You will see 3 icons, the middle one has a lightning bolt in it.  Click on that one to show the scripts.

There will be 4 scripts listed:
Screen Load Script - Initializes various variables, defines various helper functions and defines the "signal library", which is really just an array of functions indexed by signal names.  This is where you will place your code for processing the switch input.

Screen Unload Script - Add any code for clean up of saving of custom data.  Usually empty.

PLC Script - This script runs periodically (every 50 ms by default).  This is NOT normally where you would put code like you want for processing a switch input for "Cycle Start".

Signal Script - calls code in the screen load script for any change in a Mach4 signal.  Normally this script does not get changed.


To edit the code for any of these scripts click on the script name (or next to the name), then click on the little box that appears at the right-hand edge of that line.  There is already commented-out code in the "Screen Load" script in the section for Input1 (mc.ISIG_INPUT1) that you can use as an example starting point for your code.

Bob

Offline $cott

*
  •  36 36
    • View Profile
Re: Basics on how to change Signal Scrips with Lua in Mach4
« Reply #3 on: May 13, 2016, 10:59:16 AM »
BOB,

When i try to load the new screen in View menu the load screen option is grayed out so I can not load the MX4 screen set.  What did i miss?

Scott

Offline $cott

*
  •  36 36
    • View Profile
Re: Basics on how to change Signal Scrips with Lua in Mach4
« Reply #4 on: May 13, 2016, 11:03:37 AM »
Ok ... I think I am getting this ... I load the new screen set in MACH4 View menu not in the edit screen section.

Scott

Offline $cott

*
  •  36 36
    • View Profile
Re: Basics on how to change Signal Scrips with Lua in Mach4
« Reply #5 on: May 13, 2016, 11:41:44 AM »
Bob,

I tried adding the below code to the signal script section and i could not get my code to work.  Note my scripting knowledge is pathetic at most.

local inst = mc.mcGetInstance();

if (sig == mc.OSIG_MACHINE_ENABLED) then
    machEnabled = state;
end

if (sig == mc.ISIG_INPUT1) and (state == 1) then
local inst = mc.mcGetInstance()
mc.mcCntlCycleStart(inst)
end

local inst = mc.mcGetInstance();

if (sig == mc.ISIG_INPUT6) and (state == 1) then
local inst = mc.mcGetInstance()
mc.mcCntlCycleStop(inst)
end

Yet when deleted my code and commented out the Input 1/Cycle Start section in the Load Screen Script section it works.  From my reading of the manual i thought i was supposed to add this kind of thing in the Signal Script Script Section?

Can you or DAZtheGas explain to my why so i can understand what i have messed.

Thanks again for all your help ... my machine is fully functioning!!

Scott
« Last Edit: May 13, 2016, 11:43:39 AM by $cott »

Offline $cott

*
  •  36 36
    • View Profile
Re: Basics on how to change Signal Scrips with Lua in Mach4
« Reply #6 on: May 13, 2016, 12:01:04 PM »
I commented out the script in the Load Screen section for Input1/Cycle Start.  I have found the switch is activating the cycle start but it is not doing it properly.  For example when I give a G-Code of say G1A360F100 my glue disk only turns say 12 degrees instead of 360 degrees.  When just do a typical cycle start off MACH4 menu it works fine.  Another bad side effect is it seems when i use external cycle start button it locks up the MACH4 Cycle Start menu button.  If deactivate the system and start again i can seem to get it running again.

Any suggestions for me?

Scott

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Basics on how to change Signal Scrips with Lua in Mach4
« Reply #7 on: May 13, 2016, 04:14:22 PM »
The example script for input 1 will make input 1 do a cycle start when pressed and a feed hold when released (think dead man switch) if everything is uncommented.

[mc.ISIG_INPUT1] = function (state) --Anytime the state of input 1 changes, run this function
   -- if (state == 1) then --Input one is active
--        CycleStart() --Run the CycleStart() function
--    --else --Input one is inactive
--        --mc.mcCntlFeedHold (0) --Do a feed hold
--    end

end,

If you want input 1 to only run the CycleStart function it should look like this........

[mc.ISIG_INPUT1] = function (state) --Anytime the state of input 1 changes, run this function
    if (state == 1) then --Input one is active
        CycleStart() --Run the CycleStart() function
    --else --Input one is inactive
        --mc.mcCntlFeedHold (0) --Do a feed hold
    end

end,

I think you will find the following link helpful.
http://www.lua.org/manual/5.2/
;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!
Re: Basics on how to change Signal Scrips with Lua in Mach4
« Reply #8 on: May 13, 2016, 04:36:24 PM »
Scott

I've looked at the profile that you posted on our forums (http://www.pmdx.com/PMDX-Forums/index.php?topic=270.0).  There are a couple of things:

(1) You put your code in the "Signal Script".  It belongs in the "Screen Load" script.  Edit your "Signal Script" and remove everything so that it looks like this:
Code: [Select]
-------------------------------------------------------
--  Signal Script
-------------------------------------------------------

if SigLib[sig] ~= nil then
    SigLib[sig](state);
end

(2) Open at the "Screen Load" script.  THAT is where your code needs to be.  And that is where there is already an example of exactly what you want.  See Chaoticone's post above.  You just need to un-comment 3 lines in the existing [mc.ISIG_INPUT1] section.

Note that the sample code calls CycleStart(), which is a Lua function that you will find further down in the "Screen Load" script.  It does not call mc.mcCntlCycleStart() directly because there are other things that need to happen, like figuring out if the GUI is in an MDI window or if it should run a GCode file.

Bob

Offline $cott

*
  •  36 36
    • View Profile
Re: Basics on how to change Signal Scrips with Lua in Mach4
« Reply #9 on: May 13, 2016, 05:17:03 PM »
Bob and Chaos,

Thank you for your support on my task.  I cleaned up the signal scrip as suggested and made the change to eliminate the feed hold in the screen load script.  The feed hold was my issue definitely my issue.  I will also read the post you suggested.

I guess i am most confused as why the manual says to put the signal information in the signal scripting area instead of the screen load area.

I will also read the post you suggested and hope it willclear things up for me.

thank again for the help and am making perfect glue joints now ... i ma so pleased with my little Glue-Bot performance!

Regards Scott


Scott