if/while ?

More
15 years 8 months ago #7217 by piasdom
Replied by piasdom on topic Re:if/while ?
i understand the [ ].
it could be G0 x[3+5+9-10] and X would go to 7


BigJohnT wrote:

The [a + c + d] the equation inside of the square brackets is evaluated and the result is returned so,

G0 X[3 + 5]

would send the X axis to X8

John

Please Log in or Create an account to join the conversation.

More
15 years 8 months ago #7218 by piasdom
Replied by piasdom on topic Re:if/while ?
i understand #<Current-Diameter> and #<Final_Dia>, they can be whatever you set about.
i don't understand how the "while" knows which to move, xy or z.
and i'll got look at these binaries. thanks for that.


as in this example;
o100 while [#<Current-Diameter> lt #<Final_Dia>]

O101 if [#<Current-Diameter> + #<Depth_Cut> lt #<Final_Dia>]
#<Current-Diameter> = [#<Current-Diameter> + #<Depth_Cut>]
O101 else
#<Current-Diameter> = #<Final_Dia>
O101 endif

X#<Current-Diameter>
G1 Z#<Z_EndOfCut> F#<FeedRate>
G0 X[#<Current-Diameter>-0.010]
Z#<Z_StartOfCut>
o100 endwhile



BigJohnT wrote:

Here is the binary operators like LT

www.linuxcnc.org/docview/html/gcode_over...html#sub:Expressions

The basic syntax of a while loop is:

while test is true

do code between while and endwhile

endwhile

So when the while test evaluates to false jump to the endwhile line. and carry on without executing any code between while and endwhile.

John

Please Log in or Create an account to join the conversation.

More
15 years 8 months ago #7219 by BigJohnT
Replied by BigJohnT on topic Re:if/while ?
All the "while" knows is to execute what ever code you have between the while/endwhile or to skip the code between the while/endwhile.

John

Please Log in or Create an account to join the conversation.

More
15 years 8 months ago #7220 by piasdom
Replied by piasdom on topic Re:if/while ?
Thanks for ya'll time.

BigJohnT wrote:

All the "while" knows is to execute what ever code you have between the while/endwhile or to skip the code between the while/endwhile.

John

Please Log in or Create an account to join the conversation.

More
15 years 8 months ago - 15 years 8 months ago #7221 by andypugh
Replied by andypugh on topic Re:if/while ?
piasdom wrote:

thanks andypugh, but i can't figure out what goes in the [ ].
i understand #2 = [#2 - #3] equaling -.01, so it would move down .01 each pass(or run of code)?

Exactly.

but no idea what [#2 GT #1]
i'm guessing GT is GoTo. what does the While ? xy or z?

No, GT means "Is Greater Than"
So, that loop which I wrote out carries on looping between the DO and the WHILE as long as #3 (a variable) hasn't hit the limit depth stored in #1

The two O100 codes indicate that the DO and the WHILE are a pair. They could be any number, but it seems traditional to use O100, O101 and so on.
DO / WHILE always runs once, and then runs again if the conditional statement in the brackets after the WHILE is true. There is an alternative form, WHILE / ENDWHILE which checks first, and can run zero times.

Other bits of G-code between the DO and WHILE or the WHILE and ENDWHILE alter the variables and use them to set the Z depth, or anything else. All the loop does is repeat a block of code "while" a condition is true.
Last edit: 15 years 8 months ago by andypugh.

Please Log in or Create an account to join the conversation.

More
15 years 8 months ago - 15 years 8 months ago #7222 by piasdom
Replied by piasdom on topic Re:if/while ?
well, i ran this. had to change <> to () at end to be able to run.
it ran but only once at z-.1, which is right.
but shouldn't it have ran till Z got to -.4
cutting the square at each level of .1 ,.2, .3 and .4 ?

#1 = .4
#2 = 0
#3 = 0.1

O100 DO
#2 = [#2 - #3]
G1 f20 Z#2
x1
y1
x0
y0
O100 WHILE [#2 GT #1]
(finishing pass at Z = #1) this was <finishing pass at Z = #1>, but got an error.


figured out i needed to change .4 to -.4 ....... works THANKS
Last edit: 15 years 8 months ago by piasdom.

Please Log in or Create an account to join the conversation.

Time to create page: 0.168 seconds
Powered by Kunena Forum