if/while ?
- piasdom
- Topic Author
- Offline
- Platinum Member
- Posts: 472
- Thank you received: 10
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.
- piasdom
- Topic Author
- Offline
- Platinum Member
- Posts: 472
- Thank you received: 10
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.
- BigJohnT
- Offline
- Administrator
- Posts: 7330
- Thank you received: 1176
John
Please Log in or Create an account to join the conversation.
- piasdom
- Topic Author
- Offline
- Platinum Member
- Posts: 472
- Thank you received: 10
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.
- andypugh
- Offline
- Moderator
- Posts: 23537
- Thank you received: 4852
Exactly.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)?
No, GT means "Is Greater Than"but no idea what [#2 GT #1]
i'm guessing GT is GoTo. what does the While ? xy or z?
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.
Please Log in or Create an account to join the conversation.
- piasdom
- Topic Author
- Offline
- Platinum Member
- Posts: 472
- Thank you received: 10
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
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
- Posts: 23537
- Thank you received: 4852
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.
Not the way it is written. I think that is my mistake, you need #1 = -0.4it 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 ?
Please Log in or Create an account to join the conversation.
- piasdom
- Topic Author
- Offline
- Platinum Member
- Posts: 472
- Thank you received: 10
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.
- BigJohnT
- Offline
- Administrator
- Posts: 7330
- Thank you received: 1176
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.
- piasdom
- Topic Author
- Offline
- Platinum Member
- Posts: 472
- Thank you received: 10
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.