if/while ?

More
15 Feb 2011 12:53 #7203 by piasdom
if/while ? was created by piasdom
can i use if or while(or something) to set the depth ?
i want to cut at a certain depth(ie. .1") at a time till a finish depth(say .788).
been working on Owords, very fun. i usually cut pockets in aluminum.
thanks for any help !

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

More
15 Feb 2011 14:39 #7205 by BigJohnT
Replied by BigJohnT on topic Re:if/while ?
You can use do while but there is no if while

www.linuxcnc.org/docview/html/gcode_main.html#r3_2

John

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

More
15 Feb 2011 14:40 #7207 by andypugh
Replied by andypugh on topic Re:if/while ?
Yes, that is pretty much what the functions are for

#1 = .778
#2 = 0
#3 = 0.01

O100 DO
#2 = [#2 - #3]
G1 Z#2
<G-Code goes here>
O100 WHILE [#2 GT #1]
<finishing pass at Z = #1>

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

More
15 Feb 2011 15:07 - 15 Feb 2011 15:09 #7209 by BigJohnT
Replied by BigJohnT on topic Re:if/while ?
There are quite a few examples in the subroutines section of the do while loop.

Here is one from the ID subroutine.

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


John
Last edit: 15 Feb 2011 15:09 by BigJohnT.

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

More
15 Feb 2011 15:17 #7210 by piasdom
Replied by piasdom on topic Re:if/while ?
i've read this but couldn't understand what i was reading.(not a program)

BigJohnT wrote:

You can use do while but there is no if while

www.linuxcnc.org/docview/html/gcode_main.html#r3_2

John

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

More
15 Feb 2011 15:26 #7211 by piasdom
Replied by piasdom on topic Re:if/while ?
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)?
but no idea what [#2 GT #1].
i'm guessing GT is GoTo. what does the While ? xy or z?
<G-Code goes here> where is the "While" telling Z to do anything ? :)
that D### z. thanks for your help !


andypugh wrote:

Yes, that is pretty much what the functions are for

#1 = .778
#2 = 0
#3 = 0.01

O100 DO
#2 = [#2 - #3]
G1 Z#2
<G-Code goes here>
O100 WHILE [#2 GT #1]
<finishing pass at Z = #1>

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

More
15 Feb 2011 15:28 #7212 by BigJohnT
Replied by BigJohnT on topic Re:if/while ?
It draws a saw tooth shape.

John

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

More
15 Feb 2011 15:32 #7213 by piasdom
Replied by piasdom on topic Re:if/while ?
Thanks for a better example BigJohnT !
but now you threw in "if" and "lt" (guessing "less than")
i understand that "if "this" is "less than" "that" do something.
but i can't see where it(while) knows to move xy or z.
Thanks again !

BigJohnT wrote:

There are quite a few examples in the subroutines section of the do while loop.

Here is one from the ID subroutine.

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


John

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

More
15 Feb 2011 15:37 #7214 by BigJohnT
Replied by BigJohnT on topic Re:if/while ?
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:47 #7215 by BigJohnT
Replied by BigJohnT on topic Re:if/while ?
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.

Time to create page: 0.079 seconds
Powered by Kunena Forum