Hello Guest it is March 29, 2024, 08:51:09 AM

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

0 Members and 1 Guest are viewing this topic.

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: Turn tool turret macro
« Reply #20 on: April 24, 2020, 01:00:37 PM »
if i run your testcode here in VB Scripter window, i get a result, see attachment
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: Turn tool turret macro
« Reply #21 on: April 25, 2020, 02:53:10 AM »
ok if the timer function is not working, you can try to use the time function.

example:
Code: [Select]
Dim TS As Single
Dim TE As Single
Dim TT As Single

'get the starttime
TS = Timer

Sleep 4000

'get the actual time
TE = Timer
TT = TE - TS



MsgBox TT



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 #22 on: April 27, 2020, 05:55:47 AM »
That is great! Thank you very much for this!!

I have used this example in my code and it looks to be working, i will test on the machine when I get a minute and see if the whole macro works as it should.

Thanks again!!  :D :D :D
Re: Turn tool turret macro
« Reply #23 on: April 28, 2020, 05:12:05 AM »
Thanks TPS, that workaround for the timer has worked really well. I have done some tests this morning and my macro now seems to be working as it should, which I'm really happy about!!

Something that almost always catches me out is when setting and reading I/O's or DRO's, a sleep is needed as Mach either misses the command, or crashes if not.

I've posted the code below so others might be able to make use of it:

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

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

Dim TS As Single
Dim TE As Single
Dim TT As Single

NewTool = GetSelectedTool() 'Commanded tool number
OldTool = GetCurrentTool() 'Current tool number
MaxToolNum = 8 'Max number of tools for the changer
PreviousSpeed = GetRPM() '
ToolSpeed = 500

'-----------------------------------------------------------------------
'MACRO START
'-----------------------------------------------------------------------

DeActivateSignal(OUTPUT6) 'Make sure signal to PLC is negative

SetSpinSpeed(ToolSpeed) 'Spindle speed change
code"G91 G28 X0" 'set incremental, return home via X first
While IsMoving()
Wend

code"G91 G28 Z0"
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
code"M00"
code"M5"
Message("TURRET NOT READY!")
End If
End If
End

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

Sub DoToolChange()

TS = Timer 'get the start time

SetCurrentTool(NewTool) 'Update the tool DRO
ActivateSignal(OUTPUT6) 'Set tool change allowed signal to PLC
sleep 500

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

TE = Timer
If (TE - TS) > 4 Then
Call ToolFailed
End If
Wend

Call ToolComplete


End Sub
     
 

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

Sub ToolComplete()
DeActivateSignal(OUTPUT6)
sleep 100
TT = TE - TS
SetSpinSpeed(PreviousSpeed) 'RPM before tool change called
Message("Tool Change Complete in " & Round(TT,1) & " seconds")
sleep 100
End Sub


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

Sub ToolFailed()
DeActivateSignal(OUTPUT6)
sleep 100
Code"M00"
Code"M5"
Message("TURRET TIMEOUT  TOOL  " & NewTool & "  NOT LOCATED" )
sleep 100

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: Turn tool turret macro
« Reply #24 on: April 28, 2020, 09:51:39 AM »
nice to hear that you got it working.
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.