I have a 6 position turret toolchanger on an old lathe (pokeys57cnc retrofit) that takes a PWM signal for motor speed and IO signal for changing tools and/or locking the turret.
It also has 6 hall sensors on the back for sensing current tool and a sensor for ensuring the turret is in lock. This will be used for changing tools automatically.
I have a custom m6.mcs script in the macro folder of the lathe profile.
Whenever I hit cycle start using any combination of TX M6 Mach4 starts doing the original manual m6.mcs that was in that folder.
Renaming/deleting the old macro didn't seem to delete it?
I don't have access to the up to date script but it looks something like the below.
Ignore how I'm handling turning the motor on I've fixed that.
function m6()
local nTools = 6
local turretMove = false
local turretLock = false
local inst = mc.mcGetInstance()
local selectedTool = mc.mcToolGetSelected(inst)
selectedTool = math.tointeger(selectedTool)
local currentTool = mc.mcToolGetCurrent(inst)
currentTool = math.tointeger(currentTool)
--map an array of tool turret position signals to tool numbers
local Tools = {
[1] = mc.ISIG_INPUT1,
[2] = mc.ISIG_INPUT2,
[3] = mc.ISIG_INPUT3,
[4] = mc.ISIG_INPUT4,
[5] = mc.ISIG_INPUT5,
[6] = mc.ISIG_INPUT6}
--if selected tool is invalid msg and exit
if (selectedTool>nTools) or (selectedTool<1) then
return "Tool Number out of range", false
end
--if tool is the same do nothing just exit
if selectedTool == currentTool then
return false
end
--Check if turret is locked if not msg and exit
turretLock = GetSignal(mc.ISIG_INPUT0) --gets lock signal
if turretLock == 1 then
return "Turret may not be locking properly", false
end
--Remove this line if you would not like the Z axis to move
--mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z400");--Move the Z axis to 400 out of the way
--Go forward until tool sensor input matches selectedTool
WriteSignal(mc.OSIG_OUTPUT0, 0) --Set direction to move turret
WriteSignal(mc.OSIG_OUTPUT7, 0.77) -- Set motor output PWM level ie turn motor on
turretMove = true
while (turretMove == true) do
local toolSig={}; --empty array for storing signal values
--Grab all the states of the turret sensors
for i=1,nTools,1 do
toolSig[i] = GetSignal(Tools[i])
end
--Check if the turret sensor we want has triggered
--if so turn off motor
if toolSig[selectedTool] == 0 then
WriteSignal(mc.OSIG_OUTPUT7, 0) -- turn off motor
turretMove = false
end
end
--lock turret in place and check locked
WriteSignal(mc.OSIG_OUTPUT0, 1) --Set direction to lock turret
WriteSignal(mc.OSIG_OUTPUT7, 0.77) -- Set motor output PWM level ie turn motor on
turretMove = true
while (turretMove == true) do
turretLock = GetSignal(mc.ISIG_INPUT0) --get lock signal
if turretLock == true then
WriteSignal(mc.OSIG_OUTPUT7, 0) --turn off motor
turretMove = false
end
end
mc.mcToolSetCurrent(inst, selectedTool) --set current tool
end