Machsupport Forum
Mach Discussion => Mach4 General Discussion => Mach4 Toolbox => Topic started by: secretspy711 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?
-
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
-
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
local spindlerpm = mc.mcSpindleGetCommandRPM
and then
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?
-
I also tried this, in the main screen script, but I am getting a compilation error on the messagebox line.
-- 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
-
I'm at work now so I cant test this, but could I simply add an M3 Macro to my macros folder?
-
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
-
your link isn't working...
thank you. I will play around with both of these options
-
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.
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
-
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.
-
https://www.machsupport.com/forum/index.php/topic,36008.0.html
-
Thanks for that reference. I'm not trying to pass a parameter, just get normal M3 functionality with the addition of a popup window telling me what RPM to set.
After a couple hours of messing with this, I finally got it. Here's my M3 script. This seems so obvious now... learning a new programming language just takes a little patience I suppose.
function m3()
inst = mc.mcGetInstance()
commandrpm = mc.mcSpindleGetCommandRPM(inst)
mc.mcCntlSetLastError(inst, 'SpindleClockwise')
mc.mcSpindleSetDirection(inst, 1)
wx.wxMessageBox("Set spindle RPM to " .. tostring(commandrpm) .. "\nThen press Cycle Start to continue")
mc.mcCntlToolChangeManual(inst, true)
end
if (mc.mcInEditor() == 1) then
m3()
end
-
here's a better one that also tells me what dial setting on my Makita
function m3()
inst = mc.mcGetInstance()
commandrpm = mc.mcSpindleGetCommandRPM(inst)
function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
makitasetting = round((((5/20010)*commandrpm)-1.396),2)
mc.mcCntlSetLastError(inst, 'SpindleClockwise')
mc.mcSpindleSetDirection(inst, 1)
wx.wxMessageBox("Set spindle to " .. tostring(commandrpm) .. " RPM (dial #" .. makitasetting ..")\nThen press Cycle Start to continue" )
mc.mcCntlToolChangeManual(inst, true)
end
if (mc.mcInEditor() == 1) then
m3()
end