My first shot at a macro for my dual Z router
In the header before the gcode starts i want to use the M230 to check which tool is used and set the corresponding axis
Tools Under 100 = spindle tools above 100 = router
I know the code can get cleaned up further, but one step at a time!:-)
At the moment i get an error : string "function m230()" :5 'then' expected near '='
But can't find the fault, anybody has an idea?
--Check tool & set corresponding axis
--Motor 2 = Z
--Motor 4 = A
--Axis 2 = Z
--Axis 3 =A
function m230()
local inst = mc.mcGetInstance()
local selectedtool = mc.mcToolGetSelected(inst)
if selectedtool =< 100 then
Spindle()else
Router()
end
mc.mcToolSetCurrent (inst, selectedtool)
end
function Spindle()-- To change Z from router to spindle
local inst = mc.mcGetInstance()
mc.mcCntlGcodeExecuteWait (0, "G90 G53 Z-40 A-40 F10000\n G91 X7.8007 Y157.7648 F10000\n G90\n") --Both spindles in known position
local pVal = mc.mcCntlGetPoundVar(0, mc.SV_CURRENT_ABS_Z) -- Get work position of Z-Axis and put in local var P
local tVal = mc.mcCntlGetPoundVar(0, mc.SV_CURRENT_ABS_A) -- Get work position of A-Axis and put in local var T
mc.mcAxisUnmapMotor(0, mc.Z_AXIS, 4)
mc.mcAxisUnmapMotor(0, mc.A_AXIS, 2)
mc.mcAxisMapMotor(0, mc.Z_AXIS, 2)
mc.mcAxisMapMotor(0, mc.A_AXIS, 4)
mc.mcCntlSetPoundVar(0, mc.SV_HEAD_SHIFT_X, 0)
mc.mcCntlSetPoundVar(0, mc.SV_HEAD_SHIFT_Y, 0)
mc.mcAxisSetPos(0, 3, pVal) ---Set Z Axis op A waarde
mc.mcAxisSetPos(0, 2, tVal) ---Set A Axis op Z waarde
mc.mcSignalSetState(0, mc.OSIG_OUTPUT10, 0) -- marking we are using the spindle as Z (and possibly de-energize a SPDT to route the M3 signal).
wx.wxMilliSleep(500)
end
function Router()-- To change Z from spindle to router
local mc.mcGetInstance()
--local routerOffsetX = -7.8007
--local routerOffsetY = -157.7648
mc.mcCntlGcodeExecuteWait (0, "G90 G53 Z-40 A-40 F10000\n G91 X-7.8007 Y-157.7648 F10000\n G90\n")--Both spindles in known position
local pVal = mc.mcCntlGetPoundVar(0, mc.SV_CURRENT_ABS_Z) -- Get work position of Z-Axis and put in local var P
local tVal = mc.mcCntlGetPoundVar(0, mc.SV_CURRENT_ABS_A) -- Get work position of A-Axis and put in local var T
mc.mcAxisUnmapMotor(0, mc.Z_AXIS, 2)
mc.mcAxisUnmapMotor(0, mc.A_AXIS, 4)
mc.mcAxisMapMotor(0, mc.Z_AXIS, 4)
mc.mcAxisMapMotor(0, mc.A_AXIS, 2)
mc.mcCntlSetPoundVar(0, mc.SV_HEAD_SHIFT_X, -7.8007)
mc.mcCntlSetPoundVar(0, mc.SV_HEAD_SHIFT_Y, -157.7648 )
mc.mcAxisSetPos(0, 3, pVal) ---Set Z Axis op A waarde
mc.mcAxisSetPos(0, 2, tVal) ---Set A Axis op Z waarde
mc.mcSignalSetState(0, mc.OSIG_OUTPUT10, 1) -- marking we are using the router as Z (and possibly energize a SPDT to rout the M3 signal).
wx.wxMilliSleep(500)
if (mc.mcInEditor() == 1) then
m230()
end
For the m6 i'm wanting to create i would als want to use Spindle() and router() function.
Should i need to place these in the screen script? How do i call the in a macro?
Thanks in advance,
Adam
PS : Another error occurs when starting mach4: Failed to retrieve file C:*********x/m230.mcc (error 2: the system cannot find the specified file)
I've put the m230 in the macros folder under the profile i use.
PPS : I'm using the avidcnc screenset...