Hello Guest it is March 28, 2024, 12:30:28 PM

Author Topic: Turn tool turret macro  (Read 4178 times)

0 Members and 1 Guest are viewing this topic.

Turn tool turret macro
« on: April 21, 2020, 05:32:54 AM »
Hello,

I'm working on a tool changer turret for a lathe, but I'm having an issue I can't seem to overcome.

I have PLC controlling all of the logic behind the tool changer and this works absolutely perfectly! I am using a brain to send the value from CurrentTool through modbus. This works if I manually put a value in the Tool No DRO. However, If I run my macro, the Tool No DRO does not change and the PLC does not get the new tool number.

I input in the MDI: M6 T0101 for example

Am I missing something obvious here please?

Thanks,

M6 Start macro:

Code: [Select]
'-----------------------------------------------------------------------
'CYCLONE - Auto tool changer (8 pos turret type)
'V1.0
'-----------------------------------------------------------------------

'-----------------------------------------------------------------------
'CONFIG
'-----------------------------------------------------------------------


Tool = GetSelectedTool()
OldTool = GetCurrentTool()
NewTool = Tool
MaxToolNum = 8 'Max number of tools for the changer

'-----------------------------------------------------------------------
'MACRO START
'-----------------------------------------------------------------------
IsActive(INPUT1)
DeActivateSignal(OUTPUT6) 'Make sure signal to PLC is negative
'code"G91 G28 Z0" 'set incremental, return home via X first
'While IsMoving()
'Wend

While NewTool > MaxToolNum 'Dont allow tool number greater 8
Message("MAX TOOL NUMBER = 8")
Wend

While NewTool < 0 'Dont allow tool number less than 1
Message("INVALID TOOL NUMBER")
Wend

If NewTool = OldTool Then
Call ToolComplete
Else
If IsActive(INPUT1) Then 'ok signal from PLC
Call DoToolChange
Else
Message("TURRET NOT READY!")
End If
End If
End

'----------------------------------------------------------------------
'TOOL CHANGE
'----------------------------------------------------------------------

Sub DoToolChange()

SetCurrentTool(NewTool) 'Update the tool DRO
Call ActivateSignal(OUTPUT6) 'Set tool change allowed signal to PLC
SetTimer(1)
t = GetTimer(1)
sleep 10

If Not IsActive(INPUT1) Then  'If input goes low, turret is moving

While Not IsActive(INPUT1) 'While the turret is moving, count down

If IsActive(INPUT1) Then 'If input goes high again, tool has cycled
Call ToolComplete
Else
If t > 4000 Then
Call ToolFailed
End If
End If

sleep 10
Wend

End If


End Sub
     
 

'----------------------------------------------------------------------
'TOOL COMPLETE
'----------------------------------------------------------------------

Sub ToolComplete()
DeActivateSignal(OUTPUT6)
End Sub


'----------------------------------------------------------------------
'TOOL FAILED
'----------------------------------------------------------------------

Sub ToolFailed()
f = 1
DeActivateSignal(OUTPUT6)
While f = 1
Message("TURRET TIMEOUT")
Wend

End Sub               

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: Turn tool turret macro
« Reply #1 on: April 21, 2020, 05:51:15 AM »
you have to tell the System the new Toolnumber by:

    SetCurrentTool( Tool )
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: Turn tool turret macro
« Reply #2 on: April 21, 2020, 06:14:16 AM »
Hi,

Thanks, yes the macro does this within the DoToolChange() subroutine, but it does not update the Tool No DRO for some reason...


Offline Graham Waterworth

*
  • *
  •  2,668 2,668
  • Yorkshire Dales, England
    • View Profile
Re: Turn tool turret macro
« Reply #3 on: April 21, 2020, 06:54:20 AM »
To change tool on Mach4 lathe there is no M6 command just call T0203 for tool 2 offset 3 and I think there are different #vars for the tool and the offset number so you could pick that up and send that to the PLC.
Without engineers the world stops

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: Turn tool turret macro
« Reply #4 on: April 21, 2020, 07:16:53 AM »
if i test here the SetCurrentTool() OEMDro(824) is updated imediatelly
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: Turn tool turret macro
« Reply #5 on: April 21, 2020, 07:32:46 AM »
Hmm, That is strange...

If I edit the M6Start file to be just: SetCurrentTool(6) for example and type M6 into the MDI and enter, nothing happens... this should just make tool number 6, right?

@Graham Waterworth, Thanks I had considered moving over to mach4 eventually, but at the time I started the retrofit a fee years ago, CsLabs who make my controller hadn't got a stable plugin for mach4, I'm not sure if this is still the case now?

Offline Graham Waterworth

*
  • *
  •  2,668 2,668
  • Yorkshire Dales, England
    • View Profile
Re: Turn tool turret macro
« Reply #6 on: April 21, 2020, 07:37:52 AM »
Mach3 lathe is the same T0203
Without engineers the world stops
Re: Turn tool turret macro
« Reply #7 on: April 21, 2020, 07:43:59 AM »
Yeah, that does nothing either, I have tried this, maybe my version of mach3 isn't working properly?

Offline Graham Waterworth

*
  • *
  •  2,668 2,668
  • Yorkshire Dales, England
    • View Profile
Re: Turn tool turret macro
« Reply #8 on: April 21, 2020, 07:50:23 AM »
In Mach3 macros you need to give it time to update DRO's so when you set the SetCurrentTool() or any other DRO you need to do a short Sleep() of say 50 to 100 to allow Mach3 to update in the background.
Without engineers the world stops

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: Turn tool turret macro
« Reply #9 on: April 21, 2020, 08:02:47 AM »
put a MSGBox("M6 call") at the beginn of M6 macro just to see that it getting called.
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.