- Posts: 3981
- Thank you received: 994
if/while ?
- BigJohnT
- Offline
- Administrator
-
Less
More
15 years 8 months ago #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
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
- Offline
- Banned
-
Less
More
- Posts: 145
- Thank you received: 9
15 years 8 months ago #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
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.
- piasdom
- Offline
- Banned
-
Less
More
- Posts: 145
- Thank you received: 9
15 years 2 months ago #12577
by piasdom
Replied by piasdom on topic Re:if/while ?
can i get z to move up(from present depth) .1" and move to another position and start
another cut ? like z at -.4.... move z up .1"(-.3").....move to new position.... z-.5. or
do i need a script or mcode ?
o100 if [#<fin_depth> lt #<depth_of_cut>]
z[.1/1]
o100 else
z#<_safeheight>
o100 endif
g0 x.1 y-.1
Thanks
kenneth
another cut ? like z at -.4.... move z up .1"(-.3").....move to new position.... z-.5. or
do i need a script or mcode ?
o100 if [#<fin_depth> lt #<depth_of_cut>]
z[.1/1]
o100 else
z#<_safeheight>
o100 endif
g0 x.1 y-.1
Thanks
kenneth
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
-
Less
More
- Posts: 19899
- Thank you received: 4655
15 years 2 months ago #12580
by andypugh
Replied by andypugh on topic Re:if/while ?
piasdom wrote:
Yes.can i get z to move up(from present depth) .1" and move to another position and start
another cut ? like z at -.4.... move z up .1"(-.3").....move to new position.... z-.5.
You probably need to learn to program in a real programming language, and not G-code. But, this is how I do what I think you want to do.
Code:o100 if [#<fin_depth> lt #<depth_of_cut>] z[.1/1] o100 else z#<_safeheight> o100 endif g0 x.1 y-.1
Code:
#<safeheight> = 2
#<startdepth> = 1
#<fin_depth> = 0.5
#<cut> = 0.1
#1 = #<startdepth> Note the use of #1 as a "working" variable to hold current_Z
O100 WHILE [#1 GT #<fin_depth>]
G0 Z #1
#1 = [#1 - #<cut>]
O101 IF [#1 < #<fin_depth>] ; allow for the last cut being less than <cut> above <fin>
#1 = #<fin_depth>
O101 ENDIF
G1 Z#1
....
Various G-code moves go here
....
O101 ENDWHILE
Please Log in or Create an account to join the conversation.
- piasdom
- Offline
- Banned
-
Less
More
- Posts: 145
- Thank you received: 9
15 years 2 months ago #12586
by piasdom
Replied by piasdom on topic Re:if/while ?
won't this make the end mill go down with each run ? i want the end mill to
come up from current position(-.4 to -.3") - move to new position(x.1 y.1) - go down .1" from
last current position(-.5).
come up from current position(-.4 to -.3") - move to new position(x.1 y.1) - go down .1" from
last current position(-.5).
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
-
Less
More
- Posts: 19899
- Thank you received: 4655
15 years 2 months ago #12589
by andypugh
Replied by andypugh on topic Re:if/while ?
piasdom wrote:
Why do you need an "if" then?
I really don't get what you are trying to achieve, but you probably need to use a variable for Z (like I did with #1), and keep modifying that before you use it.
#1 = 0.4
G1 Z#1
...some moves...
G0 z -0.3
G0 X0.1 Y0.1
#1 = [#1 - 0.1]
G0 Z#1
...
I still don't understand what you are wanting to do, though.
won't this make the end mill go down with each run ? i want the end mill to
come up from current position(-.4 to -.3") - move to new position(x.1 y.1) - go down .1" from
last current position(-.5).
Why do you need an "if" then?
I really don't get what you are trying to achieve, but you probably need to use a variable for Z (like I did with #1), and keep modifying that before you use it.
#1 = 0.4
G1 Z#1
...some moves...
G0 z -0.3
G0 X0.1 Y0.1
#1 = [#1 - 0.1]
G0 Z#1
...
I still don't understand what you are wanting to do, though.
Please Log in or Create an account to join the conversation.
Time to create page: 0.296 seconds