What's new
What's new

Resetting variable from value at top of program

rbmgf7

Aluminum
Joined
Oct 18, 2017
I'm pretty much self taught at programming and I've managed to get by so far but I'm a little stumped on this one.

I have a program I wrote where I use a counter on a couple variables. For the program to continue on, I need the value to be what I declared at the beginning. So far I just rewrite the variable's value after the operation. However, if I want to change that variables value, I have to change it in numerous spots in the program. The purpose of this is because I wrote the program to be selectable for a series of parts that are all relatively identical but have slight variances in dimensions. Then all the operator has to do is change #100. Is there an easier way to do this? This is still a rough draft but variables #105 and #106 is what I'm getting at. Thanks.

Fanuc 31 controller.

Code:
(#100=1)(310004)
(#100=2)(310005)
(#100=3)(310006)
(#100=4)(310007)
#100=1

IF[#100NE1]GOTO0200
N0100
#101=13.4(Y0 TOP)
#102=3.6 (Y0 BOTTOM)
#103=320. (B AXIS)
#104=.9 (WALL)
[B](1)#105=4.4 (HEIGHT)(5 PLACES)
(1)#106=2.8 (WIDTH)(5 PLACES)[/B]
#107=0.05 (DOC)
#108=1.5 (TOOL DIAM)
#109=0.25 (RADIUS)
GOTO1000

N0200
IF[#100NE2]GOTO0300
#101=15(Y0 TOP)
#102=2 (Y0 BOTTOM)
#103=320. (B AXIS)
#104=.9 (WALL)
(1)#105=4.4 (HEIGHT)(5 PLACES)
(1)#106=2.8 (WIDTH)(5 PLACES)
#107=0.1 (DOC)
#108=1.5 (TOOL DIAM)
#109=0.5 (RADIUS)
GOTO1000

N0300
IF[#100NE3]GOTO0400
#101=10(Y0 TOP)
#102=5 (Y0 BOTTOM)
#103=320. (B AXIS)
#104=.9 (WALL)
(1)#105=4.4 (HEIGHT)(5 PLACES)
(1)#106=2.8 (WIDTH)(5 PLACES)
#107=0.01 (DOC)
#108=1 (TOOL DIAM)
#109=0.25 (RADIUS)
GOTO1000

N0400
IF[#100NE4]GOTO1000
#101=13.4(Y0 TOP)
#102=3.6 (Y0 BOTTOM)
#103=320. (B AXIS)
#104=.9 (WALL)
(1)#105=4.4 (HEIGHT)(5 PLACES)
(1)#106=2.8 (WIDTH)(5 PLACES)
#107=0.05 (DOC)
#108=1.5 (TOOL DIAM)
#109=0.25 (RADIUS)
GOTO1000

T99M6
N1000
G91G28Z0 
G0G17G90G94G54.1P5X0Y[#101-[[#105/2]+[#108/2]]-.1]S1530M3B[#103]
G43Z12.1H99
G1Z7.8F10
M50
G1X0Y[#101-[[#105/2]+[#108/2]]]F10.
WHILE[#106GT#104]DO1
G91G17
G1X-[[#106/2]+[#108/2]]F70.1
G2X-#109Y#109I0J#109
G1Y[#105-#107+[#108/2]]
G2X#109Y#109I#109J0
G1X[#106+[[#108/2]*2]]
G2X#109Y-#109I0J-#109
G1Y-[#105-#107+[#108/2]]
G2X-#109Y-#109I-#109J0
G1X-[[#106/2]+[#108/2]]
G1Y[#107]
#105=#105-[#107*2]
#106=#106-[#107*2]
END1
[B](2)#105=4.4
(2)#106=2.8[/B]
G90G0Z10.
IF[#103EQ40]GOTO1100
X-[[#106/2]+[#108/2]+.1]Y[[#101]-[#105/2]-[#108/2]]
Z5.
G1
X-[[#106/2]+[#108/2]]Y[[#101]-[#105/2]-[#108/2]+[#104/2]]F10.
WHILE[#106GT0]DO1
G91
G2I#109J0F70.1
G1X#107
#106=#106-#107
END1
Y-#109
WHILE[#105GT0]DO1
G91
G2I#109J0F70.1
G1Y#107
#105=#105-#107
END1
[B](3)#105=4.4
(3)#106=2.8[/B]
N1100
IF[#103NE40]GOTO1999
X[[#106/2]+[#108/2]+.1]Y[[#101]-[#105/2]-[#108/2]]
Z5.
G1
X[[#106/2]+[#108/2]]Y[[#101]-[#105/2]-[#108/2]+[#104/2]]F10.
WHILE[#106GT0]DO1
G91
G2I#109J0F70.1
G1X-#107
#106=#106-#107
END1
Y-#109
WHILE[#105GT0]DO1
G91
G2I#109J0F70.1
G1Y#107
#105=#105-#107
END1
[B](4)#105=4.4
(4)#106=2.8[/B]
N1999
G90
G0G80Z17.
G91G28Z0

N2000
G91G28Z0 
G0G17G90G94G54.1P5X0Y[#102+[[#105/2]+[#108/2]]-.1]S1530M3B[#103]
G43Z12.1H99
G1Z7.8F10
M50
G1X0Y[#102+[[#105/2]+[#108/2]]]F10.
WHILE[#106GT#104]DO1
G91G17
G1X[[#106/2]+[#108/2]]F70.1
G2X#109Y-#109I0J-#109
G1Y-[#105-#107+[#108/2]]
G2X-#109Y-#109I-#109J0
G1X-[#106+[#108/2]*2]
G2X-#109Y#109I0J#109
G1Y[#105-#107+[#108/2]]
G2X#109Y#109I#109J0
G1X[[#106/2]+[#108/2]]
G1Y-[#107]
#105=#105-[#107*2]
#106=#106-[#107*2]
END1
[B](5)#105=4.4
(5)#106=2.8[/B]
G90G0Z10.
IF[#103EQ40]GOTO2100
X-[[#106/2]+[#108/2]+.1]Y[[#102]+[#105/2]+[#108/2]]
Z5.
G1
X-[[#106/2]+[#108/2]]Y[[#102]+[#105/2]+[#108/2]-[#104/2]]F10.
WHILE[#106GT0]DO1
G91
G2I#109J0F70.1
G1X#107
#106=#106-#107
END1
Y#109
WHILE[#105GT0]DO1
G91
G2I#109J0F70.1
G1Y-#107
#105=#105-#107
END1
[B](6)#105=4.4
(6)#106=2.8[/B]

N2100
IF[#103NE40]GOTO2999
X[[#106/2]+[#108/2]+.1]Y[[#102]+[#105/2]+[#108/2]]
Z5.
G1
X[[#106/2]+[#108/2]]Y[[#102]+[#105/2]+[#108/2]-[#104/2]]F10.
WHILE[#106GT0]DO1
G91
G2I#109J0F70.1
G1X-#107
#106=#106-#107
END1
Y#109
WHILE[#105GT0]DO1
G91
G2I#109J0F70.1
G1Y-#107
#105=#105-#107
END1
[B](7)#105=4.4
(7)#106=2.8[/B]
N2999
G90
G0G80Z17.
G91G28Z0
IF[#103EQ40]GOTO9999
#103=40.
GOTO1000
N9999
G0G80Z17.
G91G28Z0

M1 
G0G91G28Y0B0M5 
M20
M60
M30
 
I'd add to the top right after the assignment of #100 something like...

#1=4.4
#2=2.8

Then replace the instances of #105=4.4 with #105=#1 and #106=2.8 with #106=#2

Then you no longer have to edit all instances of #105 and #106. Just change them at the top.
 
If I understand your question then the issue is that you overwrite variables #105 and #106 in the section starting at N1000 and you want to keep the values to do further calculations. You can solve this issue by creating two more variables at the top of your program lets say #110 and #111 and then simply assigning the values of #105 and #106 to #110 and #111 so for example in your N0100 section you could write

IF[#100NE1]GOTO0200
N0100
#101=13.4(Y0 TOP)
#102=3.6 (Y0 BOTTOM)
#103=320. (B AXIS)
#104=.9 (WALL)
(1)#105=4.4 (HEIGHT)(5 PLACES)
(1)#106=2.8 (WIDTH)(5 PLACES)
#110 = #105
#111 = #106

#107=0.05 (DOC)
#108=1.5 (TOOL DIAM)
#109=0.25 (RADIUS)
GOTO1000

then any time you wish to recover the original values in your N1000 section you can write
#105 = #110
#106 = #111
 
Ok, got it. Works now. Thanks.

Now I can go back and rewrite my older programs, lol.
 








 
Back
Top