Hello Guest it is April 27, 2024, 08:23:55 AM

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

0 Members and 1 Guest are viewing this topic.

Re: VB Script for toolchanger
« Reply #10 on: April 08, 2014, 08:27:15 AM »
No problem, again very appreciative that you took the time to help me work it out!  Good learning experience for me too. 

OK, I'll try it again, I tried several times, the only time I saw action was when I stepped thru the code in the VB editor once, it triggered a move.  But then any time I tried a step thru again, it did not trigger.  It could be possible too maybe I don't have enough time on the sleep for the output signal 'button push' and it's not initializing fast enough....I'll check that too. 

When I took out the 'then' the VB editor step thru worked, and I did get that one movement one time, but could not get it to work again. Now that I am noodling it a bit it's probably a timing issue on the signal....I'll try some iterations of sleep time and see what it does. 

And yes, agree with you I figured I would have to tell it what tool it has on startup - I thought Mach would keep the tool as there is a 'persistant tool'  setting in Mach config, but it doesn't seem to remember  :(

I took out the first while statement because the latching of the signal is very good, it does not latch until fully seated, so I figured was not necessary.  Initially I wasn't sure if it only signaled on motion or not, but it turned out that it doesn't signal until the changer is fully seated. 

Thanks, Nick

Thanks for looking at it! 
Troubleshooting
« Reply #11 on: April 09, 2014, 09:43:43 AM »
OK, so...no solution yet....

I tried a bunch of iterations with the code and here is what I found;

As written, still no action.  When I FIRST opened Mach3 and immediately opened the VB editor and did a step-thru of the code, it stepped thru the 'For' section and did 1 toolchange step.  After that, it no longer will step thru the 'For' section, it skips right over it every time.  

Then I went into MDI, changed the tool to '1' in the DRO.  Did a T202 M6.  The computer bings, and the tool immediately changes to 2.  No action at all on the toolchange.  It acts like it is not reading the code, or if it is, it is immediatley skipping to the end.  I checked again, the toolchange is set to 'auto'.

I then looked at the code to try some things - I deleted the 'Mod 4' at the end of the 'for' statement on a whim and tried the step thru.  With that gone, it steps thru the 'for' statement, and I was able to verify that all the steps in the for statement work perfectly.  Every time I step thru, it completes a tool change very well.  The only modification I made was to increase the sleep time on the output signal, as it takes a moment for the input signal to latch on start of the toolchange.  So that's good.

I reapplied the 'Mod 4' portion and tried to do stepthru, still no tool change, it skips right over the 'for' section.  

I also retried to do a toolchange in the MDI, (both with and without the Mod 4) still no action.  

In summary, it seems like the issue may be in the counting statements at the start of the code, or in the 'For' statement line, is the only thing I can think of, as the actual toolchange seems to work well.  I don't really understand teh MOD command and what it is doing, so I'm not sure how to troubleshoot it.

Just to check, I am running the trial verison of Mach to proof it out before I buy the full license, is there a limitation on the toolchange function?  I know threading was not enabled but I didn't think toolchange was an issue.  

Thanks.  

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: VB Script for toolchanger
« Reply #12 on: April 09, 2014, 10:55:18 AM »
Let's just check a couple of things.

To use it for real you have to:

1) have the code (and nothing else) in M6Start.m1s (in the correct profile folder)
2) Start Mach
3) Enter 1 into the tool # DRO (to initialize at a known point - we'll deal with this later)
4) Switch to MDI
5) Enter M6 T(any number between 1 and 12)
6) Repeat 5 as you like.

OR - if you want to step through the code and see it working you have to:

1) have absolutely NOTHING in M6Start.m1s (in the correct profile folder)
2) Start Mach
3) Enter 1 into the tool # DRO (to initialize at a known point - we'll deal with this later)
4) Switch to MDI
5) Enter M6 T(any number between 1 and 12)
6) step through the code
7) repeat from 5 as you like.

I've done both here (quite a few times now ;D) and it works sweet as a nut every time.

Just tried it without my license and it works fine also in demo mode.
Re: VB Script for toolchanger
« Reply #13 on: April 09, 2014, 11:56:07 AM »
Well, I am glad to hear it is working for someone, that is a big positive!!!

I'll run thru your steps tonight verbatim and give it another try.  I certainly can see why it would not work on step thru as no tool change on the inital step is asked for, so it skips the clicks.  Anyway, here's fingers crossed!

Thanks.
Nick

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: VB Script for toolchanger
« Reply #14 on: April 10, 2014, 05:27:29 AM »
Not being a lathe person I just realized that tool change syntax appears to be different to mills. However it makes no odds. I just tried T0202 or whatever in MachTurn and the routine I gave you still works a charm (just drop the M6 command though in my blerb above). Note that although you don't appear to state M6 in the command the code still goes in M6Start.m1s.

Maybe if some lathe guru could comment perhaps but I think the above is correct.
Re: VB Script for toolchanger
« Reply #15 on: April 10, 2014, 08:27:16 AM »
Hello Stirling;

I was able to get the code to work, my stupidity - had it in the generic lathe config vs. the one for my lathe.  So great news there anyway!!

But...it only gives me 1 step of the turret no matter what tool I try to change to.  i.e. - start with tool 1 in the DRO, ask for tool 3, it does only 1 step.

I started to research the MOD command today because I would like to understand it better, but I am a little stumped on how the math works, for instance using the 1--> 3 example;

current face = (1-1) mod 4 = 0div4 = 0, ok good so far
target face = (3-1) mod 4 = 2div4= 0, remainder of 0.5 = 1? (partial remainder?), answer should be 2 though, correct?

Does the Mod command act like a divisor, where a Mod b = a/b (and uses the remainder)?  And how does it work for fractional numbers?  I'm going off wikipedia here, I could not find a good example in the manuals, especially for fractional. 

Thanks.
Nick

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: VB Script for toolchanger
« Reply #16 on: April 10, 2014, 09:36:31 AM »
current face = (1-1) mod 4 = 0div4 = 0, ok good so far
target face = (3-1) mod 4 = 2div4= 0, remainder of 0.5 = 1? (partial remainder?), answer should be 2 though, correct?

Close but no cigar.

The mod(ulus) is the remainder after division

forget fractional numbers for the moment because we're not using them.
if both operands are integers then the division and result are integer also. so....

current face = (1-1) mod 4 = 0/4 = 0 with 0 remainder
target face = (3-1) mod 4 = 2/4 = 0 with 2 remainder

mod is the classic mechanism for handling rollovers.

copy and paste this code exactly as is into your M6Start.m1s and do a few toolchanges and get back

Code: [Select]
selectedTool = getSelectedTool()
currentTool = getCurrentTool()
currentFace = (currentTool - 1) Mod 4
targetFace = (selectedTool - 1) Mod 4
clicks = (targetFace - currentFace + 4) Mod 4
MsgBox "Selected Tool=" & selectedTool & _
       " Current Tool=" & currentTool & _
       " Current Face=" & currentFace & _
       " Target Face=" & targetFace & _
       " Clicks=" & clicks
SetCurrentTool selectedTool
Re: VB Script for toolchanger
« Reply #17 on: April 10, 2014, 10:44:49 AM »
I'll do that and see what the responses are. 

So, in summary, the mod function doesn't care if it is 'a mod b' or 'b mod a', it just takes the remainder after dividing into the larger number? (That is what I meant by acting like a divisor, depending if the first integar is larger than second, would be a fraction at the start.)

Nick

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: VB Script for toolchanger
« Reply #18 on: April 10, 2014, 11:34:17 AM »
So, in summary, the mod function doesn't care if it is 'a mod b' or 'b mod a', it just takes the remainder after dividing into the larger number? (That is what I meant by acting like a divisor, depending if the first integar is larger than second, would be a fraction at the start.)

Nick

It matters very much which number comes first and which comes second. a mod b is most definitely not the same as b mod a. Which is largest and which is smallest is irrelevant. ;)

a mod b evaluates to the remainder after the integer division of a/b. period.

but don't get hung up over this - just run that last piece of code and let me know what happens. If it doesn't give you the correct results then it's for some other reason - it has nothing to do with mod. The code is correct.
Re: VB Script for toolchanger
« Reply #19 on: April 10, 2014, 02:28:57 PM »
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
« Last Edit: April 10, 2014, 02:30:31 PM by nickkinsman »