Hello Guest it is May 14, 2021, 09:50:18 AM

Author Topic: Code working in a button but not working in Screen script or macro  (Read 150 times)

0 Members and 1 Guest are viewing this topic.

Offline DAAD

*
  •  103 103
    • View Profile
In my quest to get my machine working in dual z mode, i've got the following buttons up and running thanks to the forum:

Code: [Select]
-- To change Z from spindle to router
mc.mcGetInstance()
local OffsetX = -7.9266
local OffsetY = -156.5752
local Spindle = 2
local Router = 4
mc.mcCntlGcodeExecuteWait (0, "G90 G53 Z-20 A-20 F10000\n G91 X"..OffsetX.."Y"..OffsetY.."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
UnmapMotors()
mc.mcAxisMapMotor(0, mc.Z_AXIS, Router)
mc.mcAxisMapMotor(0, mc.A_AXIS, Spindle)
mc.mcCntlSetPoundVar(0, mc.SV_HEAD_SHIFT_X, OffsetX)
mc.mcCntlSetPoundVar(0, mc.SV_HEAD_SHIFT_Y, OffsetY )
mc.mcAxisSetPos(0, 3, pVal) ---Set Z Axis to A value
mc.mcAxisSetPos(0, 2, tVal) ---Set A Axis to Z value
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 i use the same code in a function in screen i had 2 problems :

1) Executing the gcode did not work
2) Swapping the values to retain my Z position doesn't work and workpiece zero get's off

Instead of the poundvar name i've tried to get the var number instead (5043/5044) but not avail...

Gcode screen below:

Code: [Select]
function UseSpindle()
local inst = mc.mcGetInstance()
local OffsetX = 7.9266
local OffsetY = 156.5752
local Spindle = 2
local Router = 4
mc.mcCntlMdiExecute (0, "G90 G53 Z-20 A-20 F10000\n G91 X"..OffsetX.."Y"..OffsetY.."F10000\n G90\n") --Both spindles in known position
wx.wxMilliSleep(50)
local pVal = mc.mcCntlGetPoundVar(0, mc.SV_CURRENT_ABS_Z) -- Get work position of Z-Axis and put in local var P  mc.SV_CURRENT_ABS_Z
local tVal = mc.mcCntlGetPoundVar(0, mc.SV_CURRENT_ABS_A) -- Get work position of A-Axis and put in local var T   mc.SV_CURRENT_ABS_A
wx.wxMilliSleep(50)
mc.mcAxisMapMotor(0, mc.Z_AXIS, Spindle)
mc.mcAxisMapMotor(0, mc.A_AXIS, Router)
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
wx.wxMilliSleep(50)
end