Hello Guest it is September 15, 2019, 02:54:55 PM

Author Topic: Mach3 VB Script Help  (Read 12566 times)

0 Members and 1 Guest are viewing this topic.

Offline BR549

*
  •  6,886 6,886
    • View Profile
Re: Mach3 VB Script Help
« Reply #20 on: February 10, 2016, 12:54:34 PM »
HI Ian, Very good advice.   I agree take simple steps coding and testing as you go. The first thing I do is get teh motion correct then work on the math.

And just a note  (;-) Ian has helped me a great deal working with Mach3 (;-) His programming advise is HIGHLY valued here.  

Another tip , you are working in 2 motion modes G91 (Inc) and G90 (Abs) don't get them mixed up when you go to move (;-) each has it's own advantages/Disadvantages. AND you can do this several different ways (;-) so there is really no right way or wrong way IF the end results are correct.
Re: Mach3 VB Script Help
« Reply #21 on: February 10, 2016, 03:35:37 PM »
Thanks for the help guys, really appreciate it!

Quote
Code "G91 G31 X-7 F8"
While IsMoving()
Wend
Code"G1 X" & GetVar(2000)  & "F30"

I think you'll find it doesn't do what you think it does. (don't use your real probe to test this Wink)

Yes!! I will definitely be testing with something else, i mentioned earlier I was gonna test with a small copper pipe chucked.

As for what I think the code you wrote would do, im not sure id a g31 will stop ones probe input is triggered, if not then it would move X 7in in - direction, stop at 7 and that's it. If you have If GetOemLed(825) = 0 Then your code it would move the same and stop if triggered then just sit there. Your telling it to G1 X to X's current location. 

Is that right?
Re: Mach3 VB Script Help
« Reply #22 on: February 10, 2016, 04:31:36 PM »
And iif

If GetOemLed(825) = 0 Then
X1 = GetVar(2000)
Code "G91 G31 X-7 F8"
While IsMoving()
Wend
Code"G1 X" & X1 & "F30"

That would move 7 or until triggered then return to starting X position.

Right

Offline BR549

*
  •  6,886 6,886
    • View Profile
Re: Mach3 VB Script Help
« Reply #23 on: February 10, 2016, 06:02:11 PM »
Actually X1 would not have a value or would have teh previous value  from a previous G31.

#2000 would NOT be set untill after teh g31 is run. So in your example there is NO telling where it would end up.

AND because you did not switch back to G90 after the G31 ran the next move would be an inc move not abs. AND teh #2000 value IS an Abs position.

Clear as mud HUH ? (;-)
Re: Mach3 VB Script Help
« Reply #24 on: February 10, 2016, 09:27:15 PM »
Ha-ha okay so the GetVar(2000) it getting the last G31's pobe dro amount, I thought it was to get that the X current position. That's why I was confused ... Okay so hows this:

If GetOemLed(825) =0 Then
Code "G90 G31 X-7 F8"
While IsMoving()
Wend
X1 = GetVar(2000)
Code "G1 X" & X1*.98 & "F8"         
Code "G90 G31 X7 F8 "            ' if I do these as G91 would that keep me in Inc ? Or should I change the G1 to G0? But then I can't input a feed rate the right?  Or keep it G90 and G1?
While IsMoving()
Wend
X2 GetVar(2000)
XZero = (((X2*.5)/(X1*.5))*2)
Code "G1 X" & XZero & "F30
etc.

Offline BR549

*
  •  6,886 6,886
    • View Profile
Re: Mach3 VB Script Help
« Reply #25 on: February 10, 2016, 11:04:07 PM »
You will want to do the probing in INC (G91)mode. You hve to gather teh trip point values for both sides of teh circle. ( X1 ,X2 )You can then do a positional move in INC after you proper calculate the value you need to move OR simply switch  to ABS (G90) mode to do a positional move to Center of space. Then switch back to INC to do teh next G31 call and repeat as needed.



Code "G91"             ' Switch to INC mode
Code" G31 X-7 F8"   'Probe in X- direction
While IsMoving()
Wend
X1 = GetVar(2000)      ' Collect X1 trip position
While IsMoving()
Wend
Code " G0 X.050"         ' Back off switch in X + direction
While IsMoving()
Wend
Code " G31 X14 F8"      ' Probe X + Direction
While IsMoving()
Wend
X2 = GetVar(2000)       '  Collect X2 trip position
While Ismoving()
Wend
Xc =( X2 - X1)             ' This assumes you are in Quandrant 1
While IsMoving()
Wend
Code" G90"                 ' Switch to ABS mode
Code" G0 X" & Xc         ' Move to X center position


« Last Edit: February 10, 2016, 11:11:58 PM by BR549 »
Re: Mach3 VB Script Help
« Reply #26 on: February 11, 2016, 05:31:34 AM »
Okay I see... Well I'm confused with one thing and you worng about another but so was I

Why after
X1 GetVar(2000)
Do you have
While IsMoving()
Wend
?

It's not moving so what say do nothing wile moving

And for finding Xc X1-X2 won't work  is X1=-2 and X2 = 2. You get -2-(+2) or -2-2 how ever you see it and end up with -4 not 0. Now my ((X1*.5)/(X2*.5))*2 is also wrong..

This is correct for any position.
Xc = (X1+X2)/2

As well this line won't work
Code "G0 X.050"
Mesuring a 1" circle you may be at -3.25 getting your first (2000)Var so to back off to .050 would move out of the circle.
That's why I had it like this which should work I believe.
Code "G91"            
Code" G31 X-7 F8"  
While IsMoving()
Wend
X1 = GetVar(2000)      
Code " G0 X" & .98*X1        
While IsMoving()
Wend
Code " G31 X14 F8"      
While IsMoving()
Wend
X2 = GetVar(2000)      
Xc =(X1 + X2)/2
Code "G0 X" & Xc

Code" G90"                 ' Switch to ABS- do this line on my last move back to center after second pass? Or every XcYc
Code" G0 X" & Xc

Offline Tweakie.CNC

*
  • *
  •  7,903 7,903
  • Super Kitty
    • View Profile
    • Tweakie.CNC
Re: Mach3 VB Script Help
« Reply #27 on: February 11, 2016, 06:39:09 AM »
Quote
Why after
X1 GetVar(2000)
Do you have
While IsMoving()
Wend
?

It's not moving so what say do nothing wile moving

It's just one of those things you learn to love about Mach3 interpreting Cypress Enable - it is always best to tell it to wait until one operation is completed before moving on to the next (it is unimportant if anything is actually moving or not).

Tweakie.
Success consists of going from failure to failure without loss of enthusiasm.  Winston Churchill.
Re: Mach3 VB Script Help
« Reply #28 on: February 11, 2016, 03:17:19 PM »
understood but that will not help you.

When you call While IsMoving() Wend that While statement will be skipped if not moving. If all axis are stationary then when you get to that line of code it will pull a False, skip it, then move to the next line. If you really want it to wait then you should use WScript.sleep(500) half second pause. that will wait.

But this is also code, this runs Very Very fast and very accurate. and Arduino at 16Mhz can process each line in less then 2 microseconds. I'm not sure if mach uses your computers processor speed or not but that's in GHZ. My PC is at 4.97GHZ, So thats nano seconds.

But on a coding line, to make a variable equal to a already stored number, wouldn't need a delay to update. Now maybe wile updating the DRO or something visual, that may take some time and you may want to pause. Even a really long math equation wouldn't need a delay, the computer will not go to the next line of code till the current has been completed. Back to the visual update, a line of code may send a Msg Box out and not actually show till another 27 lines of code have been processed. so yes a pause is needed at times but for a variable to get a value I dont think one is necessary.

  Not to rain on your parade and I might be wrong here but its what I  understood and I don't think that line will benefit you their.

Offline BR549

*
  •  6,886 6,886
    • View Profile
Re: Mach3 VB Script Help
« Reply #29 on: February 11, 2016, 05:56:41 PM »
(;-) WHile Ismoving is NOT just about MOVING it is about anytime MACH3 is doing something.  ALSO there is a problem with Mach 3 and CB spawning multiple threads at teh same time and loosing control over teh exact order of execution. SO it is left to teh programer to maintain order of execution in most cases.

You have a LOT to learn about Mach3 Grasshopper.

Another thing you MUST keep in mind is that mach3 is a GCODE motion controller. It is NOT a general purpose motion controller driven by scripting . Macros mixed with Gcode was an afterthought . MOST other controllers went with conditional Gcode instead of Macro interfaces to teh Gcode and in doing so can be much more stable AND FASTER in Gcode execution.

NOW once you learn how Mach3 works and learn most of the quircks MUCH can be done with it.  Just keep in mind that teh sampling rate of teh macros is ONLY 10 hz VERY SLOW as compared to other forms of motion control. SO by its own working Mixed Gcode macro can be very slow to function.

(;-) TP