1
Mach4 Toolbox / Umbrella Style M6 Script
« on: March 29, 2024, 05:18:43 PM »
I have an old Milltronics Partner 1 mill with a 6 tool umbrella style tool changer that I'm rebuilding and using Mach4 with a Hicon Integra controller. I haven't been able to find a m6 script for this style so I have attempted to modify the tool change script that is on CNC4PC. Can you guys that actually know how to program LUA check my code and let me know if it looks correct or what I should modify? I'm using a stepper to rotate the umbrella and calling it C axis. It has a home sensor and also a sensor for each tool position, but I'm not sure if I really need the tool position sensor. I didn't use it in this code. Once I finish getting the mill running I'll modify the I/O if I need to and set the correct tool change position.
Thanks!
Mike
Thanks!
Mike
Code: [Select]
----------Variables----------
local inst = mc.mcGetInstance()
local DrawBarOut = mc.OSIG_OUTPUT2 -------- Release drawbar ------
local BlowOut = mc.OSIG_OUTPUT3 -------- Tool blow ------
local UmbrellaIn = mc.OSIG_OUTPUT5 -------- Swing Umbralla In ------
local UmbrellaOutSensor = mc.ISIG_Input20 -------- Umbralla Out Sensor ------
local UmbrellaInSensor = mc.ISIG_Input21 -------- Umbralla In Sensor ------
local numtools = 6
local ToolXPositions = {}
ToolCPositions[1] = 0.0
ToolCPositions[2] = 60.
ToolCPositions[3] = 120.
ToolCPositions[4] = 180.
ToolCPositions[5] = 240.
ToolCPositions[6] = 300.
function m6()
local GCode = ""
GCode = GCode .. string.format("M9\n") --Coolant Off
GCode = GCode .. string.format("M5\n") --Stop Spindle
GCode = GCode .. string.format("G04 P500\n")
mc.mcCntlGcodeExecuteWait(inst, GCode)
------ compare current and next tools ------
local SelectedTool = mc.mcToolGetSelected(inst)
local CurrentTool = mc.mcToolGetCurrent(inst)
if (SelectedTool == CurrentTool) then
mc.mcCntlSetLastError(inst, "Next tool = Current tool")
do return end
end
if (SelectedTool > numtools) or (SelectedTool <= 0) then
mc.mcCntlEStop(inst)
mc.mcCntlSetLastError(inst, "ERROR: Tool number out of range!")
do return end
else
end
------ Get current machine state ------
local CurFeed = mc.mcCntlGetPoundVar(inst, 2134)
local CurFeedMode = mc.mcCntlGetPoundVar(inst, 4001)
local CurAbsMode = mc.mcCntlGetPoundVar(inst, 4003)
------ Get Position data for current tool ------
Num1 = CurrentTool
CPos1 = ToolCPositions[CurrentTool]
------ Get position data for next tool ------
Num2 = SelectedTool
CPos2 = ToolCPositions[SelectedTool]
------ Move to tool change position ------
GCode = ""
GCode = GCode .. "G00 G90 G53 Z-2.0\n" --Z=Tool change position
GCode = GCode .. string.format("G00 G90 G53 C%.4f\n", CPos1) --Current tool Umbrella position
mc.mcCntlGcodeExecuteWait(inst, GCode)
--Swing umbrella to get tool in spindle
hsig1 = mc.mcSignalGetHandle(inst, UmbrellaIn)
mc.mcSignalSetState(hsig1, 1)
--Verify Umbrella is In
mc.mcSignalSetState(hsig,0)
mc.mcSignalSetState(hsig1,0)
mc.mcSignalSetState(hsig2,0)
GCode = ""
GCode = GCode .. "G04 P2000\n"
mc.mcCntlGcodeExecuteWait(inst, GCode)
hSig, rc = mc.mcSignalGetHandle(inst, UmbrellaInSensor)
hReg, rc = mc.mcSignalGetState(hSig)
if (hReg == 0) then
mc.mcCntlEStop(inst)
mc.mcCntlSetLastError(inst, "ERROR: Umbrella Not In Position!")
do return end
end
------ Unclamp tool ------
hsig = mc.mcSignalGetHandle(inst, DrawBarOut)
mc.mcSignalSetState(hsig, 1)
GCode = ""
GCode = GCode .. "G04 P2000\n"
mc.mcCntlGcodeExecuteWait(inst, GCode)
--Move to tool change Clearance position
GCode = ""
GCode = GCode .. "G00 G90 G53 Z0\n" --Z=Tool change clearance position
mc.mcCntlGcodeExecuteWait(inst, GCode)
--Swing umbrella to standby position
hsig1 = mc.mcSignalGetHandle(inst, UmbrellaIn)
mc.mcSignalSetState(hsig1, 0)
--Verify Umbrella is Out
mc.mcSignalSetState(hsig,0)
mc.mcSignalSetState(hsig1,0)
mc.mcSignalSetState(hsig2,0)
GCode = ""
GCode = GCode .. "G04 P2000\n"
mc.mcCntlGcodeExecuteWait(inst, GCode)
hSig, rc = mc.mcSignalGetHandle(inst, UmbrellaOutSensor)
hReg, rc = mc.mcSignalGetState(hSig)
if (hReg == 1) then
mc.mcCntlEStop(inst)
mc.mcCntlSetLastError(inst, "ERROR: Umbrella Not In Position!")
do return end
end
--turn on tool blowoff nozzles
hsig1 = mc.mcSignalGetHandle(inst, BlowOut)
mc.mcSignalSetState(hsig1, 1)
--Rotate Umbrella to next tool
GCode = ""
GCode = GCode .. string.format("G00 G90 G53 C%.4f", CPos2)
mc.mcCntlGcodeExecuteWait(inst, GCode)
--turn off tool blowoff nozzles
local hsig1 = mc.mcSignalGetHandle(inst, BlowOut)
mc.mcSignalSetState(hsig1, 0)
--swing umbrella to tool change position
hsig1 = mc.mcSignalGetHandle(inst, UmbrellaIn)
mc.mcSignalSetState(hsig1, 1)
--Verify Umbrella is In
mc.mcSignalSetState(hsig,0)
mc.mcSignalSetState(hsig1,0)
mc.mcSignalSetState(hsig2,0)
GCode = ""
GCode = GCode .. "G04 P2000\n"
mc.mcCntlGcodeExecuteWait(inst, GCode)
hSig, rc = mc.mcSignalGetHandle(inst, UmbrellaInSensor)
hReg, rc = mc.mcSignalGetState(hSig)
if (hReg == 0) then
mc.mcCntlEStop(inst)
mc.mcCntlSetLastError(inst, "ERROR: Umbrella Not In Position!")
do return end
end
--lower Z to tool change position
GCode = ""
GCode = GCode .. "G00 G90 G53 Z-2.0\n" --Z=tool change position
mc.mcCntlGcodeExecuteWait(inst, GCode)
--Clamp tool
local hsig = mc.mcSignalGetHandle(inst, DrawBarOut)
mc.mcSignalSetState(hsig, 0)
GCode = ""
GCode = GCode .. "G04 P1000\n"
mc.mcCntlGcodeExecuteWait(inst, GCode)
--Swing umbrella to standby position
hsig1 = mc.mcSignalGetHandle(inst, UmbrellaIn)
mc.mcSignalSetState(hsig1, 0)
--Verify Umbrella is Out
mc.mcSignalSetState(hsig,0)
mc.mcSignalSetState(hsig1,0)
mc.mcSignalSetState(hsig2,0)
GCode = ""
GCode = GCode .. "G04 P2000\n"
mc.mcCntlGcodeExecuteWait(inst, GCode)
hSig, rc = mc.mcSignalGetHandle(inst, UmbrellaOutSensor)
hReg, rc = mc.mcSignalGetState(hSig)
if (hReg == 1) then
mc.mcCntlEStop(inst)
mc.mcCntlSetLastError(inst, "ERROR: Umbrella Not In Position!")
do return end
end
end
------ Reset state ------
mc.mcCntlSetPoundVar(inst, 2134, CurFeed)
mc.mcCntlSetPoundVar(inst, 4001, CurFeedMode)
mc.mcCntlSetPoundVar(inst, 4003, CurAbsMode)
------ Set new tool ------
mc.mcToolSetCurrent (inst, SelectedTool)
mc.mcCntlSetLastError(inst, string.format("Tool change - Tool: %.0f", SelectedTool))
mc.mcCntlGcodeExecuteWait(inst, "G43 H"..SelectedTool)
end
if (mc.mcInEditor() == 1) then
m6()
end