Hello Guest it is April 25, 2024, 10:50:11 AM

Author Topic: Prevent spindle rotation for certaint tools  (Read 407 times)

0 Members and 1 Guest are viewing this topic.

Offline kvid

*
  •  25 25
    • View Profile
Prevent spindle rotation for certaint tools
« on: November 07, 2021, 02:09:19 PM »
Today I had my Haimer 3D taster in the spindle (tool Nr. 2) and I wanted to load tool Nr. 6. I wrongfully typed M3 T6 instead of M6 T3 into the MDI. Luckily the spindle speed was set to only 1000 rpm, so no damage was done, but it could have been much worse.

Is there a way in Mach4 to disable the spindle for specific tools?

Offline Bill_O

*
  •  563 563
    • View Profile
Re: Prevent spindle rotation for certaint tools
« Reply #1 on: November 08, 2021, 09:16:04 AM »
I have a few options for our machines that I do not want the spindle turning on while being used.
I wrote a custom m3 that if those tools are the current tool to not turn on the spindle.
I used registers to pass the information to the m3.
Here is the code.

function m3()
   --wx.wxMessageBox('In M03')
   --mc.mcCntlSetLastError(inst, "In M03")
   local inst = mc.mcGetInstance()
   --Get Spindle On and Spindle Auto handles
   local hSpin = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON)
   local hreg = mc.mcRegGetHandle(inst, 'iRegs0/SpindleAuto')
   --Get spindle on state
   local SpinOn = mc.mcSignalGetState(hSpin)
   --Get Spindle Auto value
   local SpinVal = mc.mcRegGetValue(hreg)
   --get if tk turned on and tk osc selected
   local TKOnOff = mc.mcCntlGetParameter(502)
   local TKOReg = mc.mcRegGetHandle(inst, 'iRegs0/TKOscOnOff')
   local TKORegVal = mc.mcRegGetValue(TKOReg)
   
   local TKOnOffReg = mc.mcRegGetHandle(inst, 'iRegs0/TKOnOff')
   local TKOnOffVal = mc.mcRegGetValue(TKOnOffReg)
   
   if (TKOnOff == 0) then--or (TKOnOffVal == 0) then
      if (SpinVal == 0) then
         --mc.mcSignalSetState(hSpin, 0)
      elseif (SpinOn == 0) then
      
         local hregSpinType = mc.mcRegGetHandle(inst, 'iRegs0/SpindleType')
         local SpinType = mc.mcRegGetValue(hregSpinType)
         --local hregSpinCool = mc.mcRegGetHandle(inst, 'iRegs0/SpinCool')
         local hsigSpinCool = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT4)
         if (SpinType == 2) then --and (TKOnOff == 0)then
            --mc.mcRegSetValue(hregSpinCool, 1)
            mc.mcSignalSetState(hsigSpinCool, 1)
            wx.wxMilliSleep(2000)
         end

--         if (TKOnOff == 0) then
            mc.mcSignalSetState(hSpin, 1)
            --local hrSpinType = mc.mcRegGetHandle(inst, 'iRegs0/SpindleType')
            --local SpinType = mc.mcRegGetValue(hrSpinType)
            if (SpinType == 0) then
               wx.wxMilliSleep(1500)
            elseif (SpinType == 1) then
               wx.wxMilliSleep(5500)
            elseif (SpinType == 2) then
               wx.wxMilliSleep(11000)
            end
--         end
      end
   elseif (TKOnOff == 1) and (TKORegVal == 1)then
      local TKOscH = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT9)
      mc.mcSignalSetState(TKOscH, 1)
   end
end
if (mc.mcInEditor() == 1) then
   m3()
end