Hello Guest it is September 22, 2019, 12:31:06 AM

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

0 Members and 1 Guest are viewing this topic.

Mach3 VB Script Help
« on: February 09, 2016, 12:05:50 AM »
Hey guys so I'm wanting to write up my own code for that piezo probe I made. Was wondering if any of you code stuff yourself and could give me a hand.

I'm pretty familiar with arduino coding but I see that Vb script is a bit different. So far what I got is working but I want to do 3 passes when finding a circles center. I would like the first pass to be around F10 then after the machine touches 3 or 4 points at first, I would like the second pass to move around F30 but slow to f4 when a declared distance from touching is passed. Then same with third pass but slow to F1, when say .030" from touching.

Would any of you know how to code that. I don't need you to write the entire code, but just an example of how to make a slow zone in VB script format.

Thanks, Zach

Offline ger21

*
  • *
  •  6,288 6,288
    • View Profile
    • The CNC Woodworker
Re: Mach3 VB Script Help
« Reply #1 on: February 09, 2016, 12:15:29 AM »
You just change the feedrate in the script.

Code "F4"
Gerry

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

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: Mach3 VB Script Help
« Reply #2 on: February 09, 2016, 01:42:50 AM »
No Im saying I set it to move till probe touched at F10 but when close to the edge, say .1" slow to F5..... like this but in VB format. This is close, I got most this from a touch plate and just made my own. It most likely needs changes.

Code: [Select]
Message "Finding Circle Center"
CurrentFeed = GetOemDRO(818)
 If GetOemLed (825) <> 0 Then     
      Message "Z-Plate is grounded, check connection and try again" 'this goes in the status bar if aplicable
   Else
Code "G90 G31 X-7 F10"     'Is that right? or should I be using a G1
While IsMoving()
Wend                                  'Whats Wend for?
Call SetDro (X,0)    'Is this Right?? want to set X Dro to Zero
Code "G90 G31 X7 F10
While IsMoving()
Wend
XMax = GetVar(?)     'What is the Var for X's Dro?
XMax/2 = XZero
Code "G90 G31 XXzero F10"     'Would this work?
Code "G90 G31 Y-3 F10"
While IsMoving()
Wend
Call SetDro (Y,0)        'Is this Right??
Code "G90 G31 Y3 F10
While IsMoving()
Wend
YMax = GetVar(?)    'What is the Var for X's Dro?
YMax/2 = YZero
Code "G90 G31 YYzero F10"     'I  Dont think this is right
Code "G90 G31 X-7 F30"
While IsMoving(
if X<.1(Setfeedrate F5) )  'how do I change feed rate while moving like soft limit?
Wend
Call SetDro (X,0)    'Is this Right?? want to set X dro to zero
Code "G90 G31 X7 F30
While IsMoving(
if X>.1-XMax(Setfeedrate F5))
Wend
XMax = GetVar(?)      'What is the Var for X's Dro?
XMax/2 = XZero
Code "G90 G31 XXzero F10"     'Dont think this is right
ode "G90 G31 Y-3 F30"
While IsMoving(if Y<.1(Setfeedrate F5))
Wend
Call SetDro (Y,0)    'Is this Right??
Code "G90 G31 Y3 F30
While IsMoving(
if X>.1-YMax(Setfeedrate F5))
Wend
YMax = GetVar(?)      'What is the Var for X's Dro?
YMax/2 = YZero
Code "G90 G31 YYzero F10"     'I  Dont think this is right
Code "G90 G31 X-7 F30"
While IsMoving(
if X<.02(Setfeedrate F2) )    'how do I change feed rate while moving like soft limit?
Wend
Call SetDro (X,0)      'Is this Right?? want to set X dro to zero
Code "G90 G31 X7 F30
While IsMoving(
if X>.02-XMax(Setfeedrate F2))
Wend
XMax = GetVar(?)       'What is the Var for X's Dro?
XMax/2 = XZero
Code "G90 G31 XXzero F30"     'Dont think this is right
Call SetDro(X,0)                   
Code "G90 G31 Y-3 F30"
While IsMoving(if Y<.02(Setfeedrate F2))
Wend
Call SetDro (Y,0)       'Is this Right??
Code "G90 G31 Y3 F30
While IsMoving(
if X>.02-YMax(Setfeedrate F2))
Wend
YMax = GetVar(?)       'What is the Var for X's Dro?
YMax/2 = YZero
Code "G90 G31 YYzero F30"     'I  Dont think this is right
Call SetDro(Y,0)
Code "G1 Z3 F20"     'Is this what My code should be instead of G90 G31?
Message "Circle Center Found"

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: Mach3 VB Script Help
« Reply #3 on: February 09, 2016, 07:06:40 AM »
You may be over-complicating things. If we look at your various probe directions as being north, south, east and west. You seem to be going west, east, south, north, then again and then again.

Might be better if you did west, west, west, east, east, east etc. etc.

HOWEVER - Although some say for improved accuracy you should probe TWICE, once at some speed and then again at a a lower speed, I can't see any value in doing it THREE times.

You also shouldn't use the values in the DROs as your trip points. You should read the parameters 2000 (X) and 2001 (Y).

Here's a trivial example of a 1 shot probe which assumes you've placed the probe roughly at the centre of your circular pocket (you need to replace ? with some number):

code "G31 X?" 'where ? is some number guaranteed to get you to the circumference
while isMoving()
  sleep 10
wend
tripX = getVar(2000) 'variable tripX now holds the exact point of the trip

Now if you want to probe again, you'd just reverse a bit past the trip point and do exactly the same again.

Disclaimer: If any of the above breaks anything (including your heart) - you get to keep the pieces.

Offline RICH

*
  • *
  •  7,361 7,361
    • View Profile
Re: Mach3 VB Script Help
« Reply #4 on: February 09, 2016, 08:34:12 AM »
 FWIW,

There is a lot of info on probing and no need to reinvent the wheel, but,  different scripting tips by different users is always worth noteing.
My personal VB skills are low on the ability scale.

- Have a look at the Mach mill manual for G31 command and note that there is an example code for probing a hole by Art.
- I have a pdf about probing ( written for my lathe screen use but still applies ) and can shed light about probing only once or multiple times.

RICH

Offline BR549

*
  •  6,898 6,898
    • View Profile
Re: Mach3 VB Script Help
« Reply #5 on: February 09, 2016, 12:31:29 PM »
Just remember that once you trip you cannot imediately reprobe in another direction you have to back off the trip point before you can use G31 again.

G91
G31  X10  ( Probe X Right)
G0 X-.050 ( Back off to untrip probe)
G31 X-10  ( Probe X Left)

Also there is really no need to double or triple tap with teh G31 (;-)

And as Stirling mentioned you may be severvely overthinking the process . The only hting you need to keep in account is the amount of overrun your particular probe has before it is damaged.  Normal that type of sensor has little to no overun capability before it breaks something. The probeing process will alwyas have some overrun as teh machine comes to a safe stop on trip. The slower your accel rate is and teh faster you probe the more overrun you will see.
Re: Mach3 VB Script Help
« Reply #6 on: February 09, 2016, 04:19:06 PM »
This is what i was going after- https://www.youtube.com/watch?v=_ZDlyLI_jbc

Rich- I'm not sure If I was looking at the right manual but It was section 10.7.12.3, What is all that N010 coding? I've never seen that. So in that manual it said a G31 will move till tripped then back off slightly. Is this enough to just have the next line of code to do a G31 - move in opposite direction or do I need a G1 -move to fully pull off before the next G31 command?

Well I really like the idea of at least two passes, as well the second pass going faster and slowing down. Okay so let me know this looks...

Where are all these codes located? Like x being 2000 Y 2001 and Probe switch being 818? Cuz I also saw Probe can be 22, is there a list somewhere?

Thanks guys I really appreciate the help!

And Ill most likely test this code with a soft copper tube using conductivity.


Code: [Select]
Message "Finding Circle Center"
CurrentFeed = GetOemDRO(818)
 If GetOemLed (825) <> 0 Then     
      Message "Z-Plate is grounded, check connection and try again" 'this goes in the status bar if aplicable
   Else
Code "G91 G31 X-7 F8"     'Is this right now with G91?
While IsMoving()
Wend                                          'Whats Wend for? Still not sure what this is for
Xmin = GetVar(2000)                                 
                 Do I need a G1 pull off command here , as well as after every trip?
Code "G91 G31 X7 F8"
While IsMoving()
Wend
XMax = GetVar(2000)   
XMax-Xmin = XZero
Code "G1 XXZero F30"     'To return to center should I just use a rapid or liniear move instead of G31?
   'as well is calling a variable in a code line acceptable?
Code "G91 G31 Y-3 F8"
While IsMoving()
Wend
YMin = GetVar(2001)
Code "G91 G31 Y3 F8"
While IsMoving()
Wend
YMax = GetVar(2001)   
YMax-YMin = YZero
Code "G1 YYZero F30"     
Code "G91 G31 X-7 F30"
While IsMoving(
if X<.95*XMin(Code F2))  'I would still like the second pass to move fast then slow, even if complicated I just like the idea. 
    'Whats the command to set feed rate by its self? (Code F5)?
Wend
XMin = GetVar(2000)   
Code "G91 G31 X7 F30
While IsMoving(
if X>.95*XMax(Code F2))
Wend
XMax = GetVar(2000)     
XMax-XMin = XZero
Code "G1 XXZero F30"     
ode "G91 G31 Y-3 F30"
While IsMoving(
if Y<.95*YMin(Code F5))
Wend
YMin = GetVar(2001)
Code "G91 G31 Y3 F30
While IsMoving(
if X>.95*YMax(Code F5))
Wend
YMax = GetVar(2001)     
YMax-YMin = YZero
Code "G1 YYZero F30"   
Message "Circle Center Found"
« Last Edit: February 09, 2016, 04:25:41 PM by nissan20det »

Offline BR549

*
  •  6,898 6,898
    • View Profile
Re: Mach3 VB Script Help
« Reply #7 on: February 09, 2016, 04:53:35 PM »
The G31 does NOT stop and back off. You must back off teh switch before issueing another G31 or else you WILL get an error.  

AND just for the record you do not gain any accuracy by slowing down or double tapping (;-)

The N010 is just a line number statement in Gcode.It is not required but can be used.

Also remember that you are moving in incremental values BUT teh stored variables (2000 & 2001) are absolute values of position. That will effect your math depending on the quadrant you are currently working in.

You are getting closer (;-) TP

« Last Edit: February 09, 2016, 05:06:54 PM by BR549 »
Re: Mach3 VB Script Help
« Reply #8 on: February 09, 2016, 05:10:07 PM »
LOL thanks, And Yea accuracy or not I think it looks cool hahaha

Okay updated with pulloffs set at 98% of Mins, After every Max recording Is a G1 to XZero/YZero so I only need them on the Min's right?

Code: [Select]
Message "Finding Circle Center"
CurrentFeed = GetOemDRO(818)
 If GetOemLed (825) <> 0 Then     
      Message "Z-Plate is grounded, check connection and try again"
   Else
Code "G91 G31 X-7 F8"     'Is this right now with G91?
While IsMoving()
Wend                                          'Whats Wend for? Still not sure what this is for
Xmin = GetVar(2000)                                 
Code "G1 X.98*XMin F8"                would this work?
Code "G91 G31 X7 F8"
While IsMoving()
Wend
XMax = GetVar(2000)   
XMax-Xmin = XZero
Code "G1 XXZero F30"       'as well is calling a variable in a code line acceptable?
Code "G91 G31 Y-3 F8"
While IsMoving()
Wend
YMin = GetVar(2001)
Code "G1 Y.98*XMin F8"
Code "G91 G31 Y3 F8"
While IsMoving()
Wend
YMax = GetVar(2001)   
YMax-YMin = YZero
Code "G1 YYZero F30"     
Code "G91 G31 X-7 F30"
While IsMoving(
if X<.95*XMin(Code F2))  'I would still like the second pass to move fast then slow, even if complicated I just like the idea. 
    'Whats the command to set feed rate by its self? (Code F5)?
Wend
XMin = GetVar(2000)
Code "G1 X.98*XMin F8"   
Code "G91 G31 X7 F30
While IsMoving(
if X>.95*XMax(Code F2))
Wend
XMax = GetVar(2000)     
XMax-XMin = XZero
Code "G1 XXZero F30"     
ode "G91 G31 Y-3 F30"
While IsMoving(
if Y<.95*YMin(Code F5))
Wend
YMin = GetVar(2001)
Code "G1 X.98*YMin F8"
Code "G91 G31 Y3 F30
While IsMoving(
if X>.95*YMax(Code F5))
Wend
YMax = GetVar(2001)     
YMax-YMin = YZero
Code "G1 YYZero F30"   
Message "Circle Center Found"

Offline BR549

*
  •  6,898 6,898
    • View Profile
Re: Mach3 VB Script Help
« Reply #9 on: February 09, 2016, 05:34:04 PM »
You cannot mix CB variable code inside of Gcode calls. You will have to seperate them .

Also you have problem with your return to zero math and mixing inc moves with abs values.

(;-) TP