Hello Guest it is April 23, 2024, 08:58:53 PM

Author Topic: Are there conditionals (if, while) in the G-code?  (Read 7684 times)

0 Members and 1 Guest are viewing this topic.

Are there conditionals (if, while) in the G-code?
« on: July 22, 2006, 01:55:02 AM »
I just wrote my first G-code program that was more than 5 lines, and I know about parameters and expressions, but are there conditionals?

Can I have a loop that calls a subroutine over and over until a parameter is incremented to a certain value?

Offline Graham Waterworth

*
  • *
  •  2,673 2,673
  • Yorkshire Dales, England
    • View Profile
Re: Are there conditionals (if, while) in the G-code?
« Reply #1 on: July 22, 2006, 03:55:40 AM »
There are no while loops as such, but you can do loops.

What are you trying to do?

Have a look at this thread :- http://machsupport.com/forum/index.php?topic=310.0

Graham.
Without engineers the world stops
Re: Are there conditionals (if, while) in the G-code?
« Reply #2 on: July 22, 2006, 11:10:54 AM »
I see. So I can say "M98 P1000 L5" and repeat a subroutine 5 times.

I want to pocket out something by having an end-mill go around it and then having Z go 0.100 down, and repeating 5 times.

I wrote the path around the pocket as a subroutine and I am currently callling that 5 times sequentially, but I thought it would be nicer to have a loop which exits after some counter reaches 5.
« Last Edit: July 22, 2006, 11:19:32 AM by rsilvers »

Offline Graham Waterworth

*
  • *
  •  2,673 2,673
  • Yorkshire Dales, England
    • View Profile
Re: Are there conditionals (if, while) in the G-code?
« Reply #3 on: July 22, 2006, 06:28:51 PM »
Hi,

The L is the counter, if you make the subroutine have incremental Z moves you can call it once with the L as the number of times

E.G.

(Main program)

O1000
G20 G40 Etc.
G43 H1 Etc.
(Standard start up above)
G00 G90 X0 Y0 Z1.     (move to start of pocket)
S2000 M3                  (start spindle)
Z.1                           (move just clear of work)
G01 Z0 F2.                (feed to top of work)
M98 P1001 L5           (CALL SUB 5 TIMES)
G00 Z1.                    (jump out of pocket to safe height    **** very important *****)
G28 X0 Y0 Z0            (go to zero return)
M30

(Sub program)

O1001
G91                    (INCREMENTAL)
G01 Z-.1 F1.        (feed down .1 in incremental mode)
G90                    (set ABSOLUTE)
X.. Y..                 (mill pocket)
X.. Y..
Etc.
G00 X0 Y0           (go back to start point    **** NOTE don't move Z **** )
M99                    (end sub)

Graham.
« Last Edit: July 22, 2006, 06:32:19 PM by Graham Waterworth »
Without engineers the world stops
Re: Are there conditionals (if, while) in the G-code?
« Reply #4 on: July 22, 2006, 11:05:24 PM »
This seems to work:

---------------------------------------------------------------------------------------------------

O1000

#1=-0.45 (Depth to go down in first phase)
#2=-1.250 (Depth to go down in second phase)
#3=5 (Number of steps for first phase)
#4=8 (Number of steps for second phase)
#5=0.180 (Y for first phase, considering 1/2 inch tool size)
#6=0.030 (Y for second phase, considering 1/2 inch tool size)


G90 (Absolute distance mode)
M98 P1001 L#3 (Call phase-1 #3 times)
G4 P5.0
M98 P1002 L#4 (Call phase-2 #4 times)
G1 Z0.0 F6.0 (End)
M2


O1001
G91
G1 Z[#1 / #3] F2.0 (Feed down)
G90
G1 X2.400 F6.0 (Go to the right)
G1 Y#5 F6.0 (Go away)
G1 X1.650 F6.0 (Mill away far side)
G1 Y0.0 F6.0 (Come to start)
G4 P5.0
M99

O1002
G91
G1 Z[[#2 - #1] / #4] F2.0 (Feed down)
G90
G1 X2.400 F6.0
G1 Y#6 F6.0
G1 X1.650 F6.0 (Mill other side)
G1 Y0.0 F6.0 (Back to start)
G4 P5.0
M99

%
« Last Edit: July 23, 2006, 03:03:48 AM by rsilvers »

Offline Graham Waterworth

*
  • *
  •  2,673 2,673
  • Yorkshire Dales, England
    • View Profile
Re: Are there conditionals (if, while) in the G-code?
« Reply #5 on: July 23, 2006, 04:12:00 AM »
It looks good to me, only thing missing is the rapid to the initial X, Y & Z start point in the main program.

G90 (Absolute distance mode)
G00 X... Y... Z... (start point)
G01 Z0 F2. (feed to top of pocket)
M98 P1001 L#3 (Call phase-1 #3 times)
G4 P5.0
M98 P1002 L#4 (Call phase-2 #4 times)
G1 Z0.0 F6.0 (End)
M2

Graham.
« Last Edit: July 23, 2006, 04:14:48 AM by Graham Waterworth »
Without engineers the world stops
Re: Are there conditionals (if, while) in the G-code?
« Reply #6 on: July 23, 2006, 04:19:30 AM »

I manually start it by touching off a specific spot of the part.

I ran it twice tonight on real parts, and it worked well.

Offline Graham Waterworth

*
  • *
  •  2,673 2,673
  • Yorkshire Dales, England
    • View Profile
Re: Are there conditionals (if, while) in the G-code?
« Reply #7 on: July 23, 2006, 04:23:31 AM »
You could do it with one sub program by changing the # values between the sub calls.

O1000

#1=-0.45 (Depth to go down in first phase)
#3=5 (Number of steps for first phase)
#5=0.180 (Y for first phase, considering 1/2 inch tool size)

G90 (Absolute distance mode)
G00 X... Y... Z.1
G01 Z0 F2.
M98 P1001 L#3 (Call phase-1 #3 times)
G4 P5.0
#1=-1.250 (Depth to go down in second phase)
#3=8 (Number of steps for second phase)
#5=0.030 (Y for second phase, considering 1/2 inch tool size)
M98 P1001 L#3 (Call phase-2 #3 times)
G1 Z0.0 F6.0 (End)
M2


O1001
G91
G1 Z[#1 / #3] F2.0 (Feed down)
G90
G1 X2.400 F6.0 (Go to the right)
G1 Y#5 F6.0 (Go away)
G1 X1.650 F6.0 (Mill away far side)
G1 Y0.0 F6.0 (Come to start)
G4 P5.0
M99

Graham.
Without engineers the world stops