Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Andygraphy on January 20, 2020, 05:13:15 PM
-
hello guys,
i tried out to create an own m6 tool change macro for my emco pcturn 55 lathe conversion with an pokeys57cnc board on Mach4. I want to learn and understand lua coding.
some function like if-then-else are not the problem.... my problems are to understand whats the codes are for like "mc.mcSignalSetState(..)" or "mc.mcToolGetCurrent(...)" or .....= math.tointeger(....).
Is there maybe a list/description of all possible "codes" in Mach4/lua which i can use?
kind regards
Andy
-
Hi,
they are called API's and they are documented in API.chm in Mach4 Docs folder, all alternately select API.chm from the
list when you click <Help Docs> when Mach is enabled.
Craig
-
Hi Craig,
thanks! :) i will look at it tomorrow. Is it maybe possible to get support from you to create the m6 macro?
andy
-
Hi Craig,
thanks! :) i will look at it tomorrow. Is it maybe possible to get support from you to create the m6 macro?
this is where i`am right now...
to understand it... i have a 6 position toolchanger which is driven by a 24V dc motor on "output3"only in one direction, the reference will be scanned by a encoder signal on "input0" and the tool positions are scanned too by another encoder light source "input4" ....for the input4 -> on every tool position i get a "1" signal from the encoder.
I need a loop to count the tool positions, because the only way of the Toolnumbers are 1,2,3,4,5,6,1,2,3,4,5,6,1,2....and so on... the only thing that works now, is if i write in my MDI "M06 T0202", the motor starts to move... but it doesn`t count the signals from input 4 and didn`t stop the motor.
Before of all... i made a reference from the tool changer so that it starts from tool number 1 .. that works.
function m6()
local inst = mc.mcGetInstance()
local out3= mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT3);
local outstate = mc.mcSignalGetState(out3);
local signalfait = mc.ISIG_INPUT4
local max = "6" --maximal tools
local selectedTool = mc.mcToolGetSelected(inst) --selected tool
selectedTool = math.tointeger(selectedTool)
local currentTool = mc.mcToolGetCurrent(inst) -- current tool
currentTool = math.tointeger(currentTool)
local newTool = mc.mcToolGetCurrent(inst) -- new tool
newTool = math.tointeger(newTool)
mc.mcCntlSetLastError(inst, " "); --delete error line
mc.mcCntlGcodeExecuteWait(inst,"G53 G0 x0 \n G53 G0 Z0") -- go to safety position
if (selectedTool == currentTool)then --if selected tool is equal to current tool then
mc.mcCntlSetLastError(inst, "new tool = old tool, toolchange not possible"); -- Error
else
if (selectedTool > max) then --if selected tool is greater than max tools (6)
wx.wxMessageBox("tool number to high! max tools = "..tostring(max)) -- Error text
else
mc.mcSignalSetState(out3, true) --Output3 - Toolchange Motor o
while (selectedTool ~= currentTool) do --start loop
local selectedTool = mc.mcToolGetSelected(inst)
selectedTool = math.tointeger(selectedTool)
local currentTool = mc.mcToolGetCurrent(inst)
currentTool = math.tointeger(currentTool)
local newTool = mc.mcToolGetCurrent(inst)
newTool = math.tointeger(newTool)
if (mc.mcSignalGetState(mc.mcSignalGetHandle(inst, mc.ISIG_INPUT4)) == 1) then --if "1" Signal on Input4 ,then
newTool = currentTool + 1 -- new tool = current tool + 1
mc.mcToolSetCurrent(inst,newTool) -- set current tool display to current tool number
if (newTool > max) then -- if new tool is greater then max tool,then
newTool = 1 -- new tool = 1
if (newTool = selectedTool) then --if new tool is equal to selected tool, then
break --stop the loop
mc.mcSignalSetState(out3, false) --Output 3 off - toolchange motor stop
mc.mcCntlGcodeExecuteWait(inst,"G43 H??") -- set offset display to new tool offset
mc.mcToolSetCurrent(inst,newTool) -- set current tool display to current tool number
end
end
end
end
end
if (mc.mcInEditor() == 1) then
m6()
end
------------------------------------------------------
hopefully you can help and understand me
andy from germany