Hello Guest it is June 04, 2025, 10:57:56 AM

Author Topic: first macro try dual head  (Read 6050 times)

0 Members and 1 Guest are viewing this topic.

Offline DAAD

*
  •  103 103
first macro try dual head
« 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?

Code: [Select]
--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...

« Last Edit: March 24, 2020, 03:43:37 AM by DAAD »
Re: first macro try dual head
« Reply #1 on: March 24, 2020, 04:36:39 AM »
Hi,
try:
Code: [Select]
        if (selectedtool <= 100) then
Spindle()else
Router()
end

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline DAAD

*
  •  103 103
Re: first macro try dual head
« Reply #2 on: March 24, 2020, 04:55:01 AM »
hey Craig,

Changing =< to <= solved the error!
Thanks

Still get an error when loading mach4 that the macro cannot be found.


Offline DAAD

*
  •  103 103
Re: first macro try dual head
« Reply #3 on: March 24, 2020, 05:31:22 AM »
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...
Re: first macro try dual head
« Reply #4 on: March 24, 2020, 05:57:15 AM »
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
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline DAAD

*
  •  103 103
Re: first macro try dual head
« Reply #5 on: March 24, 2020, 06:12:59 AM »
problem is that the file is not on my pc. searched the folder and searched the whole pc but no compiled file.
Re: first macro try dual head
« Reply #6 on: March 24, 2020, 06:18:26 AM »
Hi,
not surprising that mach could not find it.

Can you indentify the directory with the .mcs source file in it?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline DAAD

*
  •  103 103
Re: first macro try dual head
« Reply #7 on: March 24, 2020, 06:28:43 AM »
The file is under Mach4/profiles /Avidcnc/macros
Re: first macro try dual head
« Reply #8 on: March 24, 2020, 06:36:06 AM »
Hi,
then that is where the .mcc file will be also.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline DAAD

*
  •  103 103
Re: first macro try dual head
« Reply #9 on: March 24, 2020, 06:37:46 AM »
problem is if i press compile, it states 100% compiled but there is no mcc file to find.