Hello Guest it is June 04, 2024, 02:25:47 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - McRoth

Pages: 1 2 »
1
Mach4 Toolbox / Re: Umbrella Style M6 Script
« on: March 31, 2024, 09:41:13 PM »
Thanks rhtuttle!  That helped a lot!

I decided to modify the code in case I need to run programs with more than 6 tools so that I can manually change any tool over 6. Debugging was kind of a pain because I had to force I/O every time it was looking for something to be in a certain state.  Once I figured that out I was able to debug the program all the way thru, with less than 6 tools and more than 6.

Here's the updated and debugged code.  Hopefully it works, I'll find out in a while after I finish putting my machine back together.

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 ToolCPositions = {}
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")
GCode = GCode .. "G00 G90 G53 Z-2.0\n" --Z=Tool change position
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 <= 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)

if (SelectedTool > numtools) then
mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to continue") --Message at beginning of tool change
mc.mcCntlToolChangeManual(inst, true) --This will pause the tool change here and wait for a press of cycle start to continue

------ 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 complete - Tool: %.0f", SelectedTool))
mc.mcCntlGcodeExecuteWait(inst, "G43 H"..SelectedTool)

do return end
else
end

------ 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)  --Make sure hsig is off
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)  --Make sure hsig is off
GCode = ""
GCode = GCode .. "G04 P2000\n"
mc.mcCntlGcodeExecuteWait(inst, GCode)
hSig, rc = mc.mcSignalGetHandle(inst, UmbrellaOutSensor)
hReg, rc = mc.mcSignalGetState(hSig)
if (hReg == 0) 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)  --Make sure hsig is off
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)  --Make sure hsig is off
GCode = ""
GCode = GCode .. "G04 P2000\n"
mc.mcCntlGcodeExecuteWait(inst, GCode)
hSig, rc = mc.mcSignalGetHandle(inst, UmbrellaOutSensor)
hReg, rc = mc.mcSignalGetState(hSig)
if (hReg == 0) then
mc.mcCntlEStop(inst)
mc.mcCntlSetLastError(inst, "ERROR: Umbrella Not In Position!")
do return 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 complete - Tool: %.0f", SelectedTool))

mc.mcCntlGcodeExecuteWait(inst, "G43 H"..SelectedTool)
end

if (mc.mcInEditor() == 1) then
m6()
end


2
Mach4 Toolbox / Re: Umbrella Style M6 Script
« on: March 31, 2024, 02:23:21 PM »
How do I check the sent and received info?  I don't see an option for that?
Also, I did find my error, I had an end in the wrong place.  once I moved it to the correct position it runs correctly now.  Looks like I just need to get everything back together on my machine and try it out!

Corrected code:
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 ToolCPositions = {}
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

------ 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


3
Mach4 Toolbox / Re: Umbrella Style M6 Script
« on: March 30, 2024, 07:44:48 PM »
I completely forgot about the debug function! lol.  I ran it and found a couple of little things to fix but now I'm getting this error and I'm not sure why?
LuaExamples/m6.mcs:175: wxLua: Expected a 'number' for parameter 3, but got a 'nil'.
Function called: 'mcCntlSetPoundVar(number, number, nil)'
The script I modified from debugs with no issues even though I didn't change those sections?

Updated code:

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 ToolCPositions = {}
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)

if (mc.mcInEditor() == 1) then
m6()
end


4
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

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


5
I know this is an ancient thread, but I am working on a similar machine, just with a 6 tool umbrella.  Did you get this working?  If so, can you post the code? 
I'm modifying the code that CNC4PC has on their site and have the basics down, I think, but I need to get the umbrella rotation and counting worked out.  Also, it'll need to be homed in the machine homing script, but I don't think that'll be too bad.

Thanks!

Mike

6
HiCON Motion Controller / Re: Spindle Setup with 7866 control and VFD
« on: March 23, 2024, 10:11:21 AM »
Since Mach has those inputs I'm going to go ahead and wire them in and use them.

7
HiCON Motion Controller / Spindle Setup with 7866 control and VFD
« on: March 18, 2024, 09:10:36 PM »
I'm setting up my servo spindle with 0-10V control.  I have the quadrature encoder wired in, so I wanted to know if there is any need to wire in the outputs from the VFD for "Speed reach" and "zero speed" since the control is using the encoder it should already know? 
It also has a "warn output" which I'm guessing is to let the control know if there is an issue with the VFD.  How would I go about wiring this in correctly?
Thanks!

Mike

8
Mach4 Plugins / Re: Spindle Encoder OA+- OB+- OZ+- or EA+- EB+-?
« on: April 24, 2023, 03:17:14 PM »
Here's the pinout from the manual.

9
Mach4 Plugins / Re: Quadrature Spindle Encoder, ESS, OA+- OB+- OZ+-?
« on: April 24, 2023, 03:12:55 PM »
I also just noticed that the step/dir input for the driver wants a EA+/-, EB+/-, 4 wires, where ESS wants 2 wires.  How would I go about this?

Thanks,
Mike

10
Mach4 Plugins / Spindle Encoder OA+- OB+- OZ+- or EA+- EB+-?
« on: April 24, 2023, 09:26:45 AM »
I'm working on trying to hook up this servo spindle motor via step/dir: https://www.automationtechnologiesinc.com/products-page/cnc-milling-spindle/3-7kw-2-2kw-8000rpm-milling-spindle-motor-and-inverter-220v , the 3.7KW 220V single phase version to my ESS with a C82 board.  ESS only wants an A, B and Index input, but this encoder has OA+- OB+- OZ+- and/or EA+- EB+-.  How would I go about getting this to work?  Do I need some kind of converter?

Thanks!

Mike

Pages: 1 2 »