I managed to get a small M6 macro to work in a sense. I dont understand how the debugger helps me with my mistakes though. A section of this code is working on my machine. Call a toolchange it goes to position. Tool changes. All good.
What doesnt work is the tool will not return to its original position this line:
--mc.mcCntlGcodeExecuteWait (inst, "G90 G53 G0 X"..xstart.. Y"..ystart..") Take the tool back to original position this doesnt seem to work.
My other scripting problem. If the machine is not homed, (obviously) on first attempt my 150kg gantry almost raced right off the machine. E-Stop - pleased I have one of those.
if yhomed = true then = return -- check if y is homed
else mc.mcCntlSetLastError (inst "Please home your Y Axis")
end
I tried debugging but dont know what to do. if someone has time to give me the bits I went wrong on would be appreciated. I know this is a standard M6 thing. But if I can get this sorted I would be able to use the same info for the other bits and pieces I need to program into my machine. Know what I mean? Big thanks in advance. B
Full Code:
function m6()
local inst = mc.mcGetInstance()
local selectedTool = mc.mcToolGetSelected(inst)
selectedTool = math.tointeger(selectedTool)
local currentTool = mc.mcToolGetCurrent(inst)
currentTool = math.tointeger(currentTool)
local ystart = mc.mcAxisGetPos (inst, 1)
local xstart = mc.mcAxisGetPos (inst, 0)
local zhomed = mcAxisIsHomed (mInst, Z_AXIS, 2)
local xhomed = mcAxisIsHomed (mInst, X_AXIS, 0)
local yhomed = mcAxisIsHomed (mInst, Y_AXIS, 1)
if zhomed == true then = return -- check if z is homed
else mc.mcCntlSetLastError (inst "Please home your Z Axis")
end
if xhomed = true then = return -- check if x is homed
else mc.mcCntlSetLastError (inst "Please home your X Axis")
end
if yhomed = true then = return -- check if y is homed
else mc.mcCntlSetLastError (inst "Please home your Y Axis")
end
if selectedTool == currentTool then
mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do Dork")
else
--Remove this line if you would not like the Z axis to move
mc.mcCntlGcodeExecuteWait (inst, "G90 G53 G0 Z-10");--Move the Z axis all the way up
mc.mcCntlGcodeExecuteWait (inst, "G90 G53 G0 Y60 X35") -- Move to tool change position
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
--mc.mcCntlGcodeExecuteWait (inst, "G90 G53 G0 X"..xstart.. Y"..ystart..") Take the tool back to original position this doesnt seem to work.
mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. " Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
mc.mcToolSetCurrent(inst, selectedTool)
end
end
if (mc.mcInEditor() == 1) then
m6()
end