71
M31 Motion Controller / Re: VFD
« Last post by edcross on March 12, 2026, 04:15:51 AM »When i load Machpro and turn on VFD , my spindle turns very slowly ( 2.37 hz ) , can stop it with vfd stop button
Ed
Ed
function m100()-- It uses pcall to call the _m100 function in protected mode, which means that any errors that occur during the execution of _m100 will be caught, preventing the script from crashing.
local is_ok, msg = pcall(_m100)
if is_ok ~= true then
wx.wxMessageBox(tostring(msg))
end
end
function _m100()
--Your Code contents here
end
if (mc.mcInEditor() == 1) then
m100()
end
function m23(hParam)-- It uses pcall to call the _m23 function in protected mode, which means that any errors that occur during the execution of _m23 will be caught, preventing the script from crashing.
local is_ok, msg = pcall(_m23, hParam)
if is_ok ~= true then
wx.wxMessageBox(tostring(msg))
end
end
function _m23(hParam)
local inst = mc.mcGetInstance()
local motor_5 = 5 --Setting your motor_5 to index 5 for readability
local axis_A = 3 --Setting your axis_A to index 3 for readability
local axis_OB1 = 6 --Setting your axis_OB1 to index 6 for readability
local getAxis = mc.mcMotorGetAxis(inst, motor_5)
local varS = 0 -- Setting S as your Spindle speed
if (getAxis == 3) then
mc.mcAxisUnmapMotor(inst, axis_A, motor_5) -- Changing these will not change the default settings.. this will just change for the duration of the session.
mc.mcAxisMapMotor(inst, axis_OB1, motor_5) -- Changing these will not change the default settings.. this will just change for the duration of the session.
mc.mcMotionSync(inst) --It's a good idea to sync when you change this information.
end
if (hParam ~= nil) then
varS = mc.mcCntlGetLocalVar(inst, hParam, mc.SV_S) -- This passes S into your varS value
end
gCode= ''
gCode= gCode..string.format("M3 S%0.f\n", varS)--This runs the gcode M3 S####
mc.mcCntlGcodeExecuteWait(inst, gCode)
end
if (mc.mcInEditor() == 1) then
m23()
end
Given the movement towards AI, I was just thinking about how it could be used to implement things like this in the CNC world. Besides creating 3D imagery, this seems to be an underserved area in the CNC world.