Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Firechief on January 16, 2017, 09:49:35 PM

Title: Need help getting started Mach4
Post by: Firechief on January 16, 2017, 09:49:35 PM
Building a CNC router and have the control box built and turning motors. I need some help with inputs set up like feed stop buttons and cycle start on the machine. Got them wired in to input pin 1,2 and ground on the bob but not getting setup in Mach4.  Any help on this would be great. This is the first time running Mach4 and not doing so well.
Title: Re: Need help getting started Mach4
Post by: TOTALLYRC on January 17, 2017, 05:47:56 AM
Try using the PMC to connect your hardwired buttons to Mach4. It uses ladder logic and for the basic stuff it is real easy.
Title: Re: Need help getting started Mach4
Post by: Chaoticone on January 17, 2017, 04:45:24 PM
This topic may help if you want to write some custom script.........

http://www.machsupport.com/forum/index.php/topic,33956.msg235406.html#msg235406
Title: Re: Need help getting started Mach4
Post by: Firechief on January 17, 2017, 06:39:56 PM
Thanks I will take a look...
Title: Re: Need help getting started Mach4
Post by: Firechief on January 17, 2017, 07:03:00 PM
How do I get to the lua code to mod it. That is just what I,m looking for
Thanks
Title: Re: Need help getting started Mach4
Post by: Chaoticone on January 17, 2017, 08:05:38 PM
This video should help.

https://www.youtube.com/watch?v=TH944Qq86kc&t=1s&index=8&list=PLFJceKphr7eMOCyhq7ArVSWkx-mLB9LVN
Title: Re: Need help getting started Mach4
Post by: Firechief on January 18, 2017, 10:00:33 AM
That was a good video.. But I can not find how to add inputs from the machine like Feed hold and cycle start buttons. I can view the lua code but not mod it.
Any more help would be great, Thanks
 
Title: Re: Need help getting started Mach4
Post by: Firechief on January 20, 2017, 11:48:00 AM
Just for someone that is starting out with Mach4, I was trying to add Button input from the machine panel to Mach4 and here is what I did.

My first problem was trying to find out were the add some lua code for the inputs to work:
Open Mach4... 1- up top click on the Operator menu, then EDIT SCREEN. 2- In the tree manger (left side top box) click on wxrouter or the top item. 3- In the Properties (left side bottom box) click on the events button (middle one), then click on the SIGNAL SCRIPT line (Should be the bottom line), then a button should show up to the right of the line, click on the button and a mclua editor page will open. Then the code I added was at the end of what was there.

You will need to set up you inputs in Mach4 to match what is in the code

-------------------------------------------
----- My Code for input from Machine
-------------------------------------------
--------------------------------------------
----Cycle Start buttons on MachMate
--------------------------------------------
if (sig == mc.ISIG_INPUT1) and (state == 1) then
local inst = mc.mcGetInstance()
mc.mcCntlCycleStart(inst)
end
SignalTable = {
[mc.ISIG_INPUT1] = function (on_off)
if (on_off == 1) then
mc.mcCntlCycleStart(inst)
end
end
}
---------------------------------------------
----Feed Hold Buttons on MachMate
----------------------------------------------
if (sig == mc.ISIG_INPUT2) and (state == 1) then
local inst = mc.mcGetInstance()
mc.mcCntlFeedHold(inst)
end
SignalTable = {
[mc.ISIG_INPUT2] = function (on_off)
if (on_off == 1) then
mc.mcCntlFeedHold(inst)
end
end
}

Hope this help someone out.
Title: Re: Need help getting started Mach4
Post by: DazTheGas on January 20, 2017, 02:25:36 PM
You seem to be doubling up the function, try cutting down too

Code: [Select]
--------------------------------------------
----Cycle Start buttons on MachMate
--------------------------------------------
local inst = mc.mcGetInstance

SigLib = {
[mc.ISIG_INPUT1] = function (state)
     if (state == 1) then   
        mc.mcCntlCycleStart(inst)
end,

---------------------------------------------
----Feed Hold Buttons on MachMate
----------------------------------------------
[mc.ISIG_INPUT2] = function (state)
     if (state == 1) then   
        mc.mcCntlFeedHold(inst)
end,

[mc.ISIG_INPUT3] = function (state)
     if (state == 1) then   
        -- do something
end,

[mc.ISIG_INPUT4] = function (state)
     if (state == 1) then   
        -- do something
end,

[mc.ISIG_INPUT5] = function (state)
     if (state == 1) then   
        -- do something
end
} -- etc.............................

DazTheGas
Title: Re: Need help getting started Mach4
Post by: Firechief on January 20, 2017, 10:08:21 PM
Thanks for your help... I,m new to this and need all the help I can get. I changed my code to match your and
I get error???  I checked and rechecked. (Inst) is giving the error not returning a number... returning a function.
Title: Re: Need help getting started Mach4
Post by: DazTheGas on January 21, 2017, 04:46:44 AM
OOOppps TYPO ALERT

mc.mcGetInstance is a function and is missing the () at the end, so should of been mc.mcGetInstance() - although if this is in the screen load script then it is already declared at the beginning.

I also noticed I had`nt ended any of the if statements, so heres the same code without the typo`s

Code: [Select]
--------------------------------------------
----Cycle Start buttons on MachMate
--------------------------------------------
local inst = mc.mcGetInstance()

SigLib = {
[mc.ISIG_INPUT1] = function (state)
    if (state == 1) then   
        mc.mcCntlCycleStart(inst)
    end
end,

---------------------------------------------
----Feed Hold Buttons on MachMate
----------------------------------------------
[mc.ISIG_INPUT2] = function (state)
    if (state == 1) then   
        mc.mcCntlFeedHold(inst)
    end
end,

[mc.ISIG_INPUT3] = function (state)
     if (state == 1) then   
        -- do something
     end
end,

[mc.ISIG_INPUT4] = function (state)
    if (state == 1) then   
        -- do something
    end
end,

[mc.ISIG_INPUT5] = function (state)
    if (state == 1) then   
        -- do something
    end
end
} -- etc.............................

DazTheGas
Title: Re: Need help getting started Mach4
Post by: Firechief on January 21, 2017, 12:35:04 PM
New code worked  ;D :o ::)

Big thank you
Title: Re: Need help getting started Mach4
Post by: Firechief on January 24, 2017, 11:42:37 AM
Here is some pics of my control box
Title: Re: Need help getting started Mach4
Post by: Firechief on January 24, 2017, 11:43:40 AM
More... Not done but we can make motors turn  ;D  :o
Mach4 Is in control... some day I maybe.