Welcome, Guest. Please login or register.
Did you miss your activation email?
November 23, 2014, 08:13:44 AM

Login with username, password and session length
Search:     Advanced search
* Home Help Search Calendar Links Login Register
+  Machsupport Forum
|-+  Mach Discussion
| |-+  VB and the development of wizards
| | |-+  VB and variables in G code
Pages: « 1 2 3 »   Go Down
Print
Author Topic: VB and variables in G code  (Read 5811 times)
0 Members and 1 Guest are viewing this topic.
vmax549
Guest
« Reply #10 on: March 16, 2009, 05:40:11 PM »

OOPS that is not the complete code, Sorry. I'll post the complete code shortly.

IF you are going the Gcode direct route it gets more complicated as you have to do the sub program routine useing macros to do the conditional and redirection via the M98 Pxx   routine. I think I have an example of that as well.

(;-) TP
« Last Edit: March 16, 2009, 05:41:54 PM by vmax549 » Logged
MachineMaster
Active Member

Offline Offline

Posts: 151


View Profile
« Reply #11 on: March 16, 2009, 08:12:17 PM »

This is what I was thinking. I have these variables in the beginning of the program

N10 G90G40
#1000 = 2.       (thousands starting digit)
#100 = 2.         (hundreds starting digit)
#10 = 5.           (tens starting digit)
#1 = 9.            (ones starting digit)
#1210 = 0.       (month tens digit)
#1201 = 1.       (month ones digit)
#2010 = 0.       (year tens digit)
#2001 = 9.       (year ones digit)
T25 M06
 
This engraves  the following

01092259

as the serial number. I am only incrementing the last four numbers. My G code as I have it so far will do that one number using the following

G90G00X0.2500Y-0.0250
M98 P#1210

G00X0.185Y-0.025
M98 P#1201

G00X0.125Y-0.025
M98 P#2010

G00X0.06Y-0.025
M98 P#2001

G90G00X0.00Y-0.025
M98 P#1000

G00X-0.065Y-0.025
M98 P#100

G00X-0.13Y-0.025
M98 P#10

G00X-0.20Y-0.025
M98 P#1

M995                    (This is the macro that I need to write to do the increment)

 O0
G00 Z0.01
G91
G00 X-0.0424 Y-0.0229
F12.0
G90
G01 Z-0.0030 F8.0
G91 G02 X0.0358 Y0. I0.0179 J0. F12.0
G01 Y-0.0293
G02 X-0.0358 Y0. I-0.0179 J0.
G01 Y0.0293
G90 G00 Z0.01
M99
 
O1
G90 G00 Z0.01
G91 G00 X-0.0076 Y-0.0574
G90 G01 Z-0.0030 F8.0
G91 G01 X-0.0126 Y-0.0126 F12.0
G01 Y0.065
G90 G00 Z0.01
G91 G00 X0.0152
G01 G90 Z-0.0030 F8.0
G01 G91 X-0.0309 F12.0
G90 G00 Z0.01
M99

I only included code for two numbers. What I want to do is use the M950 to read #1, #10, #100 and #1000 and increment as needed
and return them to the program. Is that possible?
« Last Edit: March 16, 2009, 08:16:10 PM by MachineMaster » Logged
MachineMaster
Active Member

Offline Offline

Posts: 151


View Profile
« Reply #12 on: March 17, 2009, 07:49:32 PM »

OK, I have changed some of the G code near the end of the file as follows

G00X-0.065Y-0.025
M98 P#100

G00X-0.13Y-0.025
M98 P#10

G00X-0.20Y-0.025
M98 P#1

M950                    (This is the macro that I wrote. See below)
G92.1
M05
G00 G90 X0 Y0 Z0
M01
M98 P200

M02


 O0
G00 Z0.01
G91
G00 X-0.0424 Y-0.0229
F12.0
G90

Macro
a = GetVar (1)
Print a
b = GetVar(10)
Print b
c = GetVar(100)
Print c
d = GetVar(1000)
Print d

a = a+1
If a = 10 Then a = 0
If a = 0 Then b = b + 1
SetVar 1, a
Print a
If b = 10 Then b = 0
If b = 0 Then c = c+1
SetVar 10, b
Print b
If c = 10 Then c = 0
If c = 0 Then d = d+1
SetVar 100, c
Print c
If d = 10 Then d = 0
SetVar 1000, d
Print d

I put the print statements in to see what was happening and it runs fine when called but in the VB assist window it prints the values.
Logged
vmax549
Guest
« Reply #13 on: March 17, 2009, 11:31:37 PM »

Here is another example ,

A=0
B=0
C=0
D=0

A= A+1
If A>9 Then B=B+1
If A>9 Then A=0

If B>9 Then C=C+1
If B>9 Then B=0 

If C>9 Then d=D+1
If C>9 Then C=0   

Print " " &D &C &B &A
End

NOTE:  Mach has parameters that are persistant so they hold there value when Mach is shut down. They are Param 500-600. You can store you serial number there so it is always available. You can veiw the vars with the Mach var monitor to check the values.

(;-) TP
Logged
MachineMaster
Active Member

Offline Offline

Posts: 151


View Profile
« Reply #14 on: March 18, 2009, 12:54:10 AM »

Thank you. The tip about the persistent variables is great. Now I can do away with the variables at the beginning of the G code and set the new variables to what I want with another macro that I wrote just for that. I just bring it up in the VB assistant, enter what I want and run the macro right in the assistant.
Now I can end the main program with an M30 and not have my variables over written.
Again, Thank you
Logged
vmax549
Guest
« Reply #15 on: March 18, 2009, 02:49:58 PM »

Glad I could help out, (;-)  When you are all done and you want to share you can post the finished code here for all to see how you did it.  It can be inspiring when you see an example of something.

(;-) TP
Logged
MachineMaster
Active Member

Offline Offline

Posts: 151


View Profile
« Reply #16 on: March 19, 2009, 10:12:29 PM »

Still not getting it. I got my first macro working so I started on another one.

'M79.m1s
V = GetVar (550)
V1 = (V/2.0)
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
   
Var 550 is set at .5 and if I put a Print statement in like
Print V1 the out put is the expected .25 but when I try to run M79 in my G code I get

No digits found where real number should be

The G code calling the M79 is

G49G80G90G00
X1.Y-1.F3.
M79
X0Y0
M30

If I modify the Macro to

'M78.m1s
V = GetVar (550)
V1 = (V/2.0)
Code " G90 G92 X0. Y0. "
Code "G01 X.25 Y.25"
Code "G03 X.0 Y.5 I-.25 J.0 G90"
Code "G03 X.0 Y.5 I.0 J-.5 G90"
Code "G03 X-.25 Y.25 I.0 J-.25 G90"
Code "G01 G90 X.0 Y.0"
Code "G92.1"
End
   
with real numbers it works the way I want it to. What am I doing wrong when I am trying to use variables in the G code in the macro?
« Last Edit: March 19, 2009, 11:15:37 PM by MachineMaster » Logged
MachineMaster
Active Member

Offline Offline

Posts: 151


View Profile
« Reply #17 on: March 20, 2009, 03:03:49 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 &"
Logged
MachineMaster
Active Member

Offline Offline

Posts: 151


View Profile
« Reply #18 on: March 22, 2009, 09:40:38 PM »

Here is the final version of my M79 hole boring macro.


'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

The macro feeds from the center, does a 90deg arc to a point tangent to the circle to be cut, runs a circle, does a 90deg arc toward the center and then feeds back to the center.
Logged
vmax549
Guest
« Reply #19 on: March 24, 2009, 10:09:06 AM »

WHat you have there is , it will go to X1Y1 then bore a hole striaght down to -.5 then try to cut the circle (;-) You might want to add in 2 more params.
Logged
Pages: « 1 2 3 »   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!