Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: DAAD on March 24, 2020, 03:33:33 AM
-
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...
-
Hi,
try:
if (selectedtool <= 100) then
Spindle()else
Router()
end
Craig
-
hey Craig,
Changing =< to <= solved the error!
Thanks
Still get an error when loading mach4 that the macro cannot be found.
-
found out the issue. I need also an .MCC file for this macro to run.
I can compile the m230.MCS in the editor, but how do i save the compiled file?
The editor just says compilation successfull, but the mcc file i can't find anywhere...
-
Hi,
the compiler puts the complied (.mcc) file in the same directory as the source (.mcs) file.
Macros of the type m230() should be in the Macros directory of your profile. The file tree at the lefthand side
of the ZeroBrane editor page should allow you to navigate to it.
Craig
-
problem is that the file is not on my pc. searched the folder and searched the whole pc but no compiled file.
-
Hi,
not surprising that mach could not find it.
Can you indentify the directory with the .mcs source file in it?
Craig
-
The file is under Mach4/profiles /Avidcnc/macros
-
Hi,
then that is where the .mcc file will be also.
Craig
-
problem is if i press compile, it states 100% compiled but there is no mcc file to find.
-
Finally got it working.
When compiling the file is not visible.
I needed to restart mach 4 for the file to become visible!