Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: DAAD on April 02, 2020, 02:52:57 PM
-
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
-
After some messing around, it' still this part of the script that messes up the machine movement.
I get wrong readouts counting up instead of swapping. In a button script the work flawless.
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
Would it make a difference if i try to get the values into a register instead?
Looked at adding a flag to the plc script, but it's a bridge too far for my current knowledge.
-
you can debug scripts and step through them using the Edit/Debug Scripts option in the Operator file menu. You can set a flag (breakpoint) by clicking near the line number area and press F5 until the program starts in that area. Then step through the program (F10 or F11) just look in the ZeroBrane editor Project file menu item to see what does what.
The entry to your program is the macro function name.
Basically you can step through an entire macro to see what is failing. You can hover your mouse over variables at each step (F10 or F11) to see what is what. This is all programmer talk but hopefully you gain some information from this response.
-
Thanks for the reply, will look into it!
The problem i have is some kind of "timing" related problem.
If i run it in the button script all runs fine, axis swap and the values swap accordingly.
But when i try to get it into an m6 macro or script screen, it starts to flip.
Values swap but add up or don't swap at all...
Think it has to do when the values are updated.
-
Do i need to be connected to the machine for debugging purposes?
-
If i want to debug, i can't go step by step.
I start with F5 , if i hit F10 to goto next step it does it one time, the next time the debugger skips all the rest and the debugger ends.
what am i doing wrong?
-
Use f11 not f10
-
Thanks,
finaly got i t working, needed to reinstall mach 4.
F11 does the trick