Hello Guest it is March 28, 2024, 10:33:44 PM

Author Topic: VB syntax  (Read 14857 times)

0 Members and 1 Guest are viewing this topic.

Re: VB syntax
« Reply #10 on: March 20, 2009, 03:54:43 PM »
I finally figured it out by just using one variable in one line of code until I got that to work and then added a second variable and worked at it until I got it to work. This is the result

V = GetVar (550)
V1 = V/2.
Code "G90 G92 X0. Y0."
Code "G01 X"&V1 & "Y"&V1
Code "G03 X.0 Y"&V & "I-"&V1 & "J.0 G90"
Code "G03 X.0 Y"&V & "I.0 J-"&V & "G90"
Code "G03 X-"&V1 & "Y"&V1 & "I.0 J-"&V1 & "G90"
Code "G01 G90 X.0 Y.0"
Code "G92.1"
End          

I had to get all of the quotes and &s in the right place.
The way it works is you put "&variable where the number would go and if there is more G code to follow on the same line it looks like this

Code "G01 X"&variable &"Y"&variable &"Z-.25"

There needs to be a space between variable and &"
Re: VB syntax
« Reply #11 on: March 20, 2009, 03:56:41 PM »
Looks like I was typing while you were posting. Your answer is exactly what I figured out.

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: VB syntax
« Reply #12 on: March 20, 2009, 06:03:41 PM »
V = GetVar(550)
U = GetVar(551)

Code "G90 G00 X" & V & " Y" & U

'scott
fun times

vmax549

*
Re: VB syntax
« Reply #13 on: March 20, 2009, 06:54:29 PM »
OH boy that is going to be wicked to follow(;-) and sometimes MACH struggles badly with mixed code.

You could transfer the  VBvars over to Gcode vars and run in native gcode.

NOTE I don't thinkYou can run code such as   & "I.0 J-"&V1  Mach may  throw an error with the   "J-" not followed by a real number. You may have to convert the Var to a Neg number.

V = GetVar (550)
V1 = V/2.
Code "G90 G92 X0. Y0."
Code "G01 X"&V1 & "Y"&V1
Code "G03 X.0 Y"&V & "I-"&V1 & "J.0 G90"
Code "G03 X.0 Y"&V & "I.0 J-"&V & "G90"
Code "G03 X-"&V1 & "Y"&V1 & "I.0 J-"&V1 & "G90"
Code "G01 G90 X.0 Y.0"
Code "G92.1"
End         


This Type programming will run fine and not cause any MACH confusion(;-)


SetParam(1, GetVar (550))
SetParam(2,( 1/2))
Code "G90 G92 X0. Y0."
Code "G01 X[#2] Y[#2]"
Code "G03 X.0 Y[#1] I.0 J.0 G90"
Code "G03 X.0 Y[#1] I.0 J[-1*#1]G90"
Code "G03 X[-1*#2] Y[#2] I.0 J[-1*#2]G90"
Code "G01 G90 X.0 Y.0"
Code "G92.1"
End

(;-) TP         

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: VB syntax
« Reply #14 on: March 20, 2009, 07:29:50 PM »
TP,

  SetParam is not the one you want, that is for setting machine parameters for motor tuning, etc.

you want:  SetVar(var#, value), and GetVar(var#)

these equate to the G Code  #parameter number.

I.e.    #6 = 10 written from G code or MDI
in VB, GetVar(6) would = 10

To set it, by VB would be: SetVar(6,12)  would set the G Code parameter 6 to value 12

you can check this in the VB scripter, and the "G code Var Monitor" window under "Operator" will also give the the value of that parameter/Var

scott
fun times
Re: VB syntax
« Reply #15 on: March 20, 2009, 08:10:45 PM »
Well I tried

GetVar (550)
SetVar(551,(550/2))
Code "G90 G92 X0. Y0."
Code "G01 X[#551] Y[#551]"
Code "G03 X.0 Y[#550] I.0 J.0 G90"
Code "G03 X.0 Y[#550] I.0 J[-1*#550]G90"
Code "G03 X[-1*#551] Y[#551] I.0 J[-1*#551]G90"
Code "G01 G90 X.0 Y.0"
Code "G92.1"
End   

and var #551 equaled 275 so I tried

v = GetVar (550)
v = v/2
SetVar(551,v)
Code "G90 G92 X0. Y0."
Code "G01 X[#551] Y[#551]"
Code "G03 X.0 Y[#550] I.0 J.0 G90"
Code "G03 X.0 Y[#550] I.0 J[-1*#550]G90"
Code "G03 X[-1*#551] Y[#551] I.0 J[-1*#551]G90"
Code "G01 G90 X.0 Y.0"
Code "G92.1"
End   

 and got the zero radius arc error  even though the var monitor shows that #551 was properly set.

so I tried just doing the
  
v = GetVar (550)
v = v/2
SetVar(551,v)
 in the M code and the rest in a G-code file

#550 = .5
G0G90X.25Y-.25
M79
G90 G92 X0. Y0."
G01 X[#551] Y[#551]"
G03 X.0 Y[#550] I.0 J.0 G90"
G03 X.0 Y[#550] I.0 J[-1*#550]G90"
G03 X[-1*#551] Y[#551] I.0 J[-1*#551]G90"
G01 G90 X.0 Y.0"
G92.1"

and still got the error. This code works

V = GetVar (550)
V1 = V/2.
Code "G90 G92 X0. Y0."
Code "G01 X"&V1 & "Y"&V1
Code "G03 X.0 Y"&V & "I-"&V1 & "J.0 G90"
Code "G03 X.0 Y"&V & "I.0 J-"&V & "G90"
Code "G03 X-"&V1 & "Y"&V1 & "I.0 J-"&V1 & "G90"
Code "G01 G90 X.0 Y.0"
Code "G92.1"
End 

and you call it from the G-code like this

#550 = .5
G0 G90 X.25 Y-.25
M79

It runs and does a nice hole milling cycle. #550 is set to the radius of the hole minus the radius of the tool.


« Last Edit: March 20, 2009, 08:19:51 PM by MachineMaster »

vmax549

*
Re: VB syntax
« Reply #16 on: March 20, 2009, 10:55:36 PM »
As long as it works for YA go for it. (;-)


Now that I took the time to plot out exactly what you were doing(;-) Try this, it draws out the circle starting from the center point and does a small leadin arc CIRCLE and leadout arc then back to centerpoint.

Code"#550=.5"
Code"#551=[#550/2]"
Code"G90 G92 X0. Y0."
Code"G01 X[#551] Y[#551]"
Code"G03 X.0 Y[#550] I[-1* #551] J.0 G90"
Code"G03 X.0 Y[#550]I.0 J[-1*#550] G90"
Code"G03 X [-1*#551] Y[#551] I.0 J[-1*#551] G90"
Code"G01 G90 X.0 Y.0"
Code"G92.1"


YOu could also make the Macro programable for hole size and bit size By the use of Param1, Param2 to load the hole size and bit size into the macro or VARs on the fly

M500  P1.000 Q.250  (1.000" hole size, .250"bit)

Just another way to think about it, (;-) TP


PS:  We need to start a MACH TOOL BOX section to store all the neat code that shows up from time to time. (;-)
« Last Edit: March 20, 2009, 11:40:33 PM by vmax549 »
Re: VB syntax
« Reply #17 on: March 21, 2009, 01:45:42 AM »
The idea for this bit of code came from Bridgeport's G79 boring cycle. I took your code above and changed it to this

'M79.m1s
GetVar (550)
Code"#551=[#550/2]"
Code"G90 G92 X0. Y0."
Code"G01 X[#551] Y[#551]"
Code"G03 X.0 Y[#550] I[-1* #551] J.0 G90"
Code"G03 X.0 Y[#550]I.0 J[-1*#550] G90"
Code"G03 X [-1*#551] Y[#551] I.0 J[-1*#551] G90"
Code"G01 G90 X.0 Y.0"
Code"G92.1"
End

and it will bore any size hole by calling it like this

G0G90X1.Y1. (Position to hole center)
G01Z-.5 F10. (feed to depth)
#550 = 1.    (radius of hole-radius of tool)
M79
G0Z0

I use this code to bore multiple holes of different sizes in an enclosure.

vmax549

*
Re: VB syntax
« Reply #18 on: March 21, 2009, 10:17:49 AM »
OR you could make it programable like this



'M79.m1s
Setvar(550,Param1)
Code"#551=[#550/2]"
Code"G90 G92 X0. Y0."
Code"G01 X[#551] Y[#551]"
Code"G03 X.0 Y[#550] I[-1* #551] J.0 G90"
Code"G03 X.0 Y[#550]I.0 J[-1*#550] G90"
Code"G03 X [-1*#551] Y[#551] I.0 J[-1*#551] G90"
Code"G01 G90 X.0 Y.0"
Code"G92.1"
End

and it will bore any size hole by calling it like this

G0G90X1.Y1. (Position to hole center)
G01Z-.5 F10. (feed to depth)
M79 P1.000
G0Z0

Yep Parametric programing is FUN and can be very usefull . It would be nice to get a MACH collection of usefull macros. There are all type of macros out there for OTHER systems. There are macros to do serial numbers , engraving, elispes, facing, circles, squares, drill patterns. thread milling, TAPER thread milling, etc

 We have learned a few more unpublished mach tricks as well. Such as conditional programming inside Gcode with directional code. You can do the conditional part from a macro and from inside the macro you can redirect anywhere back inside the gcode by the use of a M98 call to the Oword in the gcode. Doing it this way allows you to move around inside the Gcode without the use of the M99(return). Also if you make the macro a simple phase it can be a generic programable macro that can be used many differrent ways.

M502 P3 Q1

' Macro.M1s
IF Param1 < Param2  Code" M98 P100"   The macro checks the condition of the statement and then redirects mach to the  O100 word in the Gcode file.

Note : mach limits us to ONLY 3 arguments doing it this way. It would be really NICE if we had a least 5 arguments instead of 3 OR 26 like is available in FANUC macroB

OF course you can always do it this way.

M502  #1=1 #2=2 #3=3 , etc  that way allows you as many var inputs as the single block will hold, It just looks UGLY .   

Just a thought, (;-) TP




Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: VB syntax
« Reply #19 on: March 21, 2009, 10:25:48 AM »
if you want you can "compact" your VB code if you want as well, for fun.
you have this:

v = GetVar (550)
v = v/2
SetVar(551,v)

Can be written like this:  

v = GetVar(550)/2
SetVar(551,v)

or

SetVar(551,(GetVar(550)/2))

'Nice Job on the Circle cycle too by the way!!!

'scott

fun times