Hello Guest it is April 23, 2024, 11:36:00 AM

Author Topic: yet another lathe turret macro needing assitance  (Read 1257 times)

0 Members and 1 Guest are viewing this topic.

yet another lathe turret macro needing assitance
« on: April 29, 2020, 05:50:05 PM »
So I'm pretty handy in the fabrication side of things, but when it comes to coding i'm just terrible. I'm making a ratcheting style turret for my lathe and I think i've gotten a good start on the M6 marco, but I get a compile error any time I try to run it. Can someone more versed in VB please take a look at it and see what I'm doing incorrectly?



Dim Num_Tools As Integer
Dim Ang_Move As Integer
Dim Req_Tool As Integer
Dim Current_Tool As Integer
Dim Lock_Move As Integer
Dim CW_Feed As Integer
Dim CCW_Feed As Integer
Dim Moves As Integer


Num_Tools = 12 'number of tools on turret
Ang_Move = 360/Num_Tools 'angular rotation per tool
Req_Tool = GetSelectedTool()
Current_Tool = GetCurrentTool()
Lock_Move=15 'distance to move back onto paw to lock
CW_Feed=100
CCW_Feed=50

'Start tool change

If Req_Tool < 1 Then
Message"Tool number too low"
Code "M30"
End If

If Req_Tool = Current_Tool Then
'do nothing
Else
'do tool change
If Req_Tool > Current_Tool Then Moves = (Req_Tool - Current_Tool) * Ang_Move
Else
If Req_Tool < Current_Tool Then Moves = (Num_Tools - Current_Tool + Req_Tool) * Ang_Move
End If

'move to safe position
Code "G0 G53 X-.25 Z-.25"
Code "G04 P0.5"
'index turret
Code "G91 G94"
Code "G01 A" & Moves + 10 & "F" & CW_Feed
Code "G01 A-" & Lock_Move & "F" & CCW_Feed
While IsMoving()
Sleep(10)
Wend

SetCurrentTool Req_Tool
SetUserDRO 1500 , Req_tool
Code "G90"
Code "F" & Current_Feed

Offline TPS

*
  •  2,505 2,505
    • View Profile
Re: yet another lathe turret macro needing assitance
« Reply #1 on: April 30, 2020, 02:17:33 AM »
Code: [Select]
Dim Num_Tools As Integer
Dim Ang_Move As Integer
Dim Req_Tool As Integer
Dim Current_Tool As Integer
Dim Lock_Move As Integer
Dim CW_Feed As Integer
Dim CCW_Feed As Integer
Dim Moves As Integer


Num_Tools    = 12 'number of tools on turret
Ang_Move     = 360/Num_Tools 'angular rotation per tool
Req_Tool     = GetSelectedTool()
Current_Tool = GetCurrentTool()
Lock_Move    = 15 'distance to move back onto paw to lock
CW_Feed      = 100
CCW_Feed     = 50

'Start tool change

If Req_Tool < 1 Then
  Message"Tool number too low"
  Code "M30"
End If

If Req_Tool = Current_Tool Then
  'do nothing
Else
  'do tool change
  If Req_Tool > Current_Tool Then
    Moves = (Req_Tool - Current_Tool) * Ang_Move
  End If
  If Req_Tool < Current_Tool Then
    Moves = (Num_Tools - Current_Tool + Req_Tool) * Ang_Move
  End If 
End If

'move to safe position
Code "G0 G53 X-.25 Z-.25"
Code "G04 P0.5"
'index turret
Code "G91 G94"
Code "G01 A" & Moves + 10 & "F" & CW_Feed
Code "G01 A-" & Lock_Move & "F" & CCW_Feed
While IsMoving()
Sleep(10)
Wend

SetCurrentTool Req_Tool
SetUserDRO 1500 , Req_tool
Code "G90"
Code "F" & Current_Feed


anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: yet another lathe turret macro needing assitance
« Reply #2 on: May 01, 2020, 06:41:56 PM »
you sir are a gentle man and a scholar. Thank you very much!!