Hello Guest it is April 13, 2021, 08:51:11 PM

Author Topic: Custom ATC M6 not running  (Read 212 times)

0 Members and 1 Guest are viewing this topic.

Custom ATC M6 not running
« on: June 25, 2020, 08:32:16 AM »
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.

Code: [Select]
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

Offline Graham Waterworth

*
  • *
  •  2,305 2,305
  • Yorkshire Dales, England
    • View Profile
Re: Custom ATC M6 not running
« Reply #1 on: June 25, 2020, 08:07:51 PM »
Mach4 Lathe uses T0101 NOT T1 M6
Without engineers the world stops
Re: Custom ATC M6 not running
« Reply #2 on: June 26, 2020, 06:31:51 AM »
Thanks Graham that was one part. The other was adding M30 to the MDI so it didn't loop.
One other thing I did wrong was creating custom functions GetSignal() etc. in the screen load script.
I tried to use these in the m6() function but they couldn't be run unless I added them to the start of the m6.mcs.
I incorrectly assumed these could be declared in the screen load script and called in a macro.
I'll post the final code here for others when I get back to the workshop next week.