Hello Guest it is April 25, 2024, 07:53:48 AM

Author Topic: VB Script for toolchanger  (Read 11531 times)

0 Members and 1 Guest are viewing this topic.

All Done VB Script for 4 position turret lathe toolchanger
« Reply #20 on: April 10, 2014, 09:25:28 PM »
And we have a winner  :)

Turns out the 'turret rotating' signal, Input2, was not latching fast enough, so the 'While' command was not taking effect becuase there was not enough delay between the output signalling and the while.  In essence it was skipping right on and doing further 'clicks' while the turret was still in motion.  I also added a MachMsg as an initial step, as lack of air pressure also drives the Input1 active, so it reminds me to connect air pressure if I ask for a toolchange without air connected.  Since I turn off the air in my garage, this is pretty handy.

Again, thanks for alll the help.  Here is the final working code from my M6Start.m1s file, for anyone's reference.  Again this is a 4-position rotary toolpost on a lathe which holds multiple tools, and I am numbering my tools sequentially counterclockwise around the holder (as you look at it with bird's eye view).  Holder rotates clockwise.

'M6Start.m1s

If IsActive(Input2) Then
   MachMsg ("Connect Air Pressure to Turret!!","Turret Index Warning",MachMsgTypeOK)
End If

selectedTool = GetSelectedTool()
currentTool = GetCurrentTool()
currentFace = (currentTool - 1) Mod 4
targetFace = (selectedTool - 1) Mod 4

'rotate turret required number of "clicks"

For click = 1 To (targetFace - currentFace + 4) Mod 4 'rotate accounting for rollover

   ActivateSignal(Output2) 'activate momentary command to rotate
      Sleep (500)
   DeActivateSignal(Output2) 'deactivate momentary command and wait for movement signal
      Sleep (1500)
   While IsActive(Input2) 'wait for turret to stop
      Sleep (100)
   Wend
Next

SetCurrentTool selectedTool 'not forgetting to update to the new tool


« Last Edit: April 10, 2014, 09:36:09 PM by nickkinsman »

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: VB Script for toolchanger
« Reply #21 on: April 11, 2014, 03:13:01 AM »
OK, I think I understand the Mod function (Modulus) in Mach3 VB script, figured I'd post it here in case someone else needs to reference;

For 'a Mod b',

If a<b, uses full 'a' value as product.  i.e. '2 mod 3' = 2.  (this is what was confusing me).
If a > or = b, divide 'a' by 'b' and the remainder is your product.  i.e. for '9 mod 4', 4 goes into 9 twice evenly (8 ), with a remainder of 1 so 1 is the product.

Hope this helps, it was confusing me, but now it is all clear!   :D

And Stirling, you are absolutely right, it all works out correctly! 

Nick

Hi Nick - Pleased it's working for you.

However - your mod understanding is still incorrect.

It's simply INTEGER division.

In INTEGER division (by definition) there are no FRACTIONAL parts. So it's as simple as dividing the a by b and taking the INTEGER result. Whatever is "left" after that INTEGER division is the MODULUS.

at NO point is it of ANY RELEVANCE WHATSOEVER whether a<b or a>=b

Ian
Re: VB Script for toolchanger
« Reply #22 on: April 14, 2014, 12:37:00 PM »
OK!  I will have to settle for not really understanding it, but it certainly works!!  Good thing there are others out there that do.  

And the machmsg thing is pretty sweet too!

Finally, Mach3 does seem to be retaining the last tool loaded, so that takes care of having to set the initial tool in the DRO as well!!  Perfect.

Again, thank you very much Ian for sticking with it and helping me thru my ignorance!  You are the role model for what a forum moderator should do!

Nick
« Last Edit: April 14, 2014, 12:43:06 PM by nickkinsman »