At the moment i'm trying to clean up a macro so i can implement different functions in a m6 toolchange file.
This is the macro i have at the moment that is working:
--Check tool & set corresponding axis
--Motor 2 = Z
--Motor 4 = A
--Axis 2 = Z
--Axis 3 =A
function m250() --set to use spindle BASIC
local inst = mc.mcGetInstance() --use spindle basic
local OffsetX = 7.9266
local OffsetY = 156.5752
local Spindle = 2
local Router = 4
mc.mcCntlGcodeExecuteWait (0, "G0 G90 G53 Z-20 A-20\n X"..OffsetX.."Y"..OffsetY.."\n G90\n") --GOTO WORKPIECE ZERO -Both spindles in known position
mc.mcAxisUnmapMotor(0, mc.Z_AXIS, Router)
mc.mcAxisUnmapMotor(0, mc.Z_AXIS, Spindle)
mc.mcAxisUnmapMotor(0, mc.A_AXIS, Spindle)
mc.mcAxisUnmapMotor(0, mc.A_AXIS, Router)
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)
local TempZ = mc.mcAxisGetPos (inst, 2) -- Get work position of Z-Axis
local TempA = mc.mcAxisGetPos (inst, 3) -- Get work position of A-Axis
mc.mcAxisSetPos(0, 3, TempZ) ---Set Z Axis on A Value
mc.mcAxisSetPos(0, 2, TempA) ---Set A Axis on Z Value
local h_OUTPUT10 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT10)
mc.mcSignalSetState(h_OUTPUT10, 0)
mc.mcCntlSetLastError(inst, 'm3 spindle signal ON') -- This will send a history / error window message
end
if (mc.mcInEditor() == 1) then
m250()
end
I've made a separate function Unmapmotors that i've placed in the screen script, Macro still working
--Check tool & set corresponding axis
--Motor 2 = Z
--Motor 4 = A
--Axis 2 = Z
--Axis 3 =A
function m260() --set to use spindle BASIC
local inst = mc.mcGetInstance() --use spindle basic
local OffsetX = 7.9266
local OffsetY = 156.5752
local Spindle = 2
local Router = 4
mc.mcCntlGcodeExecuteWait (0, "G0 G90 G53 Z-20 A-20\n X"..OffsetX.."Y"..OffsetY.."\n G90\n") --GOTO WORKPIECE ZERO -Both spindles in known position
UnmapMotors()
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)
local TempZ = mc.mcAxisGetPos (inst, 2) -- Get work position of Z-Axis
local TempA = mc.mcAxisGetPos (inst, 3) -- Get work position of A-Axis
mc.mcAxisSetPos(0, 3, TempZ) ---Set Z Axis on A Value
mc.mcAxisSetPos(0, 2, TempA) ---Set A Axis on Z Value
local h_OUTPUT10 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT10)
mc.mcSignalSetState(h_OUTPUT10, 0)
mc.mcCntlSetLastError(inst, 'm3 spindle signal ON') -- This will send a history / error window message
-- mc.mcCntlSetLogging(inst, 'm110() Turned OUTPUT10 ON') -- This will send a log window message
end
if (mc.mcInEditor() == 1) then
m260()
end
and the unmapmotors code - Credits to Steve
function UnmapMotors()
local inst = mc.mcGetInstance()
local Spindle = 2
local Router = 4
--Just unmapp everything to be safe.
local rc = mc.mcAxisUnmapMotor(0, mc.A_AXIS, Router)
if ((rc ~= mc.MERROR_MOTOR_NOT_FOUND) and (rc ~= mc.MERROR_NOERROR)) then
-- expect mc.MERROR_MOTOR_NOT_FOUND or mc.MERROR_NOERROR
return 1 -- failure
end
rc = mc.mcAxisUnmapMotor(0, mc.Z_AXIS, Router)
if ((rc ~= mc.MERROR_MOTOR_NOT_FOUND) and (rc ~= mc.MERROR_NOERROR)) then
-- expect mc.MERROR_MOTOR_NOT_FOUND or mc.MERROR_NOERROR
return 1 -- failure
end
rc = mc.mcAxisUnmapMotor(0, mc.A_AXIS, Spindle)
if ((rc ~= mc.MERROR_MOTOR_NOT_FOUND) and (rc ~= mc.MERROR_NOERROR)) then
-- expect mc.MERROR_MOTOR_NOT_FOUND or mc.MERROR_NOERROR
return 1 -- failure
end
rc = mc.mcAxisUnmapMotor(0, mc.Z_AXIS, Spindle)
if ((rc ~= mc.MERROR_MOTOR_NOT_FOUND) and (rc ~= mc.MERROR_NOERROR)) then
-- expect mc.MERROR_MOTOR_NOT_FOUND or mc.MERROR_NOERROR
return 1 -- failure
end
return 0 -- success
end
But when i try to make a function for the Axis values to swap,
The macro doesn't swap the values anymore. Also the output signal swap stops working.
Below is the function i have placed i the screen script.
it contains the same information as in the macro.
function SwapPosZA() --Place in Screenscript
local inst = mc.mcGetInstance()
local TempZ = mc.mcAxisGetPos (inst, 2) -- Get work position of Z-Axis
local TempA = mc.mcAxisGetPos (inst, 3) -- Get work position of A-Axis
mc.mcAxisSetPos(0, 3, TempZ) -- Replace A-axis value with Z value
mc.mcAxisSetPos(0, 2, TempA) -- Replace Z-axis value with A value
end
What an i doing wrong? Do i need to take another approach on howto clean up the macro?
Why does this not work as a function in the screen script?
All help is welcome,
Adam