Hello Guest it is March 28, 2024, 01:47:41 PM

Author Topic: Need help turning on coolant when my spindle starts  (Read 2035 times)

0 Members and 1 Guest are viewing this topic.

Need help turning on coolant when my spindle starts
« on: October 30, 2017, 09:35:43 AM »
I'm new to Mach 4 so I'm looking for a little help on the scripting side.  I would like to set up my mill so that anytime I turn on my spindle the coolant automatically turns on.  Any help would be appreciated.
Re: Need help turning on coolant when my spindle starts
« Reply #1 on: November 03, 2017, 10:40:15 AM »
Hi Ewalk02,
I notice that you have a few active posts and all concerning Mach4.
Posting on the Mach4 board will result in more people seeing it and responding.

As you probably know m3 is the macro which turns the spindle on CW, m4 turns it on CCW and m5 turns it off. Mach4 has these macros but they are internally
coded and you can't inspect or modify them. However if you write your own m3. m4 and m5 in your current profile Mach will use those instead. Note that
any behaviour in the original m3 will have to be duplicated in your m3 plus whatever extra behaviour you want.

http://www.machsupport.com/wp-content/uploads/2014/05/Mach4%20Scripting%20Manual.pdf
page 9 describes the idea. Note this Scripting Manual is bundled with Mach4...when Mach4 is enabled <Help Docs ?> in the File Ops Tab.

In the screen load script there are two functions to turn the spindle on:
Code: [Select]
---------------------------------------------------------------
-- Spin CW function.
---------------------------------------------------------------
function SpinCW()
    local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
    local sigState = mc.mcSignalGetState(sigh);
   
    if (sigState == 1) then
        mc.mcSpindleSetDirection(inst, 0);
    else
        mc.mcSpindleSetDirection(inst, 1);
    end
end

---------------------------------------------------------------
-- Spin CCW function.
---------------------------------------------------------------
function SpinCCW()
    local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
    local sigState = mc.mcSignalGetState(sigh);
   
    if (sigState == 1) then
        mc.mcSpindleSetDirection(inst, 0);
    else
        mc.mcSpindleSetDirection(inst, -1);
    end
end

The simplest expedient would be to add a line to turn your coolant on in each function.
There is a similar function to turn the spindle off:
Code: [Select]
---------------------------------------------------------------
--  Spindle Shutdown
---------------------------------------------------------------
function Shutdown();
    local inst=mc.mcGetInstance();
    mc.mcScriptExecute(inst,"m5.mcs",0);
end;
which could include a line to shut the coolant off.

If you wish for more complete control and customised behaviour the writing your own m3, m4 and m5 scripts is the way to go.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'