Hello Guest it is March 28, 2024, 02:36:48 PM

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

0 Members and 1 Guest are viewing this topic.

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: Turn tool turret macro
« Reply #10 on: April 21, 2020, 08:05:19 AM »
what have you selected in Config -> General Config -> Toolchange?
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 #11 on: April 21, 2020, 11:34:19 AM »
Thanks both, I will try those pointers shortly as I think my motion controller plugin is causing other issues when its not connected and i'm still trying to run mach. I will update on my findings  ;)
Re: Turn tool turret macro
« Reply #12 on: April 22, 2020, 09:47:20 AM »
Ok, an update  ;D

So I have added in some small sleep commands into my code to allow the dro to update, also added in the msgbox to see if M6 was actually being called. Long story short, I have ended up with the turret working correctly and the M6Start macro doing what it should.

One small shameful confession, the tool change was set to ignore in the general config screen, which had made life very difficult. However, this must have happened during a crash (as mach3 frequently does on my laptop) because this setting was set to auto tool changer prior to my first post in this thread. Stoopid mistake I know... but I never thought to check this as I'd already set it to atc!! Oh well, its all working great now  :D :D

Thanks all for your assistance
Turn tool turret macro
« Reply #13 on: April 23, 2020, 05:17:03 AM »
I spoke too soon!

I do have some problems with my code in the M6Start macro.....

I think the problem is with the while loop in the DoToolChange() sub.

What the code is supposed to do is:
- Check the tool number is valid, if its allowed proceed to DoToolChange()
-The tool number is sent to a PLC via modbus, that is giving a tool change allowed signal (INPUT1), but is waiting for the command to change the tool from mach (OUTPUT6).
-Once (OUTPUT6) goes high, the PLC sends (INPUT1) low while it cycles the tool. Once it has successfully located and locked the tool, it will set (INPUT1) high again. If it doesn't, something has gone wrong.
-The While loop is supposed to look at when (INPUT1) is low and wait for it to go high again, before it calls ToolComplete(), it should also start timing 4 seconds, by which time if it hasn't seen the signal it will call ToolFailed().

The while loop is doing something strange and won't go to either ToolComplete() or ToolFailed(), I think its something to do with the timer, but cant quite figure it out.

If anyone wouldn't mind looking over my code to see if anything jumps out please?

Thanks,

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

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


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
code"G91 G28 Z0" 'set incremental, return home via X first
SetSpinSpeed(ToolSpeed) 'Spindle speed change
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)

sleep 200
t = GetTimer(1)


While IsActive(INPUT1) = False 'While the turret is moving, count down
If IsActive(INPUT1) = True Then 'If input goes high again, tool has cycled
Call ToolComplete
'Else
If t > 4000 Then
Call ToolFailed
End If
End If

sleep 100
Wend

'End If


End Sub
     
 

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

Sub ToolComplete()
DeActivateSignal(OUTPUT6)
SetSpinSpeed(PreviousSpeed) 'RPM before tool change called
sleep 100
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 #14 on: April 23, 2020, 05:46:07 AM »
i think that is what you try to do

Code: [Select]

'Clear timer 1
SetTimer(1)



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

If t > 4000 Then
Call ToolFailed
End If
Sleep 100
Wend

Call ToolComplete



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 #15 on: April 23, 2020, 08:25:16 AM »
Ahh..., Ok I'll try this asap!
Re: Turn tool turret macro
« Reply #16 on: April 24, 2020, 04:35:02 AM »
Had a chance to try this, this morning.

The While loop now works and unless it sees (INPUT1) it will not exit the loop.

The timer however does not work. I have tested the timer by sending a message when ToolComplete() is called and it always returns zero.

I've changed the timer number and also changed where SetTimer() is in the macro, but it only ever returns zero, is there a way it needs to be started?

Thanks

Code: [Select]
'----------------------------------------------------------------------
'TOOL CHANGE
'----------------------------------------------------------------------

Sub DoToolChange()

SetCurrentTool(NewTool) 'Update the tool DRO
'Call ActivateSignal(OUTPUT6) 'Set tool change allowed signal to PLC
SetTimer(20) 'Clear timer 1
sleep 500

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

t = GetTimer(20)
If t > 4000 Then
Call ToolFailed
End If
Sleep 100
Wend

Call ToolComplete


End Sub
     
 

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

Sub ToolComplete()
DeActivateSignal(OUTPUT6)
SetSpinSpeed(PreviousSpeed) 'RPM before tool change called
Message("Tool Change Complete in " & GetTimer(20) & " seconds")
sleep 100
End Sub

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: Turn tool turret macro
« Reply #17 on: April 24, 2020, 06:21:30 AM »
did some tests Looks like the Timer Resolution is 10 seconds this code should work better

Code: [Select]
'----------------------------------------------------------------------
'TOOL CHANGE
'----------------------------------------------------------------------

Sub DoToolChange()

SetCurrentTool(NewTool) 'Update the tool DRO
'Call ActivateSignal(OUTPUT6) 'Set tool change allowed signal to PLC
SetTimer(20) 'Clear timer 1
sleep 500

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

t = GetTimer(20)
If t > 0.4 Then
Call ToolFailed
End If
Sleep 100
Wend

Call ToolComplete


End Sub
     
 

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

Sub ToolComplete()
DeActivateSignal(OUTPUT6)
SetSpinSpeed(PreviousSpeed) 'RPM before tool change called
Message("Tool Change Complete in " & GetTimer(20) & " seconds")
sleep 100
End Sub

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 #18 on: April 24, 2020, 08:58:19 AM »
Thanks for testing this, Will give it a try later  ;)
Re: Turn tool turret macro
« Reply #19 on: April 24, 2020, 09:52:55 AM »
GetTimer() still returns zero...

Code: [Select]
SetTimer(1)

sleep 1000

MsgBox(GetTimer(1))

This should say 1000ms right? or 0.1 if the timer resolution is 10 seconds? I just get 0