Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: CNCwt on December 20, 2007, 09:43:26 AM

Title: Macro VB Script for Lathe Toolchanger
Post by: CNCwt on December 20, 2007, 09:43:26 AM
Hi,

I need HELP on the Macro VB Scripting for the Lathe Toolchanger below.

This is a rather long description but hope it will help others as well doing the same type of VB Script.

I have a 4-position lathe toolchanger that uses 4 sensor switches to detect its position. I have made an electronic circuit to onvert the 4 positions (decimal) into 2-bit binary (00, 01, 10, 11) and then input these into the parallel port INPUT Pins. Here are the detailed description of the setup:

A)   Turret Tool Post & Relays:
a)   The Turret is a 4-position tool post driven by a 50W AC Motor.
b)   The AC Motor can be rotated CW or CCW controlled by 2 “ICE CUBE” Relays.
c)   The relays have 24VDC coils, Contacts of 3A/30VDC and 3A/240VAC.
d)   The 2 relays are interlatched.[/li]

B)   Tool Position Sensors:
a)   The 4 positions of the turret tool post are sensed by 4 installed hall-effect sensors or switches. The hall-effect sensors can be powered with 24VDC though I used 5VDC.

C)   Electronic Circuit and INPUT/OUTPUT controls using the parallel port:
a)   The electronic circuit was made feasible with the help of John Pearson (aka CJMerlin) without which, this will not be possible.
b)   The 4 hall-effect sensors (switches) are fed into an electronic circuit board and converted into 2-bit binary signals (Decimal Position 1, 2, 3, & 4 are converted into Binary 00, 01, 10, & 11).
c)   The 2-bit binary signals are inputted into 2 INPUTs of the Parallel Port (say, INPUT Pins #13 & #15) and set in Mach3 as INPUT2 & INPUT3.
d)   Mach3 is supposed to sense or monitor the 2 INPUTs and using Macro, Mach3 will know when a particular tool no. has just been sensed.
e)   Using an electronic circuit, 2 OUTPUTs of the Parallel Port are used to trigger the 2 relays of the tool post’s motor. One of the relay is to rotate the tool post CW and the other relay is to rotate the tool post CCW. Let’s say Parallel Port OUTPUT Pins # 6 & #7 and set in Mach3 as OUTPUT2 & OUTPUT3.
f)   Also, the above mentioned circuit interfaced the 5VDC TTL of the parallel port OUTPUT to 24VDC of the coil.

D)   How the auto turret tool post works:
a)   Let’s make the assumption that Tool # 3 is to be used.
b)   The GCode will specify T0301 (Txxyy where xx is the tool no.and yy is the tool offset) or this can be put in manually in MDI.
c)   A Macro will then monitor what is the present tool # in position. This function will be that of Mach3 reading the INPUT  # 2 & 3 to know which tool # is in position.
d)   If the correct tool # (Tool # 3) is in position, no further action will be taken and the rest of the GCodes are executed.
e)   If the required tool # is not in position, thru the Macro, Mach3 will send out a logical high signal pulse to OUTPUT2 and triggers RELAY #1 to raise and turn the turret CW.
f)   By so doing, the tool post will rotate until such a time that Mach3 senses thru the INPUT2 & INPUT3 that the required tool # has just rotated past the sensor.
g)   When Mach3 sensed that the required tool # has just rotated into position, it will send thru OUTPUT2 a logical low and thus stop the tool post’s CW rotation. It will next send a logical high thru OUTPUT3 to trigger RELAY #2 and thus rotate the tool post CCW and lock the tool post by lowering it into position.
h)   Mach3 will next send, thru Macro, a logical low to OUPUT3 to stop RELAY #2 and thus stop the motor of the tool post (say, within 1 second).

E)   The DECIMAL to BINARY relationship and proposed Macro equation to identify the tool position are as follows:
a)   The DECIMAL to BINARY is based on the following:
Tool Position No.       2-bit Binary
(Decimal)   (INPUT2)   (INPUT3)
                       B                    A
1                      0                   0
2                      0                   1
3                      1                   0
4                      1                   1

Below are the pictures of the Lathe and tool changer turret I am working on:
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: CNCwt on December 20, 2007, 09:47:49 AM
I have made the following Macro M6Start.m1s by studying the various Macro VB scripts posted in this forum as well as the help of numerous people here) :

'(NOTE: This Tool changer Macro is not working yet due to some problems I have with the sensor 2-bit binary electronic circuit I made. I will update this one soon with a working Macro but using 4 inputs instead of 2.)

'M6Start.m1s
'Input2 is 1st binary bit, 'Input3 is 2nd binary bit
'Output2 triggers 1st relay that rotates turret CW
'Output3 triggers 2nd relay that rotates turret CCW and lock tool in position

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

While NewTool > MaxToolNum
NewTool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend

Call StartTool

While SelectedTool <> NewTool
Call CheckPins
Wend

SelectedTool = NewTool

Call StopTool

SetCurrentTool(NewTool )

'//// Subroutines /////////

Sub StartTool
   ActivateSignal(Output2)
   'Code "G4 P4.0"    'Wait for the tool to rotate past the sensor
   While Ismoving()
   Wend
End Sub


Sub CheckPins
   If Not IsActive(Input3) And Not IsActive(Input2) Then
      NewTool = 1
      End If
   If Not IsActive(Input3) And IsActive(Input2) Then
      NewTool = 2
      End If
   If IsActive(Input3) And Not IsActive(Input2) Then
      NewTool = 3
      End If
   If IsActive(Input3) And IsActive(Input2) Then
      NewTool = 4
      End If
End Sub

Sub Stoptool
   DeActivateSignal(Output2)
   ActivateSignal(Output3) 
   'Code "G4 P1.0"    'Wait for the tool to rotate onto ratchet stop
   While Ismoving()
   Wend
   DeActivateSignal(Output3) 
End Sub
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: CNCwt on December 20, 2007, 10:00:37 AM
I made a simple test Brain to see if the INPUT2 & INPUT3 are being sensed and compared with the SelectedTool.

The test shows that upon using Txxyy in MDI, the Brain shows they are being equal and thus should trigger the Relay#2 to stop the turret turning CW BUT... the Macro is not working.

I attached the test Brain here.
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: CNCwt on December 20, 2007, 10:01:53 AM
Can someone take a look and point out where I may have committed the mistakes in the Macro?

Thanks,
Weedy
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: CNCwt on December 23, 2007, 12:34:03 AM
After analyzing my problem with the Tool Changer Macro, I suspect that my electronic circuit that converts the 4 decimal positions to 2-bit binary is not latching fast enough for the Input2 & Input3 to correctly monitor the tool position. This is partly due to its being on a breadboard and I decided to temporarily shelf it.

Instead, I connected directly the 4 sensor/switches to the BOB and used "Input1, Input2, Input3, & Input4" in Mach3 that correspond to the parallel port's Input Pins 11, 12, 13, & 15. My weakest in VB scripting and not enough knowledge of electronics took me some time to realize that the sensors are sinking current (I am not even sure if this is the correct term :)) and thus, the one that is not lighting up in the BOB as well as in the Active signals in the diagnostic page is the active position.

Eventually, I got it to work nice and easy. The turret takes less than a second to a max of 2 seconds to rotate the requested tool into position. It never takes more than 1 complete revolution of the turret to put the requested tool into position.

Here is the working Toolchanger Macro:

'This Macro was based on the 4 position sensors being fed directly into 4 INPUTs
'to the parallel port.
'Input1 is Tool1 (Pin11, Active High), Input2 is Tool2 (Pin12, Active High),
'Input3 is Tool3 (Pin13, Active High), Input4 is Tool4 (Pin15, Active High).
'Since Sensors are sinking current, hence all set to Active High.
'Output2 triggers 1st relay that raises and rotates the turret CW,
'Output3 triggers 2nd relay that rotates turret CCW and lower the turret to lock tool in position.
'OEMDRO(1200) is utilized to store the last used tool (OldTool) and is updated
'upon final execution of the macro. This is resorted to as the Txxyy will overwrite
'the "CurrentTool" DRO.


'M6Start.m1s
OldTool = GetOEMDRO (1200)
Tool = GetSelectedTool()
MaxToolNum = 4      'Max number of tools for the changer

If OldTool = Tool Then
Message ("Selected Tool already loaded")
Exit Sub
End If

While Tool > MaxToolNum
Tool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend

Call StartTool

While NewTool <> Tool
   Call CheckPins
   While IsMoving()
   Wend
Wend

Call StopTool

Call SetUserDRO (1200, NewTool)
SetCurrentTool(NewTool)

'//// Subroutines /////////

Sub StartTool
   ActivateSignal(Output2)
   'Code "G4 P4.0"    'Wait for the tool to rotate past the sensor
      While IsMoving()
      Wend
End Sub

Sub CheckPins
   If Not IsActive(Input1) Then
      NewTool = 1
      End If
   If Not IsActive(Input2) Then
      NewTool = 2
      End If
   If Not IsActive(Input3) Then
      NewTool = 3
      End If
   If Not IsActive(Input4) Then
      NewTool = 4
      End If
End Sub

Sub Stoptool
   DeActivateSignal(Output2)
      While IsMoving()
      Wend
   ActivateSignal(Output3) 
      Code "G4 P1.0"    'Wait for the tool to rotate onto ratchet stop
      While IsMoving()
      Wend
   DeActivateSignal(Output3)
      While IsMoving()
      Wend
End Sub   





Title: Re: Macro VB Script for Lathe Toolchanger
Post by: CNCwt on December 23, 2007, 07:08:07 AM
Below is a snapshot of the OEMDRO(1200) put inside the Mach3 Turn Diagnostic page (encircled in red).
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: mechaniac on December 23, 2007, 08:25:34 AM
Hello Weedy,

I have the same type of ATC, but works with separate sensors of each tool. This Macro definitely works ( parts of code stolen from Brian Barker  ;) ,Comments are unfortunately in German):

'Werkzeugwechslermakro f. Trolcut430, Helmut Heigl, 07/12/21
Sub Main()
OldTool = GetOEMDRO (1200) 'Aktuelles Werkzeug
x = GetToolChangeStart( 0 )'Abfrage Position "X" vor Werkzeugwechsel   
z = GetToolChangeStart( 2 )'Abfrage Position "Z" vor Werkzeugwechsel   
tool = GetSelectedTool()'Auswahl neues Werkzeug   
NewTool = tool
MaxToolNum = 4    'Anzahl Werkzeuge
ToolFreistX = 40   'Freistellwert "X"
ToolFreistZ = 80   'Freistellwert "Z"          

If NewTool = OldTool Then
   Exit Sub
End If
While NewTool > MaxToolNum
NewTool = Question ("Bitte andere Werkzeugnummer eingeben: 1-" & MaxToolNum)
Wend
Code "G00 G53 X" & ToolFreistX & " Z" & ToolFreistZ 'Werkzeug freistellen (über Maschinenkoordinaten!!!)
While IsMoving()
Wend
ActivateSignal(Output1) 'Werkzeughalter drehen "EIN"
Call MovePos(NewTool)
While IsMoving()
Wend
DeActivateSignal(Output1) 'Werkzeughalter drehen "AUS"
Code "G4 P.5" 'Kleine "Weichei"- Zeitverzoegerung, kann eventuell weggelassen werden
While IsMoving()
Wend
ActivateSignal(Output2) 'Wendeschuetz für Halterklemmung "EIN"
Code "G4 P0.5"    'Warten auf Klemmung
While IsMoving()
Wend
DeActivateSignal(Output2) 'Wendeschuetz für Halterklemmung "AUS"
Call SetUserDRO (1200,NewTool)
SetCurrentTool( NewTool )'neues Werkzeug anzeigen
Code "G00 X" & x & " Z" & z 'neues Werkzeug in Arbeitsposition fahren
While IsMoving()
Wend
End Sub

Sub MovePos(ByVal ToolNumber As Integer)



Select Case ToolNumber

       Case Is =1
       ToolNumber=1
           While Not IsActive (Input1) 'Abfrage Werkzeugsensor 1
         Wend
       
       Case Is = 2
       ToolNumber=2
         While Not IsActive (Input2) 'Abfrage Werkzeugsensor 2
         Wend
     
       Case Is = 3
       ToolNumber=3
         While Not IsActive (Input3) 'Abfrage Werkzeugsensor 3
         Wend

       Case Is = 4
       ToolNumber=4
         While Not IsActive (Input4) 'Abfrage Werkzeugsensor 4
         Wend
         
       
End Select

End Sub
           




Greetings,
Helmut
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: CNCwt on December 23, 2007, 10:59:14 AM
Hi Helmut,

Thanks for posting your working toolchanger macro. Even though my German is none existing at all, I can guess on the comments' meanings :).

In fact, your macro is almost the same working toolchanger macro I posted (2 posts earlier than your posting). We both utilized the system of Brian Barker by creating an OEMDRO(1200) to have an OldTool DRO so that it will not be overwritten by Txxyy. And both these macros need to use 4 inputs to Mach.

I am still working on changing the 4 sensor positions to 2-bit binary so that I will only need 2 Inputs. This will allow me to use only 1 parallel port instead of 2. My electronic circuit that converts the decimal 4 positions to 2-bit binary is not functioning fast enough to latch the last tool position signal and this creates a situation wherein in between the sensor signals, the 4th tool position (binary 11 is the signal that comes out when it does not latch) is being sent to the Inputs.

I have made a test macro to identify the tool position signals and it identifies the correct tool position. I have made another toolchanger macro for the 2-bit binary position and I know it works except for a particular situation. That is, when the existing tool position is T3, and the requested tool is T4, then the turret will not rotate as the signal that is not latching is 11 which translates to T4. After which, any other subsequent toolchange will be in error. This situation has confirmed my analysis that my circuit is not latching fast enough.

If you are interested to know how I am doing the electronics and the macro for 2 Inputs only, let me know and I can post the details. In fact, without the mentioned circuit problem, I could have make this macro work with a brain that handles the timing as well as the NewTool and OldTool comparison (Note: John Pearson a.k.a. CJMerlin is kind enough to be behind the scene in helping me sort out the electronics as well as the brain solutions though any mistakes or problems is entirely mine as John has no way of knowing how I am implementing it. Thanks John :))

Kind regards,
Weedy




Title: Re: Macro VB Script for Lathe Toolchanger
Post by: Graham Waterworth on December 24, 2007, 05:15:05 AM
I have always found it better with mach to assign values to pins and check the count, like this :-

Sub CheckPins
   count=0
   If IsActive(Input1) Then
      count=count+1
   End If
   If IsActive(Input2) Then
      count=count + 2
   End If
End Sub

You then have your 4 numbers, 0,1,2,3

Graham.
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: CNCwt on December 24, 2007, 05:54:00 AM
Hi Graham,

Thanks for that bit of tip. It's nice and clean.

So, all I have to do to have my NewTool correctly is:

Sub CheckPins
   count=0
   If IsActive(Input1) Then
      count=count+1
   End If
   If IsActive(Input2) Then
      count=count + 2
   End If
NewTool = count + 1
End Sub

Right?

Thanks,
Weedy

Title: Re: Macro VB Script for Lathe Toolchanger
Post by: Graham Waterworth on December 24, 2007, 06:39:31 AM
that will do it,

Graham.
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: roodesign on December 24, 2007, 08:22:43 AM
hi guys, I have a hardinge hnc (lathe) that I have retrofitted with a galil 2130...the hardinge uses a air motor powered turret and has a digital encoder that uses four inputs to the galil to tell each of the 8 turret positions...I am trying to figure out how to write a turret macro for this application...seems very sim. to what you are working on, I need to control two outs....turn, and stop and read those four inputs and the turret locked limit....any help that you might be willing to give would be greatly appreciated!

thanks, Roo
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: Graham Waterworth on December 24, 2007, 08:31:22 AM
You may be able to modify this one to get you what you want.

Graham.

Sub Main()
If IsLoading() then
  ' do nowt
Else
  OldTurretPos=(GetOEMDRO(824))   'current tool position
  NextTool=GetSelectedTool()      'tool to be indexed
 
  If NextTool<1 Or NextTool>8 Then 'valid tool check
    Message("Next Tool out of range")
    Exit Sub
  End If

  ActivateSignal(OUTPUT4)   'rotate Turret

  '=== Index Tool ===
  Select Case NextTool
   Case 1
      count=1
   Case 2
      count=3
   Case 3
      count=2
   Case 4
      count=6
   Case 5
      count=4
   Case 6
      count=12
   Case 7
      count=8
   Case 8
      count=9
  End Select

  thistool=OldTurretPos

  While thistool<>count
    sensors=0
    While sensors=0
      if IsActive(OEMTRIG1) then sensors=sensors+1
      if IsActive(OEMTRIG2) then sensors=sensors+2
      if IsActive(OEMTRIG3) then sensors=sensors+4
      if IsActive(OEMTRIG4) then sensors=sensors+8
    Wend
    thistool=sensors
  Wend

  Code"G04 P50"
  While Ismoving()
  Wend
 
  DeActivateSignal(OUTPUT4) 'stop turret rotation
  SetCurrentTool(thistool)
End If
End Sub           

Title: Re: Macro VB Script for Lathe Toolchanger
Post by: CNCwt on December 24, 2007, 11:22:10 PM
Hi Roo,

The Macro given by Graham should give you a good start and let us know how you are doing.

If I can be of further help, feel free to post the questions. Though I am no expert when it comes VB scripting, it helps increase my knowledge by analyzing the problems.

Regards,
Weedy
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: roodesign on December 25, 2007, 08:21:54 AM
Hi guys, sorry if this is a stupid question, but I don't understand how the case command would work for me...
the signal that I get from the hnc's turret encoder is from four switches (four inputs)that are either on or off...
so tool 1 might be 00I0 tool 2 might be 000I etc, so I think that, as the turret rotates, I need to check
the inputs for each of the eight combinations ....if this helps at all here is a sequence of how it should work....

new tool# is called....
check if tool # is valid (1-8)
check if tool # is already there....
if not, then move turret back to safe index position(different for each tool, depending on how much they stick out)
wait till done....
activate output1 to lift and turn turret....(turns only one way)
start looking at the four inputs for the combination unique to that tool number
00I0= tool 1
000I= tool 2
0I00= tool 3
etc.....for all eight positions...
when tool found:
dwell
activate output2 stop turret....(stalls air motor)
dwell
deactivate output1 stop turning and drop/lock turret
dwell
deactivate output2 stop turret
check turret down limit switch (input5)...fault?
return to gcode program....

the couple things that I really don't understand is how to set up the routine to query those four inputs
and, how to tell mach3 where the safe index position is for each tool (set up eight dro's?)...I could just have the turret go all the way back each time but that would waste time moving further than I need to....

thanks for any help you can give me!.....I am slow on the uptake with this vb stuff

Roo Trimble
 :)
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: CNCwt on December 25, 2007, 10:20:03 AM
I am not sure how your 4 inputs are configured but I would think there are 8 sensors at each tool positions 1 to 8. These 8 sensors are then converted into 4-bit binary thru an electronic circuit. Like so:

Position 1 - 0001
Position 2 - 0010
Position 3 - 0011
Position 4 - 0100
Position 5 - 0101
Position 6 - 0110
Position 7 - 0111
Position 8 - 1000

In other words, the 8 decimal positions are converted into binary to allow you to use only 4 inputs to Mach3.

The following VB script of Graham computes to the corresponding 8 tool positions:

    sensors=0
    While sensors=0
      if IsActive(OEMTRIG1) then sensors=sensors+1
      if IsActive(OEMTRIG2) then sensors=sensors+2
      if IsActive(OEMTRIG3) then sensors=sensors+4
      if IsActive(OEMTRIG4) then sensors=sensors+8
    Wend

Input4   Input3   Input2   Input1   ToolPosition
  0           0           0          1             1
  0           0           1          0             2
  0           0           1          1             3
  0           1           0          0             4
  0           1           0          1             5
  0           1           1          0             6
  0           1           1          1             7
  1           0           0          0             8

This is how it is computed:
1) For example, if you take the 7th row (0 1 1 1) and apply the vb script of Graham
2) Input 1 is active, so sensors = sensors + 1 = 0 + 1 = 1 (Initial seeded value of sensors is 0)
3) Input 2 is active, so sensors = 1 + 2 = 3 (Note: you have to take the preceeding sensors value of 1 and add it to 2)
4) Input 3 is active, so sensors = 3 + 4 = 7
5) Input 4 is not active, so sensors = 7 + 0 = 7 (that is your tool position 7)

The Case command can be written to correspond to the above 8 tool positions. The rest of the script will depend where is your tool safe position for tool change.

Hope this helps.

Weedy



Title: Re: Macro VB Script for Lathe Toolchanger
Post by: roodesign on December 25, 2007, 12:47:53 PM
thank you weedy....what an education...I get it now...I can't wait to get to the shop and start writing the macro....that was an incredible concise and clear explanation....thanks again...
Roo
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: Graham Waterworth on December 25, 2007, 06:42:25 PM
Hi,

sorry I was not here to give a more in depth detail of how to use the macro,  it has been a busy day.

It looks like you figured it out though.  If you need any more info just ask.

Nice explanation Weedy.

Graham.
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: CNCwt on December 25, 2007, 09:59:11 PM
Hi Roo,

Glad to be of help. I learned the hard way by reading and analyzing practically all the macro posts and relearning programming. Those knowledge were stale for several decades already.

Do let us know how you are progressing as I am eager to know how it works out eventually. If you can post your final working macro with the offsets, so much the better. I am still learning the idiosyncrasies of how the lathe tool offset works as I have no practical experience with machining.

Weedy

Title: Re: Macro VB Script for Lathe Toolchanger
Post by: CNCwt on December 25, 2007, 10:00:43 PM
Hi Graham,

Thanks for the encouragement. I need it as I am still relearning all those programming techniques.

Weedy
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: mechaniac on December 26, 2007, 05:27:19 AM
Hello Weedy,

In your macros, there is no offsetting of the tool during turning the ATC, to prevent collision. Do you carry out this  with separate G- Code or want you to integrate this in your actual macro?
 I think, integrating in the macro is the more convenient way, I've done this, see above, but have a problem with positioning in incremental coordinate mode.

Greetings,
Helmut
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: CNCwt on December 26, 2007, 06:56:33 AM
Hi Helmut,

I have not touched yet the macro vb for the toolchanger safe position codes. I think I will be including the safe tool change position in the macro when I finalize my setup. The offset is taken care of by the tool table if I am not mistaken.

If you look at this video (http://www.youtube.com/watch?v=8oVD7mrY9zw), you will notice that every time a tool change is being made, it goes back to a safe tool change position.

Can you elaborate further with your problem in positioning in incremental coordinate mode?

Thanks,
Weedy         
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: Graham Waterworth on December 26, 2007, 07:03:05 AM
Helmut,

if your machine has homing switches fitted then one way to go to a safe position is by using G53 Xnnn Znnn this is a known point in machine coordinates from the zero return point.

Graham.
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: mechaniac on January 05, 2008, 02:38:54 PM
Hi Weedy, Graham,

Sorry for the late response (i had to spend some holidays with my family) . I have tried another solution for the work offset, because in the old version is making troubles, if the machine is in G91 (incremental) mode. In this mode, moving with machine coordinates will not work.
In my new version, the mode will not influence the moving.

BTW: How can i realize a "do nothing" in VB Script ?




'Werkzeugwechslermakro f. Trolcut430, Helmut Heigl, R0.8 08/01/05
Sub Main()
OldTool = GetOEMDRO (1200) 'actual tool
tool = GetSelectedTool()'new tool selected
incremental= GetOEMLED (49)'get coordinate system (absolute or incremental)
NewTool = tool
MaxToolNum = 4    'number of tools
ToolFreistX = 40   'Offset "X"
ToolFreistZ = 40   'Offset "Z"          

If NewTool = OldTool Then
   Exit Sub
End If
While NewTool > MaxToolNum
NewTool = Question ("Bitte andere Werkzeugnummer eingeben: 1-" & MaxToolNum)
Wend
Code "G91"'change to relative coordinates
While IsMoving()
Wend
Code "G00 X" & ToolFreistX & " Z" & ToolFreistZ 'offset tool
While IsMoving()
Wend
ActivateSignal(Output1) 'turning toolpost clockwise "ON"
Call MovePos(NewTool)
While IsMoving()
Wend
DeActivateSignal(Output1) 'turning toolpost clockwise "OFF"
Code "G4 P.5" 'short time- delay, can possibly been deleted
While IsMoving()
Wend
ActivateSignal(Output2) 'turning toolpost CCW (clamping)"ON"
Code "G4 P0.5"    'wait for clamping
While IsMoving()
Wend
DeActivateSignal(Output2) 'turning toolpost CCW (clamping)"OFF"
Call SetUserDRO (1200,NewTool)
SetCurrentTool( NewTool )'show new tool
Code "G00 X-" & ToolFreistX   & " Z-" & ToolFreistZ 'set new tool to old coordinates
If incremental = 1 Then
Code "G91"
While IsMoving()
Wend
Else
Code "G90"
While IsMoving()
Wend
End If

End Sub
.
.
.
.

Greets from Austria,

Helmut

   
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: tantan on April 19, 2008, 10:52:34 AM
hi,

thanks for all these replies, they have been a great help to get started. but i have 3 questions about the VBcode:

1. how can i become the "GetOEMDRO (1200)". I cannot find this on my screens in MACH3 turning. is it possible to become this dro on a screen.
2. the Code "G4 P1.0" does not work at all. the line is executed but it does not delay? is it a configuration fault somewhere in mach?
2. my macro only runs if i start i manually, i thought it would run continuously.

thanks

antoine
the Netherlands
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: mechaniac on April 27, 2008, 12:21:13 PM
Hi all,

My toolchanger is running now:

http://www.youtube.com/watch?v=VehHjJcrR2M


Greets,
Helmut

Title: Re: Macro VB Script for Lathe Toolchanger
Post by: tantan on April 30, 2008, 01:11:08 PM
hi,

that realy looks good. i hope you can help me with one of my questions; see first post in "VB and development of wizards"

thanks

antoine
Title: Re: Macro VB Script for Lathe Toolchanger
Post by: tantan on May 02, 2008, 02:01:49 PM
hi anyone,

i think my problem is solved (with help of ron). using only "T5" on the MDI line starts the M6start macro. but the toolnumber is not interpreted correctly by the m6start macro. typing "M6 T0505" works well.

hope this will help others.

antoine
the netherlands