Hello Guest it is April 24, 2024, 06:52:00 AM

Author Topic: Macro VB Script for Lathe Toolchanger  (Read 36036 times)

0 Members and 1 Guest are viewing this topic.

Offline Graham Waterworth

*
  • *
  •  2,673 2,673
  • Yorkshire Dales, England
    • View Profile
Re: Macro VB Script for Lathe Toolchanger
« Reply #10 on: December 24, 2007, 06:39:31 AM »
that will do it,

Graham.
Without engineers the world stops
Re: Macro VB Script for Lathe Toolchanger
« Reply #11 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

Offline Graham Waterworth

*
  • *
  •  2,673 2,673
  • Yorkshire Dales, England
    • View Profile
Re: Macro VB Script for Lathe Toolchanger
« Reply #12 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           

Without engineers the world stops

Offline CNCwt

*
  •  65 65
    • View Profile
Re: Macro VB Script for Lathe Toolchanger
« Reply #13 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
Re: Macro VB Script for Lathe Toolchanger
« Reply #14 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
 :)

Offline CNCwt

*
  •  65 65
    • View Profile
Re: Macro VB Script for Lathe Toolchanger
« Reply #15 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



Re: Macro VB Script for Lathe Toolchanger
« Reply #16 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

Offline Graham Waterworth

*
  • *
  •  2,673 2,673
  • Yorkshire Dales, England
    • View Profile
Re: Macro VB Script for Lathe Toolchanger
« Reply #17 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.
« Last Edit: December 25, 2007, 06:45:17 PM by Graham Waterworth »
Without engineers the world stops

Offline CNCwt

*
  •  65 65
    • View Profile
Re: Macro VB Script for Lathe Toolchanger
« Reply #18 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

Offline CNCwt

*
  •  65 65
    • View Profile
Re: Macro VB Script for Lathe Toolchanger
« Reply #19 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