Hello Guest it is August 18, 2019, 08:22:10 PM

Author Topic: M6: how to add manual spindle RPM with tool change?  (Read 1007 times)

0 Members and 1 Guest are viewing this topic.

M6: how to add manual spindle RPM with tool change?
« on: October 01, 2018, 12:49:13 PM »
I am using a trim-router as a spindle on my homebuilt machine.  Mach4 controls on/off, but for now, I have to set the speed manually until I get a VFD or SuperPID controller.

I would like to modify my M6 script to get Mach to tell me what RPM to set, in addition to the tool number.  Can someone show me an example script for how to do this?
Re: M6: how to add manual spindle RPM with tool change?
« Reply #1 on: October 02, 2018, 05:48:52 AM »
I added a custom field "Real Length" to my tool table. I print the value for the selected tool within the M6 routine with the following code:
-------------------------------
local toollen = mc.mcToolGetDataExDbl(inst, selectedtool, "Real Length")
wx.wxMessageBox("Please change to tool# "..selectedtool..": "..changetoo..", "..toollen.." mm and press ok to continue")
-------------------------------
You could add a field called "Spindle RPM" to the tool table and add values for each tool.
How about that?
Regards,
Karl
Re: M6: how to add manual spindle RPM with tool change?
« Reply #2 on: October 03, 2018, 01:00:15 AM »
CNCharly, that's close, but it doesn't consider that the spindle RPM in the Mach4 tool table might be different than the RPM I've set in my Gcode.  I suppose since "T1 M6" is immediately followed by something like "S10000 M3", I could simply look at the Gcode preview window and determine that I need to set it to 10000 RPM... it would just be nice to have it in the same popup window that tells me what tool to change to.

I tried using
Code: [Select]
local spindlerpm = mc.mcSpindleGetCommandRPM
and then
Code: [Select]
wx.wxMessageBox("Set spindle RPM to " .. tostring(spindlerpm) .. "\nThen press Cycle Start" )
and it works except it's telling me to set the spindle RPM to 0...
I assume that's because it hasn't seen the first "S10000 M3" command yet.  How do I get it to look ahead 1 line of gcode and get that number?
« Last Edit: October 03, 2018, 01:05:38 AM by secretspy711 »
Re: M6: how to add manual spindle RPM with tool change?
« Reply #3 on: October 03, 2018, 02:23:51 AM »
I also tried this, in the main screen script, but I am getting a compilation error on the messagebox line.

Code: [Select]
-- Spin CW function.
---------------------------------------------------------------
function SpinCW()
    local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
    local sigState = mc.mcSignalGetState(sigh);
    local spindlerpm = mc.mcSpindleGetCommandRPM(inst);
   
    if (sigState == 1) then
        mc.mcSpindleSetDirection(inst, 0);
mc.mcCntlToolChangeManual(inst, true); --This will pause the tool change here and wait for a press of cycle start to continue
wx.wxMessageBox('Set spindle RPM to' .. spindlerpm .. ); --message box with RPM to set
    else
        mc.mcSpindleSetDirection(inst, 1);
mc.mcCntlToolChangeManual(inst, true); --This will pause the tool change here and wait for a press of cycle start to continue
wx.wxMessageBox('Set spindle RPM to' .. spindlerpm .. ); --message box with RPM to set
    end
end
Re: M6: how to add manual spindle RPM with tool change?
« Reply #4 on: October 03, 2018, 10:47:54 AM »
I'm at work now so I cant test this, but could I simply add an M3 Macro to my macros folder?
Re: M6: how to add manual spindle RPM with tool change?
« Reply #5 on: October 03, 2018, 11:34:36 AM »
I don't believe you can modify M3.  You can however put a macro named spindlspeed.mcs that will be called every time a m3 is issued.  See this post:

https://www.machsupport.com/forum/index.php?action=search2

Also, there is an api to get the current line being executed
mcCntlGetGcodeLineNbr
mcCntlGetGcodeLine

fromn that you could parse the line to see what is being requested
Re: M6: how to add manual spindle RPM with tool change?
« Reply #6 on: October 03, 2018, 12:09:07 PM »
your link isn't working...

thank you.  I will play around with both of these options
Re: M6: how to add manual spindle RPM with tool change?
« Reply #7 on: October 03, 2018, 12:37:56 PM »
rhtuttle, currently there is no M3 macro in my macros folder.  Wouldn't creating an M3 macro like this work?  I could probably add in some way to store the last spindle speed, and compare it to the one currently being commanded, and if they are the same, then skip this entirely.

Code: [Select]
function m3()
local inst = mc.mcGetInstance()
local spindlerpm = mc.mcSpindleGetCommandRPM(inst)

mc.mcCntlCycleStop(inst)
        wx.wxMessageBox("Set Spindle RPM to" .. tostring(spindlerpm) .. )
mc.mcCntlSetLastError(inst, "Set Spindle RPM to" .. tostring(spindlerpm) ..)
end

if (mc.mcInEditor() == 1)
then  m3()
end
« Last Edit: October 03, 2018, 12:39:28 PM by secretspy711 »
Re: M6: how to add manual spindle RPM with tool change?
« Reply #8 on: October 03, 2018, 02:12:54 PM »
I keep learning new stuff...

According to the scripting manual:
https://usermanual.wiki/Pdf/Mach420Scripting20Manual.642363313/html

On page 9/10, the M3 code falls under the category of "if there's no user script, the internal script will be used" which is what's currently happening.  So it looks like I can create my own script as above, but I will have to expand it to actually turn on the spindle.  I think I just found my answer.