Hello Guest it is March 29, 2024, 05:54:29 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - drumsticksplinter

Pages: 1 2
1
VB and the development of wizards / Re: Turn tool turret macro
« 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

2
VB and the development of wizards / Re: Turn tool turret macro
« 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

3
VB and the development of wizards / Re: Turn tool turret macro
« 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

4
VB and the development of wizards / Re: Turn tool turret macro
« on: April 24, 2020, 08:58:19 AM »
Thanks for testing this, Will give it a try later  ;)

5
VB and the development of wizards / Re: Turn tool turret macro
« 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

6
VB and the development of wizards / Re: Turn tool turret macro
« on: April 23, 2020, 08:25:16 AM »
Ahh..., Ok I'll try this asap!

7
VB and the development of wizards / Turn tool turret macro
« 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                         

8
VB and the development of wizards / Re: Turn tool turret macro
« 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

9
VB and the development of wizards / Re: Turn tool turret macro
« 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  ;)

10
VB and the development of wizards / Re: Turn tool turret macro
« 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?

Pages: 1 2