Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: RecceDG on April 26, 2020, 01:31:42 PM

Title: Manual Spindle Start Switch?
Post by: RecceDG on April 26, 2020, 01:31:42 PM
I have a benchtop lathe that I converted to CNC (https://www.youtube.com/playlist?list=PLZYHEvmLdMEqb9NKAPYyhaSPm2VY4q45G if you are curious)

I find that I still do the occasional operation (like drilling from the tailstock) that requires the spindle to be turned on/off manually.

I can do this from the Mach 4 interface, but it would be handy to wire in a physical switch so I can start and stop the spindle. This would work exactly like the interface buttons (and ideally would toggle the UI elements ).

Can this be done, and if so, how?
Title: Re: Manual Spindle Start Switch?
Post by: TOTALLYRC on April 26, 2020, 08:36:44 PM
I use the PMC to "connect" all of my operator station switches.


Mike
Title: Re: Manual Spindle Start Switch?
Post by: RecceDG on April 26, 2020, 10:51:33 PM
Do you have an example?

Do you use a separate momentary-contact switch for each op, or can a toggle work as off/on?
Title: Re: Manual Spindle Start Switch?
Post by: thosj on April 27, 2020, 08:43:14 AM
I do it in the Screen Start Script, Signal Library. A button, momentary, is wired to an input, in my case a Pokeys 57E, and the code is in the Signal Library. It IS a toggle. You need to setup the input for whatever input you're using, BOB, PoKeys, whatever. PMC might be easier, you don't have to write the code, but the code ain't much!!

My code:

------------Mach4 Input 8 PoKeys Pin 8----------------
------------Toggle SpinCW-----------------------------
[mc.ISIG_INPUT8] = function (state)
if (state == 1) then
     local inst = mc.mcGetInstance();
     local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
     local sigState = mc.mcSignalGetState(sigh);
     if (sigState == 1) then
         mc.mcSpindleSetDirection(inst, 0);
     else
         SpinCW()
     end
end

end,

Tom
Title: Re: Manual Spindle Start Switch?
Post by: RecceDG on April 27, 2020, 09:47:11 AM
So then you also need a "Spindle Off" button, momentary contact, that works the same way, right?
Title: Re: Manual Spindle Start Switch?
Post by: thosj on April 27, 2020, 01:09:37 PM
No.....that momentary button, with that code, toggles........like the code comment says.......one press, spindle on, next press, spindle off. You do need a speed active, and Mach4 starts up with zero speed. So an S1000 or some such via MDI or gcode. I actually put some code in my RefAllHome script to set the spindle speed as in Mach3 it was remembered between sessions and I never shook that, always assuming a speed was there on Mach4 startup and it isn't:)
Title: Re: Manual Spindle Start Switch?
Post by: Ron Ginger on May 05, 2020, 09:31:35 PM
OK, a switch to start it is  nice, now how about a pot to an d analog input to over ride the spindle speed. I have done this for Feed and Rapid, but I didint find a spinOverrride script.

Anyone done this?
Title: Re: Manual Spindle Start Switch?
Post by: thosj on May 06, 2020, 07:27:22 AM
I do it but with a PoKeys 57E which has inputs for analog pots, pins 44 and 45 if memory serves. So I just wired pots, one for spindle speed and one for feed override. I don't think I had to write any code, might just be in PoKeys plugin/software. The feed override also overrides rapid, so you can pretty easily control things!! I'm old fashioned and ran machines in the real world with pots to control feed/speed, so I will NOT run a machine without those two things. The new kids laugh, but I prefer sneaking up on the first part rather that replacing broken cutters. My Kurt vises don't have cutter marks on top!!!
Title: Re: Manual Spindle Start Switch?
Post by: Ron Ginger on May 06, 2020, 07:57:34 AM
Thanks. I am using a Pokey57E and I have pots connected for Rapid and Feed over ride. They require a script in the PMC folder that reads the pot and calls the Feed and Rapid override function. What I dont know is the correct name of the Spindle over ride function.
Title: Re: Manual Spindle Start Switch?
Post by: thosj on May 06, 2020, 09:24:48 AM
Hmmmm.....no script in my PMC folder. I'll have to go look how they work!! Trouble with all this customization stuff is you struggle and get it working and two years later you don't remember how the hell you did it;) I'll be back.
Title: Re: Manual Spindle Start Switch?
Post by: thosj on May 06, 2020, 09:59:06 AM
PoKeys 57E analog pots. This is in the PLC script, last thing at the end of the file. The two .lua files I have in my Profiles directory so they get copied in with the profile when updating Mach4. They can be anywhere, just point the dofile to the right place.

-------------------------------------------------
--My Stuff!!
-------------------------------------------------
--Runs the PoKeys FRO and SRO lua files as shown!

dofile("C:\\Mach4Hobby\\Profiles\\ESS_New\\PoKeys_analog_FRO.lua")
dofile("C:\\Mach4Hobby\\Profiles\\ESS_New\\PoKeys_analog_SRO.lua")

---------------------------------------------------------------------------

FRO/RRO .lua file

--Function to read value from analog register
function ReadRegister(device, analogPin)
    local inst = mc.mcGetInstance()
    local hreg = mc.mcRegGetHandle(inst, string.format("%s/Analog input %s", device, analogPin))
    return mc.mcRegGetValueString(hreg)
end

--Function to set FRO value
function SetFRO(analog)
    local percent = analog/1*250 --calculate percentage from 0% to 250%
    local inst = mc.mcGetInstance()
    mc.mcCntlSetFRO(inst, percent)
    mc.mcCntlSetRRO(inst, percent) --sets RRO 0% to 250% to follow FRO
end

--Main
local device = "PoKeys57" --Change this to the name of your PoKeys device
local analogPin = "45" --Analog input pin number

analogVal = ReadRegister(device, analogPin) --Save analog register value in variable
SetFRO(analogVal) -- Set FRO value in %

-------------------------------------------------------------------------------

SRO .lua file

function ReadRegister(device, analogPin)
    local inst = mc.mcGetInstance()
    local hreg = mc.mcRegGetHandle(inst, string.format("%s/Analog input %s", device, analogPin))
    return mc.mcRegGetValueString(hreg)
end

--Function to set SRO value
function SetSRO(analog)
    local percent = analog/1*1.0+0.5 --calculate percentage
    local inst = mc.mcGetInstance()
    mc.mcSpindleSetOverride(inst, percent)
end

--Main body -
local device = "PoKeys57" --Change this to the name of your PoKeys device
local analogPin = "44" --Analog input pin number on PoKeys

analogVal = ReadRegister(device, analogPin) --Save analog register value in variable
SetSRO(analogVal) -- Set SRO value in %

I could upload the two .lua files if you'd prefer that!!

I've now made a notepad file to remind me two years from now how I did this!!!

Tom
Title: Re: Manual Spindle Start Switch?
Post by: Ron Ginger on May 06, 2020, 12:27:08 PM
OK, no longer need a script. PoKey has added pots to the last page of their config dialog. You just select the pin numbers and it works.

Well, it almost works. On my system the Feed pot works, bout only to 100%. The rapid pot is configured the same way and wired the same way, but does not move the slider. I didnt try the spindle, I dont have spindle output on my system.

So again, a Mach feature almost works.
Title: Re: Manual Spindle Start Switch?
Post by: thosj on May 06, 2020, 04:11:41 PM
You SURELY meant a PoKeys feature that almost works!!! My coded Mach feature works like a champ and is programable for your desired percentage at the same time. Use that;)
Title: Re: Manual Spindle Start Switch?
Post by: TOTALLYRC on May 07, 2020, 06:58:41 AM
Hi Ron,
They are configurable to match what the slider in Mach says. I have SRO, and FRO setup and configured to match the screen sliders, and they both work. When I add a third pot I will setup RRO. It was easy to do but I don't remember exactly where I did the edit to get them to match.

If they give me trouble I will set them up like Thosj has done.

Mike