Hello Guest it is April 19, 2024, 08:33:55 PM

Author Topic: Learning to use variables in my code  (Read 1551 times)

0 Members and 1 Guest are viewing this topic.

Learning to use variables in my code
« on: January 18, 2020, 09:44:53 PM »
Using Mach4 with ESS and I am trying to get familiar with Gcode before I start using CAM to create it. Just making a back and forth pass incrementing Y each time to surface the spoilboard for my wood router and I wanted to make it more flexible to work for surfacing anything. And now I am stuck. Where am I going wrong with the use variables?
BTW Can I use text for variables or must they be numbers? What are the rules for that?


The lines in parenthesis are what I used originally and it worked. Left there show show what my intention was.


Code: [Select]
#1001 = 46.5 (Width)
#1002 = 36 (Depth)
#1003 = 17 (Cycles of Loop)
#1004 = 1 (Tool Diameter)
#1005 = [#1004 - .1] (Step over)
#1006 = -0.050 (Depth of Cut)
G0 G90 G54 G17 G40 G49 G80
(G0 X3.0 Y1.2 Z1.0 ;home, inside previous cut)
G0 X0 Y0 Z.2 ;home, inside previous cut
(G1 Z-0.050 F10 ; letting me know its cutting)
G1 Z#1006 F10 ; letting me know its cutting
M03 S18000; start spindle
G04 P3000 ;Pause 3 seconds for VFD comes to speed
M0 ;confirm the start
( M98 P1000 L17 ;Call Sub O1000, loop enough times to reach back side )
M98 P1000 L#1003 ;Call Sub O1000, loop enough times to reach back side
M04 ;stop spindle
G0 G90 G54 G17 G40 G49 G80
G0 Z5.0
(G0 X1.5 Y1.95 )
G0 X0.0 Y0.0
G28 M30 ;exit routine
O1000 ;Beginning of loop
G91 ;incremental
(G01 Y0.95 F100.)
G01 Y#1005 F100.
G90 ;absolute
( X46.5 ;go to end)
X#1001 ;go to end
G91 ;incremental
(Y0.95 ;by this much)
Y#1005 ;by this much
G90 ;absolute
(G1 X3.0 ;back to beginning)
G1 X0 ;back to beginning
M99 ;End of loop
Re: Learning to use variables in my code
« Reply #1 on: January 19, 2020, 12:00:17 PM »
I believe codes 1000+ are taken.  Try your same code with #'s less than 1000

HTH

RT
Re: Learning to use variables in my code
« Reply #2 on: January 19, 2020, 02:21:14 PM »
You appear to be correct,variables are 100-199. I also found limited google support for "L" parameter technique (though it did function in MACH4) so I re-wrote it using a while loop which seems to be far more common and would then be easier to ask questions about.


The following code works in g-code simulator (Gwizard?) but now it seems Mach doesn't like math on the variables. Or at least the way that GWizard does.
Code: [Select]
#107 = 0 ; Starting (and Current) Y Position
#101 = 46.5 ; X Max  (Static Variable, Object width)
#102 = 34.0 ; Y Max (Static Variable, Object height)
#103 = 0.1 ;  Step overlap (Static Variable)
#104 = 1 ; Tool Diameter (Static Variable)
#105 = #104-#103 ; Y Increment  <<<======= FAILS HERE - UNKNOWN COMMAND
#106 = -0.010 (Depth of Cut)


G0 G90 G54 G17 G40 G49 G80 ;Safety Line
G0 X0 Y0 Z.2 ; Home
;M03 S18000; Start spindle
G1 Z0.2 F10 ; Get close to surface
G04 P5000 ; Pause 3 seconds for VFD comes to speed
M0 ; Confirm the Cycle Start


G01 Z#106 ; Z to Depth


WHILE [#107 LE #102] DO1 ; Start Loop, run until Y value reached
G01 Y#107 F10. ; move TO Y
G01 X#101 ; Go To X Max
#107=#107+#105 ; Increment Y variable by step over value
G01 Y#107 F10. ; move Y to next step
G01 X0 ; Move to X Min
#107=#107+#105 ;increment Y by step over value


END1 ; End Loop


G0 Z5.0 ; Raise Spindle
M04 ; stop spindle
G0 G90 G54 G17 G40 G49 G80
G0 X0.0 Y0.0 ; Go Home
M30 ; exit routine


This faults on the first #105 whether in brackets or not, this syntax is the only way I have seen it done so far. Whats wrong this time?? Is this a MACH specific thing??


I really would like to get over the gcode hurdle. the basics appear pretty easy to grasp, but the nuances between machine types must be what I am fighting now.

Feature not licensed ??
« Reply #3 on: January 19, 2020, 02:35:53 PM »
 Used parens instead of semicolon for comments and made it though the #105 math only to be stopped at  the WHILE statement which errored saying "Feature Not Licensed" ?

Re: Learning to use variables in my code
« Reply #4 on: January 19, 2020, 02:38:56 PM »
I believe while is only available to industrial licensed individuals.  Part of Fanuc B.
Re: Learning to use variables in my code
« Reply #5 on: January 19, 2020, 02:44:51 PM »
You are kidding me...