Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: gabedrummin on March 08, 2021, 12:27:14 PM
-
I have a lathe on mach4 control uses a Pokeys 57e and a cnc4pc m16 .The Lathe has a Tool changer is there a way to make the tool change counter read tool 0 offset 0 after I home the turret ? If so how do I do this ? Thank you all .
-
At the end of your homing script add:
rc = mc.mcToolSetCurrent(inst,0)
This will set the current tool to tool zero but it will not set the offset. There is an api call to get the current offset but not one to set it :(
In theory you should be able to set the register for that which is supposed to be #2032 and the tool #2029 according to some docs that spell out the pound variables. However the following code always shows zero for each entry and when you display the variables through the diagnostics menu those values don't change so I don't know what are the real registers currently. build 4612.
local inst=mc.mcGetInstance()
local val
local rc = mc.mcToolSetCurrent(inst,2)
val,rc=mc.mcCntlGetPoundVar(inst,2029)
val,rc=mc.mcCntlGetPoundVar(inst,2032)
rc = mc.mcToolSetCurrent(inst,0)
val,rc=mc.mcCntlGetPoundVar(inst,2029)
val,rc=mc.mcCntlGetPoundVar(inst,2032)
HTH
RT
-
Found another doc with enum list, code should be:
local inst=mc.mcGetInstance()
rc=mc.mcCntlSetPoundVar(inst, mc.SV_CUR_TOOL_NUMBER,0)
rc=mc.mcCntlSetPoundVar(inst, mc.SV_CUR_LENGTH_INDEX,0)
-
Where is the homing script located ? Thank you for your help .
-
It's in the screen load script: RefAllHome() which is called when you hit the Ref All Button. If your not familiar with screen editing Brianna has a video in the section above.
-
---------------------------------------------------------------
-- Ref All Home() function.
---------------------------------------------------------------
function RefAllHome()
mc.mcAxisDerefAll(inst) --Just to turn off all ref leds
mc.mcAxisHomeAll(inst)
coroutine.yield() --yield coroutine so we can do the following after motion stops
----See ref all home button and plc script for coroutine.create and coroutine.resume
local hReg, rc = mc.mcRegGetHandle(inst, "iRegs0/CurrentSlot")
rc = mc.mcRegSetValue(hReg, 0)
mc.mcToolSetCurrent(inst, 0)
wx.wxMilliSleep(2000)
wx.wxMessageBox('Referencing is complete')
end
So I would insert it just before the End comment ?
-
---------------------------------------------------------------
-- Ref All Home() function.
---------------------------------------------------------------
function RefAllHome()
mc.mcAxisDerefAll(inst) --Just to turn off all ref leds
mc.mcAxisHomeAll(inst)
coroutine.yield() --yield coroutine so we can do the following after motion stops
----See ref all home button and plc script for coroutine.create and coroutine.resume
local hReg, rc = mc.mcRegGetHandle(inst, "iRegs0/CurrentSlot")
rc = mc.mcRegSetValue(hReg, 0)
rc = mc.mcToolSetCurrent(inst, 0)
rc=mc.mcCntlSetPoundVar(inst, mc.SV_CUR_LENGTH_INDEX,0)
wx.wxMilliSleep(2000)
wx.wxMessageBox('Referencing is complete')
end
That should work.
I think RH has the right way to do this as you can't call G43 H0 to set the offset.
Pound vars are nice :)
Let me know if that works Gabe.
-
Your suggestions worked . Thank you guys .