Hello Guest it is September 20, 2019, 06:34:55 AM

### Author Topic: Mach3 VB Script Help  (Read 12582 times)

0 Members and 1 Guest are viewing this topic.

#### nissan20det

• 88
##### Re: Mach3 VB Script Help
« Reply #70 on: February 14, 2016, 01:16:42 AM »
Okay I thought about it real hard, I haven't tried this yet but I think Im getting there. Only thing I worry about is it being able to do the math right. I know for a fact my equations are right if all variables are in abs... I swear this has gatta be close.

Code: [Select]
`Message "Finding Circle Center"CurrentFeed = GetOemDRO(818) If GetOemLed (825) <> 0 Then            Message "Z-Plate is grounded, check connection and try again"   ElseCode "G90"Code "G31 X-7 F20"    While IsMoving()Sleep(200)Wend                                          X1 = GetVar(2000)Sleep(90)XF1 = X1*.9   'this is to set my X G0 fast point to stop 90% from edge on second pass,If I did X1+.05 it could add it if X1 is Positive, It wouldn't work anywhere                                                      Sleep(90)Code "G91 G0 X.10"While IsMoving()Sleep(90)                  WendSleep(90)                                                SetDro(3,XF1)              ' these are not to confuse the machine, there just telling me my variables, I dont use  A B and C while doing this test ill remove later Code "G31 X7 F20"While IsMoving()Sleep(250)WendX2 = GetVar(2000)XF2 = X2*.9Sleep(90)   XC1 = X1+X2   'X2-X1 this doesnt work if X2=8 X1=-3 -3(-)+8=-11  So this would not work anywhere on table...this does->(-3+8)/2=5/2=2.5XC2 = XC1/2Sleep(200)Code "G0 X" & XC2While IsMovingSleep(250)Wend   Code "G31 Y-3 F20"    While IsMoving()Sleep(200)Wend                                          Y1 = GetVar(2001)Sleep(90) YF1 = Y1*.9Sleep(90)                                    Code "G91 G0 Y.10"While IsMoving()Sleep(90)WendCode "G90"Code "G31 Y3 F20"While IsMoving()Sleep(200)WendY2 = GetVar(2001)Sleep(90) YF2 = Y2*.9Sleep(90) SetDro(4,YF2)Sleep(90)   YC1=Y1+Y2Sleep(90)YC2 = YC1/2Sleep(90)Code "G0 Y" & YC2While IsMoving()Sleep(200)Wend Sleep(90)Code "G0 X" & XF1While IsMoving()Sleep(200)WendCode "G31 X-3.5 F4"While IsMoving()Sleep(200)WendX1 = GetVar(2000)Sleep(90)  Code "G0 X" & XF2 While IsMoving()Sleep(200) Wend Code "G31 X3.5 F4"While IsMoving()Sleeo(200)WendX2 = GetVar(2000) Sleep(90)   XC1= X1+X2Sleep(90)XC2 = XC1/2Sleep(90) Code "G0 X" & XC2       End If`
« Last Edit: February 14, 2016, 01:20:37 AM by nissan20det »

#### nissan20det

• 88
##### Re: Mach3 VB Script Help
« Reply #71 on: February 14, 2016, 03:36:45 PM »
O another thought, when you fetch X value 2000 in a G31 call, say its Negative, will it make the variable you assign Neg, or just assign the value?

You guys say to read up about all this, I really cant find much litterateur out there about teh quadrant math or really anything in depth its all basic stuff which I've read lot's. Could you guys hook me up with a link maybe?

#### nissan20det

• 88
##### Re: Mach3 VB Script Help
« Reply #72 on: February 14, 2016, 08:10:55 PM »
well I made an adjustment to this after making a Z touch plate script. That I got to work great!! heres the touch plate script then adjustmants
Code: [Select]
`PlateThickness = 0.030Message "Auto Zeroing Z Axis"If GetOemLed(825)<>0 ThenMessage"Probe Grounded, Check Connection And Try Again"ElseCode"G91 G31 Z-5 F4"While IsMoving()Sleep(200)WendZ1= GetVar(2002)Sleep(90)Code "G0 Z" & Z1While IsMoving()Sleep(100)WendSetDro(2,PlateThickness)Code(G91 G0 Z.97)Message "Z Axis Tool Zeroed"End If`
Code: [Select]
`Message "Finding Circle Center"CurrentFeed = GetOemDRO(818) If GetOemLed (825) <> 0 Then            Message "Z-Plate is grounded, check connection and try again"   ElseCode "G91 G31 X-7 F20"    While IsMoving()Sleep(200)Wend                                          X1 = GetVar(2000)Sleep(90)XF1 = X1*.9   'this is to set my X G0 fast point to stop 90% from edge on second pass,If I did X1+.05 it could add it if X1 is Positive, It wouldn't work anywhere                                                      Sleep(90)Code "G91 G0 X.10"While IsMoving()Sleep(90)                  WendSleep(90)                                                SetDro(3,XF1)              ' these are not to confuse the machine, there just telling me my variables, I dont use  A B and C while doing this test ill remove later Code "G91 G31 X7 F20"While IsMoving()Sleep(250)WendX2 = GetVar(2000)XF2 = X2*.9Sleep(90)   XC1 = X1+X2   'X2-X1 this doesnt work if X2=8 X1=-3 -3(-)+8=-11  So this would not work anywhere on table...this does->(-3+8)/2=5/2=2.5XC2 = XC1/2Sleep(200)Code "G0 X" & XC2While IsMovingSleep(250)Wend   Code "G91G31 Y-3 F20"    While IsMoving()Sleep(200)Wend                                          Y1 = GetVar(2001)Sleep(90) YF1 = Y1*.9Sleep(90)                                    Code "G91 G0 Y.10"While IsMoving()Sleep(90)WendCode "G91 G31 Y3 F20"While IsMoving()Sleep(200)WendY2 = GetVar(2001)Sleep(90) YF2 = Y2*.9Sleep(90) SetDro(4,YF2)Sleep(90)   YC1=Y1+Y2Sleep(90)YC2 = YC1/2Sleep(90)Code "G0 Y" & YC2While IsMoving()Sleep(200)Wend Sleep(90)Code "G0 X" & XF1While IsMoving()Sleep(200)WendCode "G91 G31 X-3.5 F4"While IsMoving()Sleep(200)WendX1 = GetVar(2000)Sleep(90)  Code "G0 X" & XF2 While IsMoving()Sleep(200) Wend Code "G91 G31 X3.5 F4"While IsMoving()Sleeo(200)WendX2 = GetVar(2000) Sleep(90)   XC1= X1+X2Sleep(90)XC2 = XC1/2Sleep(90) Code "G0 X" & XC2       End If`

#### BR549

• 6,895
##### Re: Mach3 VB Script Help
« Reply #73 on: February 14, 2016, 09:12:34 PM »
NOPE not yet you just traded one problem for another.

(;-) TP

#### nissan20det

• 88
##### Re: Mach3 VB Script Help
« Reply #74 on: February 15, 2016, 02:09:48 AM »
Crap.. Okay let me work on this a bit..

#### BR549

• 6,895
##### Re: Mach3 VB Script Help
« Reply #75 on: February 15, 2016, 09:07:51 AM »
Thee are 4 quadrants in CNC work based on X0Y0 being the point of origin.  Top Right, Top LEft,Bottom Left,Bottom Rightalso known as Q1,Q2,Q3,Q4.

Q1 =  X+ & Y+
Q2 = X- & Y+
Q3 = X- & Y-
Q4 = X+ & Y-

There is also the possiblility that you could work in 1 or MORE quuadrants at teh same time where there would be any comibinations of teh XY values.

MOST people work inside of  Q1 for a good reason. Being X+ & Y+ it makes the math VERY easy and very consistant. I suggest you do the same at this point. That would put your POE (point of origin, X0 Y0) at teh lower left of your work and NONE of your work extends out of that quadrant.

Things should make a little more sense at that point math wise.

You are still having a problem with ABS and INC values and how you are using them.  You have to keep the 2 values seperate in your head as each has to be treated differently when you use them to move somewhere.

Your % of a move move is still going to bite you in teh rear. You need to get rid of it and work that move  out another way.

Strip it all out but teh first X seires of moves, Get that part working correctly and it GOING to teh exact center of X EVERY time and EVERY position inside of Q1 THEN start adding parts back into your routine.  One set of equations will work ANYWHERE inside of Q1.

STOP writing to teh DROs you do NOT need to do that. IF you really want to know the value or 2000 or 2001 then learn to use the built in Var monitor.

Also remember that WHERE you stop with G31 is NOT teh same as #2000,#2002.

(;-) TP

« Last Edit: February 15, 2016, 09:15:40 AM by BR549 »

#### BR549

• 6,895
##### Re: Mach3 VB Script Help
« Reply #76 on: February 15, 2016, 09:17:10 AM »
Thee are 4 quadrants in CNC work based on X0Y0 being the point of origin.  Top Right, Top LEft,Bottom Left,Bottom Rightalso known as Q1,Q2,Q3,Q4.

Q1 =  X+ & Y+
Q2 = X- & Y+
Q3 = X- & Y-
Q4 = X+ & Y-

There is also the possiblility that you could work in 1 or MORE quuadrants at teh same time where there would be any comibinations of teh XY values.

MOST people work inside of  Q1 for a good reason. Being X+ & Y+ it makes the math VERY easy and very consistant. I suggest you do the same at this point. That would put your POE (point of origin, X0 Y0) at teh lower left of your work and NONE of your work extends out of that quadrant.

Things should make a little more sense at that point math wise.

You are still having a problem with ABS and INC values and how you are using them.  You have to keep the 2 values seperate in your head as each has to be treated differently when you use them to move somewhere. IF you are going to use an INC value to move you must be in G91 mode and IF you are going to use an ABS vlaue to move you must be in G90 mode.

Your % of a move move is still going to bite you in teh rear. You need to get rid of it and work that move  out another way.

(;-) TP

#### RICH

• 7,361
##### Re: Mach3 VB Script Help
« Reply #77 on: February 16, 2016, 11:35:29 AM »
Quote
You guys say to read up about all this, I really cant find much litterateur out there about teh quadrant math or really anything in depth its all basic stuff which I've read lot's. Could you guys hook me up with a link maybe?

TP's reply #75 is the equivilant for what you would find in one of the beginning chapters of the book I suggested you get / read / study. Additionaly he gives you practical reason for use of that info.

Why was the book suggested......because its a highly regaurded proffessional reference for CNC by one of the best CNC authors. You will fumble around looking at all kinds of info from different sites, different books / articles / for answers to basic stuff, and it can go on forever, and you will not have gained the basic knowledge that you should have. That's because your looking for an answer rather than the understanding.
The MAch reference manuals are about the specifics of MACH software and fall short on the the topic of CNC and assumes you have basic knowledge.

Let's assume that you understand the G90, G91, G31, G0 & G1  Mach Coordinates, etc.

++++++++++++++++++++++

So now you desire to do some programming...well welcome to another new learning curve!
It would be nice if one had some programming experience and a lot of the info listed below will not provide program teaching, but, they are resource you should have on hand.

1. Macro3 Macro Programmers Reference Manual
2. Mach2 Customisation Guide
3. MachScreen
4. OEM Series Button, DRO, and LED Numbers

There is a lot to be learned by having a read of posts and replies in the following:
You may even find a wizard or Macro that does what you want.
- VB and the development of wizards
- MACH TOOL BOX

Lot of ways to do things and looking at scripting done by others is very helpfull.
You can look at the VB script to see how it was done or what it is meant to do. Have a look under Operator tab in Mach and you'll see the following to look at scripting:
- Edit Button Script
- Ccode Var Monitor
- VB Script Editor
- look at some macro's in the macro folder of where Mach  is installed.
I listed Mach Screen as you will find associated scripts for buttons etc.

RICH
« Last Edit: February 16, 2016, 11:38:00 AM by RICH »

#### nissan20det

• 88
##### Re: Mach3 VB Script Help
« Reply #78 on: February 16, 2016, 07:39:56 PM »
LOL Rich I have already done everything you posted but go buy that book.. well two you posted I havent seen so thank you lol

Thats how I learned C++ is reading code, and a library. I cant find one bit of code online for mach 3 other than 3 or 4 touch plate scripts. I might not be typing in the right things but Im talking 22hrs at least of looking, reading, thinking.

As of your Q1,Q2,Q3,Q4 I already understood that. Machine Coords are always in Q1, I work in Q1, I zero holes 0,0... 4 quadrants, That means a equation in the wrong quadrant would add instead of subtract ect... Can someone just explain why the % equation wont work?? 98% of a Neg is a Neg. as well the (X1 + X2)/2 No matter the quadrant the answer is always the center. You can make any of those two(X1 or X2) Neg or Pos and it always comes out center?? How im I screwing this up!!

Give me an example of numbers that you plug into my equations that come out wrong. That would make me understand
« Last Edit: February 16, 2016, 07:43:08 PM by nissan20det »

#### ger21

• 6,288
##### Re: Mach3 VB Script Help
« Reply #79 on: February 16, 2016, 07:52:00 PM »
I was curious myself about the quadrant thing. No matter what quadrant you work in, the math should always be the same..
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html