if/while ?

More
15 Feb 2011 15:51 #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 Feb 2011 15:56 #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 Feb 2011 16:06 #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 Feb 2011 16:24 #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 Feb 2011 16:36 - 15 Feb 2011 16:37 #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 Feb 2011 16:37 by andypugh.

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

More
15 Feb 2011 17:03 - 15 Feb 2011 17:18 #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 Feb 2011 17:18 by piasdom.

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

More
15 Feb 2011 17:19 #7223 by andypugh
Replied by andypugh on topic Re:if/while ?
piasdom wrote:

well, i ran this. had to change <> to () at end to be able to run.


Ah, well, you see, the stuff I put in <> characters was meant to indicate where the actual G-code to do the machining was meant to go, I rather assumed you already had that written.

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 ?

Not the way it is written. I think that is my mistake, you need #1 = -0.4

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

More
23 Feb 2011 19:59 #7415 by piasdom
Replied by piasdom on topic Re:if/while ?
why does the first "do" go to a depth of .065 instead of #1 = -.06
and the second goes to .04" as it should ? i've ran it three times and it goes to .065".
as far as i can see, they are only different by the depth. #1 & #4. Thanks


%
g17 g20 g40 g49 g54 g80 g90 g94 g92.1


#1 = -.06
#2 = 0
#3 = .005
#4 = -.04
#5 = 0
#6 = .005

g0 z.2

O100 DO
#2 = [#2 - #3]
G1 f6 Z#2
x-1
y-1
x0
y0
O100 WHILE [#2 GT #1]

g0 z.2
x-2

O101 DO
#5 = [#5 - #6]
G1 f6 Z#5
x-3
y-1
x-2
y0
O101 WHILE [#5 GT #4]

g0 z3.4
x0 y0

m2
%

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

More
23 Feb 2011 21:37 #7416 by BigJohnT
Replied by BigJohnT on topic Re:if/while ?
A DO-WHILE loop does the code then checks the while condition. A WHILE-ENDWHILE loop checks the while condition and if true does the code.

So a DO WHILE loop in sudocode

Do

Stuff
...

Check While condition if true return to top and run again



A WHILE ENDWHILE loop in sudocode

Check While condition if it is True run code if False skip code

Stuff
...

Endwhile

So your do while loop will always execute at least once. Your test condition is while #2 is greater than #1 so it has to be larger before the loop stops. In other words you must pass up your desired target before the loop exits.

You either have to change your relational operator to one that gives you the correct outcome or the loop.

Hidden in the Binary Operators are the Relational Operators.

www.linuxcnc.org/docview/html/gcode_over...sub:Binary-Operators

John

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

More
24 Feb 2011 10:32 #7425 by piasdom
Replied by piasdom on topic Re:if/while ?
i thought that was the case about it having to be bigger than #1.
but it doesn't go over on the second Do. it goes to .04, so i still don't understand this
do'y think :)

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

Time to create page: 0.086 seconds
Powered by Kunena Forum