User Variables Question

A place to discuss and ask questions about all things Machining for Mills, Lathes, Laser, and Routers

Moderator: cnckeith

Post Reply
Gerral
Posts: 33
Joined: Fri Nov 22, 2024 4:25 pm
Acorn CNC Controller: Yes
Plasma CNC Controller: No
AcornSix CNC Controller: No
Allin1DC CNC Controller: No
Hickory CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: B4107B77A373-0905248481
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

User Variables Question

Post by Gerral »

I am working on converting programming from a different system to CNC12, and I have a question about user variables. From what I understand, the general-purpose user variables are #100-#149 and #29000-#31999. Variables #100-#149 are cleared at the beginning of each job, while variables #29000-#31999 persist until CNC12 is shut down.

I am performing calculations for one job that runs the probe for a specific product. The next job relies on the variables generated from the first job, which means I need to use variables in the range of #29000 to #31999. However, whenever I try to perform calculations using these variables, the program seems to freeze.

For example

Code: Select all

G0 X0 Y0 Z0
#100 = [#100 + 10]
G0 Z[#100]
#100 = [#100 + 10]
G0 Z[#100]
Increments the variable and moves the Z axis appropriately. Each time the job runs #100 is started back at 0.

Code: Select all

G0 X0 Y0 Z0
#30100 = [#30100 + 10]
G0 Z[#30100]
#30100 = [#30100 + 10]
G0 Z[#30100]
Locks up CNC12 entirely.
I was expecting it to work like the previous code but not resetting variable #30100 between runs.
What am I missing?

Thank you in advance for your comments


Centroid_Jacob
Web Developer
Posts: 100
Joined: Wed Oct 19, 2022 4:49 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: Yes
Oak CNC controller: Yes
CNC Control System Serial Number: none
DC3IOB: No
CNC12: No
CNC11: Yes
CPU10 or CPU7: No

Re: User Variables Question

Post by Centroid_Jacob »

I can confirm this behavior with v5.22.
You can avoid the lock up by giving a starting value to #30100 before attempting to add 10 to it, but this is not ideal for repeat runs where you wouldn't want to reset the variable between jobs.

Code: Select all

G0 X0 Y0 Z0
#30100 = 0 ; initialize the variable before using to avoid lock up. 
#30100 = [#30100 + 10]
G0 Z[#30100]
#30100 = [#30100 + 10]
G0 Z[#30100]
Of interest is that lock up is avoided when the macro/job file checks if we're graphing or searching before the use of the variable, so it's likely related to one of those functions.

Code: Select all

IF #4201 || #4202 THEN GOTO 1000 ;Skip macro if graphing or searching
So this would work for the time being:

Code: Select all

IF #4201 || #4202 THEN GOTO 1000 ;Skip macro if graphing or searching
G0 X0 Y0 Z0
#30100 = [#30100 + 10]
G0 Z[#30100]
#30100 = [#30100 + 10]
G0 Z[#30100]
; rest of macro/job here
N1000 ; end of macro/job
When requesting support please read this post first.

A fresh report makes it easier to assist you. To make a report check this post


Gerral
Posts: 33
Joined: Fri Nov 22, 2024 4:25 pm
Acorn CNC Controller: Yes
Plasma CNC Controller: No
AcornSix CNC Controller: No
Allin1DC CNC Controller: No
Hickory CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: B4107B77A373-0905248481
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: User Variables Question

Post by Gerral »

Thanks!

Using the value in #30100 from the previous job run, attempting to save to this variable also causes a freeze.

Code: Select all

#100 = #30100
#100 = [#100 + 10]
G0 Z[#100]
#100 = [#100 + 10]
G0 Z[#100]
#30100 = #100
Is this a bug that I need to report? I use a similar technique to run the same job over and over on an inlay grooving machine to slowly sneak up on the width of the inlay strip as they vary in width from strip to strip by as much as 1mm and the inlay grove has to be spot on.


suntravel
Community Expert
Posts: 3522
Joined: Thu Sep 23, 2021 3:49 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: 6433DB0446C1-08115074
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No
Location: Germany

Re: User Variables Question

Post by suntravel »

Try to use

Code: Select all

IF #4201 || #4202 THEN GOTO 1000 ;Skip macro if graphing or searching
in each job first and after this work with the variables.

Uwe


Gerral
Posts: 33
Joined: Fri Nov 22, 2024 4:25 pm
Acorn CNC Controller: Yes
Plasma CNC Controller: No
AcornSix CNC Controller: No
Allin1DC CNC Controller: No
Hickory CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: B4107B77A373-0905248481
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: User Variables Question

Post by Gerral »

That worked!
I've never used conditionals in GCode before as the previous system didn't support them.
When you suggested that I initially thought you were thinking I was working with a macro.

Thanks!!


suntravel
Community Expert
Posts: 3522
Joined: Thu Sep 23, 2021 3:49 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: 6433DB0446C1-08115074
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No
Location: Germany

Re: User Variables Question

Post by suntravel »

Gerral wrote: Sat Dec 07, 2024 11:58 am That worked!
I've never used conditionals in GCode before as the previous system didn't support them.
When you suggested that I initially thought you were thinking I was working with a macro.

Thanks!!

Code: Select all

IF #4201 == 0 && #4202 == 0 THEN #100 = #30100
should also work to not set a variable if graphing or searching for a single line instead of skipping a block or a macro with N1000 as the last block

Uwe


Post Reply