Hello Guest it is March 29, 2024, 10:06:01 AM

Author Topic: How to set an active tool offset.  (Read 1985 times)

0 Members and 1 Guest are viewing this topic.

How to set an active tool offset.
« on: March 16, 2018, 03:34:23 PM »
Once Mach4 Lathe is opened; I have a Dialogue Box that pops up asking the operator which tool in the turret is active.  

We don't have any gang style tools so our offsets are straight forward.  T101 T202 .... T606.  What I need to do is go ahead and set the current offset active to whatever tool is active.  How can I do this in the PLC Script.

I found this in the PLC Script:  m_currentOffset = mc.mcCntlGetPoundVar(inst, mc.SV_CUR_LENGTH_INDEX)

I changed it to "SetPoundVar" and it did change the Active Offset Number that is on the screen.  But it didn't update the current offset position like I thought it would.

I could probably call a tool change to T101 .... T606, but now I'm curious to see if I can do this in code.
Chad Byrd
Re: How to set an active tool offset.
« Reply #1 on: March 16, 2018, 04:09:33 PM »
This will work.  
But I am still want to know if you are able to do this another way.

Here is the macro for proof of concept.
function m202()
local inst = mc.mcGetInstance()
local ActualTool = wx.wxGetNumberFromUser("What tool is in the turret?", "Tool # ","Current Tool", 1, 1, 6) -- Default, Min, Max.
local rc = ActualTool
if rc == -1 then
     wx.wxMessageBox("Set the current tool to the actual tool.")
else
     mc.mcToolSetCurrent(inst, ActualTool)
     mc.mcCntlSetLastError(inst, "T" .. tostring(ActualTool) .. "0" .. tostring(ActualTool))
     mc.mcCntlGcodeExecute(inst, "T" .. tostring(ActualTool) .. "0" .. tostring(ActualTool))  --This uses the Tool Number that was entered into the Dialogue Box and pieces together a T### Command real fast.
end

end --m202

if (mc.mcInEditor() == 1) then
 m202()
end  

Chad Byrd
Re: How to set an active tool offset.
« Reply #2 on: March 16, 2018, 04:24:49 PM »
So..
This works in a macro.
It doesn't work when it is run from the Screen Script.

I have this function in the Screen Load script.  The PLC Script calls this function on its 25th run.  It will Set the current tool and give me a message.  But it does not run the GcodeExecute or the MDIExecute.  I tried it with both.
Chad Byrd
Re: How to set an active tool offset.
« Reply #3 on: March 16, 2018, 04:36:48 PM »
It doesn't work because the machine is not enabled.   I wonder if there is a way to capture the first instance the machine is enabled so it can run the SetCurrentToolFunction()
Chad Byrd
Re: How to set an active tool offset.
« Reply #4 on: March 21, 2018, 06:15:53 PM »
Anyone has any ideas about this?
Chad Byrd
Re: How to set an active tool offset.
« Reply #5 on: March 21, 2018, 06:41:39 PM »
Hi,
this pretty much sums up what I know about it:

http://www.machsupport.com/forum/index.php/topic,36855.0.html

Could you use a signal and the testcount increment to determine when to run the script?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: How to set an active tool offset.
« Reply #6 on: March 21, 2018, 06:55:53 PM »
Hey Craig,
Just to let you know what I'm doing...
I'm having my PLC Script run my SetCurrentTool() function on the 25th run.  This way the operator can tell Mach what tool is in the turret.  
I need to activate the tool offset while I'm doing this.

I've used the OSIG_MACHINE_ENABLED output handle before.  

.......................

While writing this post I thought of a possibility.  I remember a register I can access.    
There is a register counting how many times the Mach has been enabled and disabled.  I can just grab the first instance of this in the PLC Script and run my Function.  


Craig,
Do you know the command to get the core registers?  I've only gotten Var# and Registers I've made.
Chad Byrd
Re: How to set an active tool offset.
« Reply #7 on: March 21, 2018, 07:03:24 PM »
Here is a screenshot of the register I can use.
Chad Byrd
Re: How to set an active tool offset.
« Reply #8 on: March 21, 2018, 07:59:09 PM »
Alrighty,
I've found a solution.
This snippet of code gets the core/inst register of CmdEnable count.  
When it is "1" then it will run my SetCurrentTool() function and adds 1 to the CmdEnable register so it doesn't keep looping.
Here is the Screen Load Script and the PLC Script that I'm using to accomplish this task.

--Set Current Tool Screen Load Script.
function SetCurrentTool()
     local inst = mc.mcGetInstance()
     local ActualTool = wx.wxGetNumberFromUser("What tool is in the turret?", "Tool # ","Current Tool", 1, 1, 6) -- Default, Min, Max.
     local rc = ActualTool
     if rc == -1 then
         wx.wxMessageBox("Set the current tool to the actual tool.")
     else
         mc.mcToolSetCurrent(inst, ActualTool)
         mc.mcCntlSetLastError(inst, "T" .. tostring(ActualTool) .. "0" .. tostring(ActualTool))
         mc.mcCntlGcodeExecute(inst, "T" .. tostring(ActualTool) .. "0" .. tostring(ActualTool))  --This uses the Tool Number that was entered into the Dialogue Box and pieces together a T### Command real fast.
     end
end--SetCurrentTool()

--Set Current Tool PLC Script
local hReg = mc.mcRegGetHandle(inst, "core/inst/CmdEnable");
local EnableCount = mc.mcRegGetValue(hReg)
if EnableCount == 1 then
     SetCurrentTool()
     mc.mcRegSetValue(hReg, 2)
end
« Last Edit: March 21, 2018, 08:02:23 PM by Cbyrdtopper »
Chad Byrd