Sure...
m6 - I removed the m5 from it and used a mc.mcSpindleSetDirection(inst, mc.MC_SPINDLE_OFF) to stop the spindle.
function m6()
local inst=mc.mcGetInstance()
mc.mcCntlSetLastError(inst, 'Tool change in progress')
------ Get and compare next and current tools ------
local SelectedTool = mc.mcToolGetSelected(inst)
local CurrentTool = mc.mcToolGetCurrent(inst)
if (SelectedTool == CurrentTool) then
mc.mcCntlSetLastError(inst, "Next tool = Current tool")
mc.mcCntlGcodeExecute(inst, "G43 H"..CurrentTool) --Turn on tool length offset for current tool
do return end
end
mc.mcCntlSetLastError(inst, 'Break 0')
------ Define slide distance and direction ------
------ Only 1 of these should have a non-zero value -----
------ Changing from a positive to negative slide value, or vice-versa, will change the direction that the tool slides into the tool fork -----
local XSlide = 0.00
local YSlide = 2.00
local dwell = 8.00
------- Declare Position Variables ------
local XPos = 0
local YPos = 0
local ZPos = 0
------ For spindles that have a partial tool push out, define the amount of movement here -----
local ZBump = 0.100
------ Define the OUTPUT# for the drawbar signal -----
local DrawBarOut = mc.OSIG_OUTPUT6
------ Define the OUTPUT# for the dusthood signal -----
local DustHood = mc.OSIG_OUTPUT7
------ Get current state ------
local CurFeed = mc.mcCntlGetPoundVar(inst, 2134)
local CurFeedMode = mc.mcCntlGetPoundVar(inst, 4001)
local CurAbsMode = mc.mcCntlGetPoundVar(inst, 4003)
------ Raise Dust Hood if dust hood is down ------
local dhsig = mc.mcSignalGetHandle(inst, DustHood)
local dhstate = mc.mcSignalGetState(dhsig)
if (dhstate == 0) then
mc.mcSignalSetState(dhsig, 1)
end
------ Check to if spindle is on, if on, turn off spindle -------
dir = mc.mcSpindleGetDirection(inst)
if dir ~= mc.MC_SPINDLE_OFF then
mc.mcSpindleSetDirection(inst, mc.MC_SPINDLE_OFF)
mc.mcCntlSetLastError(inst, "Turn off spindle")
hreg = mc.mcRegGetHandle(inst, "iRegs0/lastSpindleStopTime")
mc.mcRegSetValue(hreg, os.time())
end
------ Check when was last turned off and pause to allow time for spindle to stop ------
local hreg = mc.mcRegGetHandle(inst, "iRegs0/lastSpindleStopTime")
local SpindleStopTime = mc.mcRegGetValue(hreg)
local currentClockTime = os.time()
local secondsSinceSpindleStop = currentClockTime - SpindleStopTime
if secondsSinceSpindleStop > 0 then
dwell = dwell - secondsSinceSpindleStop
end
if dwell > 0 then
local GCode = ""
GCode = GCode .. string.format("G04 P%.4f", dwell)
mc.mcCntlGcodeExecuteWait(inst, GCode)
--mc.mcCntlSetLastError(inst, string.format("Wait for spindle to stop. Dwell time: %.0", dwell)
end
------ Move to current tool change position ------
local tool = CurrentTool
--You will need to enter the tool position below.
--Once you enter them, copy and paste the area defined
--below to the second set of positions further down in
--the script. The two sets of tool positions must match
--exactly, or unexpected motion will occur!!!
-----------------Copy Start-------------------
----- Define Tool Postions ------
--Tool 1--
if tool == 1 then
XPos = 7.161
YPos = 49.144
ZPos = -6.283
--Tool 2--
elseif tool == 2 then
XPos = 11.447
YPos = 49.144
ZPos = -6.283
--Tool 3--
elseif tool == 3 then
XPos = 15.733
YPos = 49.144
ZPos = -6.283
--Tool 4--
elseif tool == 4 then
XPos = 20.005
YPos = 49.144
ZPos = -6.283
--Tool 5--
elseif tool == 5 then
XPos = 24.322
YPos = 49.144
ZPos = -6.283
--Tool 6--
elseif tool == 6 then
XPos = 28.593
YPos = 49.144
ZPos = -6.283
--Tool 7--
elseif tool == 7 then
XPos = 32.859
YPos = 49.144
ZPos = -6.283
--Tool 8--
elseif tool == 8 then
XPos = 37.126
YPos = 49.144
ZPos = -6.283
--Tool 9--
elseif tool == 9 then
XPos = 41.432
YPos = 49.144
ZPos = -6.283
--Tool 10--
elseif tool == 10 then
XPos = 45.755
YPos = 49.144
ZPos = -6.283
---------------Copy Stop------------------
else
wx.wxMessageBox("Invalid tool #. Cancelling tool change!\nYour requested tool will now be set as the current tool in the spindle.\n****Ensure that the tool station that you have selected is empty!****")
mc.mcToolSetCurrent(inst, SelectedTool)
mc.mcCntlGcodeExecute(inst, "G43 H"..SelectedTool) --Turn on tool length offset for selected tool
------ Lower DustHood if originally was down at start of m6------
if (dhstate == 0) then
mc.mcSignalSetState(dhsig, 0)
else
mc.mcSignalSetState(dhsig, 1)
end
do return end
end
local GCode = ""
GCode = GCode .. "G00 G90 G53 Z0.0\n"
GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", (XPos-XSlide), (YPos-YSlide))
GCode = GCode .. string.format("G00 G90 G53 Z%.4f\n", ZPos)
GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", XPos, YPos)
mc.mcCntlGcodeExecuteWait(inst, GCode)
------ Open drawbar ------
local hsig = mc.mcSignalGetHandle(inst, DrawBarOut)
mc.mcSignalSetState(hsig, 1)
------ Raise spindle, after releasing tool ------
GCode = ""
GCode = GCode .. string.format("G01 G90 G53 Z-3.00 F250.0\n")
mc.mcCntlGcodeExecuteWait(inst, GCode)
------ Move to next tool change position ------
tool = SelectedTool
-----------------Copy Start-------------------
----- Define Tool Postions ------
--Tool 1--
if tool == 1 then
XPos = 7.161
YPos = 49.144
ZPos = -6.283
--Tool 2--
elseif tool == 2 then
XPos = 11.447
YPos = 49.144
ZPos = -6.283
--Tool 3--
elseif tool == 3 then
XPos = 15.733
YPos = 49.144
ZPos = -6.283
--Tool 4--
elseif tool == 4 then
XPos = 20.005
YPos = 49.144
ZPos = -6.283
--Tool 5--
elseif tool == 5 then
XPos = 24.322
YPos = 49.144
ZPos = -6.283
--Tool 6--
elseif tool == 6 then
XPos = 28.593
YPos = 49.144
ZPos = -6.283
--Tool 7--
elseif tool == 7 then
XPos = 32.859
YPos = 49.144
ZPos = -6.283
--Tool 8--
elseif tool == 8 then
XPos = 37.126
YPos = 49.144
ZPos = -6.283
--Tool 9--
elseif tool == 9 then
XPos = 41.432
YPos = 49.144
ZPos = -6.283
--Tool 10--
elseif tool == 10 then
XPos = 45.755
YPos = 49.144
ZPos = -6.283
---------------Copy Stop------------------
else
wx.wxMessageBox("Invalid tool #. Retrieving previous tool!")
SelectedTool = CurrentTool
mc.mcCntlGcodeExecute(inst, "G43 H"..CurrentTool) -- Turn on Tool Length Offset to CurrentTool
mc.mcSignalSetState(dhsig, 0) -- Lower DustHood
end
GCode = ""
GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", XPos, YPos)
GCode = GCode .. string.format("G00 G90 G53 Z%.4f\n", ZPos + ZBump)
mc.mcCntlGcodeExecuteWait(inst, GCode)
------ Clamp drawbar ------
mc.mcSignalSetState(hsig, 0)
GCode = ""
GCode = GCode .. string.format("G01 G90 G53 Z%.4f F50.0\n", ZPos)
GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", (XPos-XSlide), (YPos-YSlide))
mc.mcCntlGcodeExecuteWait(inst, GCode)
------ Move Z to home position ------
GCode = ""
mc.mcCntlGcodeExecuteWait(inst, "G00 G90 G53 Z0.0\n")
mc.mcCntlGcodeExecute(inst, "G43 H"..SelectedTool) -- Turn on Tool Length Offset to selected tool
------ 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))
------ Lower DustHood if originally was down at start of m6------
if (dhstate == 0) then
mc.mcSignalSetState(dhsig, 0)
else
mc.mcSignalSetState(dhsig, 1)
end
end
if (mc.mcInEditor() == 1) then
m6()
end
m30
function m30()
local inst = mc.mcGetInstance("m30()");
local msg = "Avid: m30()";
local rc = mc.MERROR_NOERROR;
-- Set Part Finish output signal
local hsig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_PRTSF);
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlLog(
inst,
string.format("%s failure to get signal handle, rc=%s", msg, rc),
"",
-1
);
else
mc.mcSignalSetState(hsig, 1);
end
-- Save persistent cycle time
local cycleTime = mc.mcCtrlGetRunTime(inst);
local hreg, rc = mc.mcRegGetHandle(inst, "iRegs0/AvidCNC/GCode/Last_Cycle_Time");
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlLog(
inst,
string.format("%s failure to get register handle, rc=%s", msg, rc),
"",
-1);
else
mc.mcRegSetValueString(hreg, tostring(cycleTime));
end
--[[ Additional items that need to be included so
our custom M30 macro perfrorms all the functions
of the stock M30 macro.
--]]
-- Cutter comp, coolant, mist, and spindle OFF
rc = mc.mcCntlGcodeExecute(inst, "G40\nM09\nM05");
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlLog(
inst,
string.format("%s failure to execute gcode, rc=%s", msg, rc),
"",
-1
);
end
end
if (mc.mcInEditor() == 1) then
m30()
end