586,114 active members*
3,218 visitors online*
Register for free
Login
Results 1 to 14 of 14
  1. #1
    Join Date
    Feb 2006
    Posts
    1792

    WHILE loop inside G71

    This is a brain twister (at least mine):
    I was trying to write a macro for machining a parabolic reflector, out of a solid cylindrical workpiece.
    The first step was to generate the parabolic profile using mathematical formulae, in a loop. I did it correctly, because when I execute this part of the program, it correctly traces a parabolic profile, exactly the way the points were generated. When I place the WHILE loop (which also has a G01 move to the calculated coordinates, corresponding to each execution of the loop) between block numbers N1 and N2, and command G70 P1 Q2, then also the curve is traced correctly. So far, so good!

    Now the problem:

    It is necessary to initially use G71 for stock removal. When I insert the same WHILE loop inside G71's P- and Q-blocks, it alarms out with "124 MISSING END STATEMENT" message. In other words, it detects an illegal WHILE loop. If anyone of you has ever used a loop with G71, please let me know the correct way.

    A bit of brainstorming:
    The G71 profile definition blocks are read and executed from bottom to top. So, do we have to write the WHILE loop in a reverse order?

  2. #2
    Join Date
    Mar 2003
    Posts
    2932
    The alarm description says:

    DO - END does not correspond 1 : 1. Modify the program.

    Does the END come after the Q block?

    Why not post that section of the program so we can look it over?

  3. #3
    Join Date
    Feb 2006
    Posts
    1792
    I will do some more experimentation today, and post the result.
    As I said, G70 P1 Q2 runs correctly. So, WHILE loop must be OK.
    The same blocks are placed in the G71 profile definition, between N1 and N2. It alarms out. The reason, as far as I can guess, is that G71 reads N1 to N2 blocks in the reverse sequence. So, It first sees END_ and then WHILE_DO_. Naturally, it would be illegal.

    Have you ever used any kind of loop with G71?

  4. #4
    Join Date
    Feb 2006
    Posts
    1792
    I did some experimentation today and came to the following conclusion:
    You can use WHILE_DO_END loop between P-and Q-blocks of G71, but the loop cannot have any movement G-code inside it. The WHILE loop is written in the usual manner, not upside down, as I was previously guessing.
    The program which I was trying to execute is given below. It alarms out.

    ...
    G00 X0 Z2;
    G65 P8018 M80 B10 D20 Q0.1 R0.5 F60;
    ...

    O8018 (PARABOLIC TURNING);
    G00 X#2 Z2;
    #104 = #4109;
    G71 U#18 R0.1;
    G71 P1 Q2 U–0.1 W0.05 F#9;
    N1 G00 X#13;
    G01 Z0;
    #100 = ABS [#17];
    #101 = – #100;
    WHILE [ABS [#101] LE ABS [#7]] DO 1;
    #102 = [[#13 * #13 * ABS [#7]] / [#13 * #13 – #2 * #2]];
    #102 = #101 + #102;
    #102 = [[#13 * #13 – #2 * #2] / ABS [#7]] * #102;
    #102 = SQRT [#102];
    G01 X#102 Z#101;
    #101 = #101 – #100;
    N2 END 1;
    (I also tried putting END1; and N2; in two separate blocks. It does not help)
    #103 = #4119;
    G70 P1 Q2 F [#9 / 2] S [#103 * 2];
    S#103 F#104;
    M99;

    When I skip G71 blocks and jump directly to G70 block, by a GOTO statement, the toolpath is as expected (parabolic), without any error.

    I finally gave up. I believe it is just not possible to use a loop with G01, for defining G71/G72 profiles. I am not sure about G73. I will have to check.

    So, I wrote a macro using G94 (G90 also can be used) for parabolic roughing. It works without any problem.

  5. #5
    Join Date
    Jul 2005
    Posts
    12177
    By mistake I tried using a subroutine with a G71 loop and it did not work.

    I think it is not surprising that it will not work because the G71 reads through the motion commands before starting its routine so it can calculate the roughing steps. This means that the coordinate values cannot change while it is doing that operation. The G70 command simply reads the coordinates and executes them in a normal manner.
    An open mind is a virtue...so long as all the common sense has not leaked out.

  6. #6
    Join Date
    Mar 2003
    Posts
    2932
    Isn't N2 supposed to be the last block of the shape definition? How about this:

    G01 X#102 Z#101;
    #101 = #101 – #100;
    END 1;
    N2 X#2

  7. #7
    Join Date
    Feb 2006
    Posts
    1792
    Quote Originally Posted by Geof View Post
    By mistake I tried using a subroutine with a G71 loop and it did not work.
    I think it is not surprising that it will not work because the G71 reads through the motion commands before starting its routine so it can calculate the roughing steps. This means that the coordinate values cannot change while it is doing that operation. The G70 command simply reads the coordinates and executes them in a normal manner.
    The manual does say that subprograms cannot be called from within P-, Q-blocks (I guess it applies to G65/G66 also). But it is silent about loops. Anyway, G90/G94 can be used to simulate the G71/G72 cycles, except that retraction at the end of a cutting pass would not be at 45 degree. But, this is hardly important.

    G73 may not have this limitation, because it does not have to calculate the toolpath. It simply shifts the defined profile in subsequent passes. I will verify and post the result.

  8. #8
    Join Date
    Sep 2004
    Posts
    209
    I understand that you want to use a macro so that the profile is exactly parabolic. But roughing does not have to be exact; can you use a simple approximation with G71?

  9. #9
    Join Date
    Jul 2005
    Posts
    12177
    I did some thinking, always a dangerous activity.

    Have you considered a different approach?

    An inefficient approach would be to perform the parabolic tool path many times and step the starting point forward using an incremental G52 Z command. This is inefficient because initially the machine will be cutting a lot of air.

    One way to improve the efficiency would be to write another macro to calculate the parabola OD which would then enter the macro for the parabola as the end point. This would reduce the time spent cutting air.
    An open mind is a virtue...so long as all the common sense has not leaked out.

  10. #10
    Join Date
    Feb 2006
    Posts
    1792
    Quote Originally Posted by dcoupar View Post
    Isn't N2 supposed to be the last block of the shape definition? How about this:

    G01 X#102 Z#101;
    #101 = #101 – #100;
    END 1;
    N2 X#2
    I have tried nearly everything, including some absurd ideas also (such as writing WHILE loop upside down). Nothing works.

  11. #11
    Join Date
    Feb 2006
    Posts
    1792
    Quote Originally Posted by ckirchen View Post
    I understand that you want to use a macro so that the profile is exactly parabolic. But roughing does not have to be exact; can you use a simple approximation with G71?
    You are right.
    Initially, the parabola can be approximated by a few straight lines, and G71/G72 be used to machine it. But the end points of the lines will have to be calculated, and somehow the macro has to be made of general type, so that a parabola with a different dimensions also could be machined without changing the macro.

  12. #12
    Join Date
    Feb 2006
    Posts
    1792
    Quote Originally Posted by Geof View Post
    I did some thinking, always a dangerous activity.

    Have you considered a different approach?

    An inefficient approach would be to perform the parabolic tool path many times and step the starting point forward using an incremental G52 Z command. This is inefficient because initially the machine will be cutting a lot of air.
    Inefficient, but it will work. In fact there is no need to use G52. You can use G73, with U = 0, and W = depth of parabola (#7), in the first block. Specify R to have the desired axial shift in the profile in subsequent cutting passes. I have tested this. It works.

    In fact, my experiment with G71/G72/G73 is now complete, with the following observations:
    You cannot use a loop with G01 for defining the profiles for G71 or G72.
    But this is permissible for G73.


    However, the most efficient method for this kind of machining would be to use G90 or G94 (as appropriate) in a loop, to simulate the roughing passes of G71/G72. This would be followed by moving the tool along the defined profile, to remove the steps. I am assuming that there is an initial hole in the workpiece, which would avoid tool interference with the workpiece. The program is ready and it works. I will post it in a day or two. Of course, it does not have the finishing allowances feature of G71/ G72. The drawing of the parabola is attached here.
    Attached Files Attached Files

  13. #13
    Join Date
    Feb 2006
    Posts
    1792
    As promised, I am giving the details of the macro.
    The equation of the parabola can be shown to be

    X*X = (M*M - B*B)/D * [Z + {(M*M*D)/(M*M - B*B)}]

    One can verify that Z=0 gives X=M, and Z=D gives X=B (refer to the figure given in my previous post)

    Here is the algorithm:
    Roughing operation
    1. Place the tool at Z = 0, with 1 mm clearance from the hole, i.e., at X = B – 2.
    2. Assign Z = – <specified roughing depth of cut>.
    3. If |Z| is greater than D, go to step 9.
    4. Calculate X, using the given formula.
    5. Command G94, with the calculated coordinates and the specified feedrate as its arguments.
    6. Shift the tool axially, to the Z-level of the machined surface, which would be the start point of the next G94 cycle.
    7. Change Z-coordinate (Z = Z – <specified roughing depth of cut>).
    8. Go to step 3.
    Step removal operation
    9. Place the tool at the inner edge of the parabola, i.e., at (B, –D).
    10. Assign Z = – D.
    11. If Z is greater than 0, go to step 16.
    12. Calculate X, using the given formula.
    13. Move to the calculated coordinates by G01.
    14. Change Z-coordinate (Z = Z + <specified step distance in Z>).
    15. Go to step 11.
    16. Return to the calling program.
    Note that if the depth of the parabola is not an exact multiple of the specified step distance in Z, the tool will not exactly reach the outer edge of the parabola. This would leave a small kink at the edge. This can be removed by moving the tool by some distance along the tangential direction at Z = 0. It can be shown that the increments in X and Z, at Z = 0, are related by the following formula:

    <change in X> = (M*M - B*B)/(2*M*D) * <change in Z>

    Thus, an additional tangential move, using the given formula, is desirable before returning to the calling program.

    The parameters of the parabola and the selected letter addresses are:

    Maximum Diameter, M (#13)
    Bore diameter, B (#2)
    Depth of parabola, D (#7)
    Step distance in Z, Q (#17)
    Roughing depth of cut, R (#18)
    Feedrate, F (#9)

    The program is
    ...
    G00 X0 Z2;
    G65 P8018 M80 B10 D20 Q0.1 R0.5 F60;
    ...
    O8018 (PARABOLIC TURNING WITH G94);
    #105 = #5041; (Stores the initial X-position of the tool)
    #106 = #5042; (Stores the initial Z-position of the tool)
    G00 X [#2 – 2] Z0; (Tool placed at the start point of the first G94 cycle, leaving a clearance of 1 mm in the radial direction. Step 1 complete)
    #100 = ABS [#17]; (ABS function would accept both positive and negative values for step distance in Z)
    #101 = – #18; (The first step change in Z. Step 2 complete)
    WHILE [ABS [#101] LE ABS [#7]] DO 1; (Exit from the loop if the entire depth is roughed out. Step 3 complete)
    #102 = [[#13 * #13 * ABS [#7]] / [#13 * #13 – #2 * #2]]; (Intermediate calculation)
    #102 = #101 + #102; (Intermediate calculation)
    #102 = [[#13 * #13 – #2 * #2] / ABS [#7]] * #102; (Intermediate calculation)
    #102 = SQRT [#102]; (X calculated. Step 4 complete)
    G94 X#102 Z#101 F#9; (Roughing with G94. Step 5 complete)
    G00 Z#101; (Tool positioning for the next G94 cycle. Step 6 complete)
    #101 = #101 – #18; (Z decremented by the specified roughing depth of cut. Step 7 complete)
    END 1; (End of loop. Step 8 complete)
    #103 = #4119; (Current rpm stored)
    G01 X#2 Z [–ABS [#7]] F [#9 / 2] S [#103 * 2]; (Tool placed at the inner edge of the parabola. Step 9 complete)
    #101 = –ABS [#7]; (Z-coordinate of the inner edge of the parabola stored. Step 10 complete)
    WHILE [#101 LE 0] DO 1; (Exit from the loop if the outer edge of the parabola is reached. Step 11 complete)
    #102 = [[#13 * #13 * ABS [#7]] / [#13 * #13 – #2 * #2]]; (Intermediate calculation)
    #102 = #101 + #102; (Intermediate calculation)
    #102 = [[#13 * #13 – #2 * #2] / ABS [#7]] * #102; (Intermediate calculation)
    #102 = SQRT [#102]; (X calculated. Step 12 complete)
    X#102 Z#101; (Linear interpolation to the calculated coordinates. Step 13 complete)
    #101 = #101 + #100; (Z incremented by the specified step distance. Step 14 complete)
    END 1; (End of loop. Step 15 complete)
    #104 = [[#13 * #13 – #2 * #2] / [2 * #13 * ABS [#7]] * 2]; (Calculating ∆X, corresponding to ∆Z = 2 mm, at Z = 0)
    U#104 W2; (Additional tangential move at the outer edge of the parabola for removing any possible kink)
    G00 X#105 Z#106; (Rapid move to the original tool position)
    S#103 F#9; (Original rpm and feedrate restored)
    M99; (Return to the calling program. Step 16 complete)

    The toolpath for this program is attached here.
    Attached Files Attached Files

  14. #14
    Join Date
    Oct 2009
    Posts
    84
    Quote Originally Posted by Geof View Post
    I did some thinking, always a dangerous activity.

    Have you considered a different approach?

    An inefficient approach would be to perform the parabolic tool path many times and step the starting point forward using an incremental G52 Z command. This is inefficient because initially the machine will be cutting a lot of air.

    One way to improve the efficiency would be to write another macro to calculate the parabola OD which would then enter the macro for the parabola as the end point. This would reduce the time spent cutting air.
    Just have the macro eliminate any cutting for a z value greater than necessary to turn the parabola.. pretty simple.

Similar Threads

  1. Open Loop to Closed Loop Stepper Conversion
    By beamhome in forum Stepper Motors / Drives
    Replies: 11
    Last Post: 03-09-2014, 11:27 PM
  2. Replies: 11
    Last Post: 06-01-2009, 03:13 PM
  3. question on closed loop vs open loop (servo systems)
    By boonie in forum Servo Motors / Drives
    Replies: 20
    Last Post: 11-09-2007, 07:30 PM
  4. Closed loop vs. open loop
    By pelesl in forum Benchtop Machines
    Replies: 10
    Last Post: 04-06-2007, 10:56 PM
  5. Lathe conversion - open loop vs closed loop
    By bhowden in forum Uncategorised MetalWorking Machines
    Replies: 7
    Last Post: 03-21-2006, 10:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •