Need expert help debugging trochoidal milling macro, paging Sinha or similar.
Close
Login to Your Account
Page 1 of 3 123 LastLast
Results 1 to 20 of 57
  1. #1
    Join Date
    Jan 2019
    Country
    SWEDEN
    Posts
    220
    Post Thanks / Like
    Likes (Given)
    68
    Likes (Received)
    26

    Default Need expert help debugging trochoidal milling macro, paging Sinha or similar.

    I have a problem with a rather complex trochoidal line feed macro. The first version only does X and Y, and it works fine. The second does XYZ, adds support for tilting and concave/convex tool paths, and... well, that works too, but:

    It's designed for Fanuc 21i and it must be run with G05.1q1 in order to run smoothly. When G05.1 is activated in the second macro the machine goes haywire and loses its Z orientation, so it can only be run "normally", i.e. the machine stutters while processing. The primitive macro works fine with G05.1. I don't know why this is so.

    I can provide code but be warned it is a bit of a monster.

    Example of a generated tool path from the second version:

    g101-convex.jpg

  2. #2
    Join Date
    Jan 2014
    Country
    UNITED STATES
    State/Province
    Oregon
    Posts
    906
    Post Thanks / Like
    Likes (Given)
    283
    Likes (Received)
    686

    Default

    I can't even... Wait, what year is it?

    Why would you punish yourself with this?

  3. Likes gkoenig liked this post
  4. #3
    Join Date
    Jan 2019
    Country
    SWEDEN
    Posts
    220
    Post Thanks / Like
    Likes (Given)
    68
    Likes (Received)
    26

    Default

    Quote Originally Posted by boosted View Post
    I can't even... Wait, what year is it?

    Why would you punish yourself with this?
    Punish? I think coding macros is fun.

  5. #4
    Join Date
    Feb 2008
    Location
    MI, USA
    Posts
    1,069
    Post Thanks / Like
    Likes (Given)
    75
    Likes (Received)
    442

    Default

    Well you may as well post the code, nobody will be able to help you without it.

    Along with what controls you are using it with. you mentioned it was designed for 21i, but is that what you're running it poorly on, or what it worked on? 21ia or b? What's the machine?

  6. #5
    Join Date
    May 2017
    Country
    UNITED STATES
    State/Province
    Minnesota
    Posts
    2,253
    Post Thanks / Like
    Likes (Given)
    3123
    Likes (Received)
    1644

    Default

    I like to debug my macros with NCPlot. They have a free trial.

  7. #6
    Join Date
    Jan 2014
    Country
    UNITED STATES
    State/Province
    Oregon
    Posts
    906
    Post Thanks / Like
    Likes (Given)
    283
    Likes (Received)
    686

    Default

    Quote Originally Posted by Tichy View Post
    Punish? I think coding macros is fun.
    Same! That's why I responded. But I try to limit myself to things that can't be easily accomplished with CAM.

  8. #7
    Join Date
    Jan 2019
    Country
    SWEDEN
    Posts
    220
    Post Thanks / Like
    Likes (Given)
    68
    Likes (Received)
    26

    Default

    Everything is on a Fanuc 21iM Doosan Mynx.

    This is what I have trouble with.

    Code:
    :9016(M-TROCG1)
    (FIL=G101V2) 
    (G90 ONLY) 
    G4(EXACT STOP)
    (DEFAULTS)
    IF[#24EQ#0]THEN #24=#5001(DEFAULT XYZ CURRENT XYZ)
    IF[#25EQ#0]THEN #25=#5002
    IF[#26EQ#0]THEN #26=#5003 
    #101=#24-#5001	(DISTANCE X)
    #102=#25-#5002	(DISTANCE Y)
    #103=#26-#5003	(DISTANCE Z)
    #124=#24	(TARGET X)
    #125=#25	(TARGET Y)
    #126=#26	(TARGET Z)
    #134=#5001	(CURRENT X, CURRENT X ARC CENTER)
    #135=#5002	(CURRENT Y, CURRENT Y ARC CENTER)
    #136=#5003	(CURRENT Z, CURRENT Z ARC CENTER)
    #104=[SQRT[[#101*#101]+[#102*#102]]]				(DISTANCE XY)
    #105=[SQRT[[#101*#101]+[#102*#102]+[#103*#103]]]	(DISTANCE XYZ)
    #106=[ATAN[#102]/[#101]] 
    #107=#104/[FUP[#104/#17]]	(REAL Q IS <= Q) 
    #108=[#8-#7]/2 
    #109=#103/#104*#108
    #110=#103/#104*#107
    #140=#103/#104*#108
    #111=11.25		(TOOLPATH RESOLUTION)
    #120=#104(-#107)	(DISTANCE TO GO COUNTER.) 
    #121=#106-90		(CURRENT ANGLE COUNTER)
    #122=0			(TARGET ANGLE)
    IF[#22EQ#0]THEN#22=0	(DEFAULT VARIANT 0) 
    IF[#21EQ#0]THEN#21=1	(DEFAULT FEED MULTIPLIER 1) 
    IF[#09EQ#0]THEN#09=#4109	(DEFAULT FEED SYSTEM FEED)
    F#09(DEFAULT FEED) 
    GOTO#22(JUMP TO VARIANT) 
     
    N0(CIRCULAR TROCHOIDAL)
    G3X[#134+[COS[#121]*#108]]Y[#135+[SIN[#121]*#108]]Z[#136-#1]R[#108](ENTERING CUT)
    WHILE[#120GT0]DO1
    #122=#121+180(TARGET ANGLE FORWARD DIRECTION)
    F#09(DEFAULT FEED) 
    WHILE[#121LT#122]DO2 
    #121=#121+#111 
    G3X[#134+[COS[#121]*#108]]Y[#135+[SIN[#121]*#108]]Z[#136+[#140*COS[#121-#106]]+[#3*[SIN[[#121-#106-90]]]]+[#1*[COS[[#121-#106-90]]]]]R#108 
    END2 
    #122=#121+180(TARGET ANGLE BACKWARD DIRECTION) 
    F[#09*#21](OPTIONAL HIGHER FEED) 
    WHILE[#121LT#122]DO2 
    #121=#121+#111 
    G3X[#134+[COS[#121]*#108]]Y[#135+[SIN[#121]*#108]]Z[#136+[#140*COS[#121-#106]]+[#3*[-SIN[[#121-#106-90]]]]+[#1*[COS[[#121-#106-90]]]]]R#108
    END2 
    #121=#106-90(WE'RE BACK AT THE ORIGINAL ANGLE) 
    #134=#134+[COS[#106]*#107]	(NEW X) 
    #135=#135+[SIN[#106]*#107]	(NEW Y) 
    #136=#136+#110				(NEW Z)
    G1X[#134+[COS[#121]*#108]]Y[#135+[SIN[#121]*#108]]Z[#136+[#3*[SIN[[#121-#106-90]]]]+[#1*[COS[[#121-#106-90]]]]]
    #120=#120-#107	(SUBTRACT Q FROM DISTANCE TO GO)
    END1 
    (LAST ROTATION)
    #121=#106-90 
    #122=#121+180
    F#09(DEFAULT FEED) 
    G1X[#124+[COS[#121]*#108]]Y[#125+[SIN[#121]*#108]]Z[#126+[#1*[COS[[#121-#106-90]]]]] 
    WHILE[#121LT#122]DO2(TARGET ANGLE FORWARD DIRECTION) 
    #121=#121+#111 
    G3X[#124+[COS[#121]*#108]]Y[#125+[SIN[#121]*#108]]Z[#126+[#140*COS[#121-#106]]+[#3*[SIN[[#121-#106-90]]]]+[#1*[COS[[#121-#106-90]]]]]R#108 
    END2 
    #122=#121+180(TARGET ANGLE BACKWARD DIRECTION) 
    F[#09*#21](OPTIONAL HIGHER FEED) 
    WHILE[#121LT#122]DO2 
    #121=#121+#111 
    G3X[#124+[COS[#121]*#108]]Y[#125+[SIN[#121]*#108]]Z[#126+[#140*COS[#121-#106]]+[#3*[-SIN[[#121-#106-90]]]]+[#1*[COS[#121-#106-90]]]]R#108
    END2 
    G1X[#124]Y[#125]Z[#126](FINISHING CUT) 
    F#09(RESTORE FEED) 
    M99
     
    N1(SIMPLIFIED VARIANT) 
    G1X[#134+[COS[#121]*#108]]Y[#135+[SIN[#121]*#108]]Z[#136-#1](ENTERING CUT) 
    WHILE[#120GT0]DO1
    #122=#121+180(TARGET ANGLE FORWARD DIRECTION)
    WHILE[#121LT#122]DO2 
    #121=#121+#111 
    G3X[#134+[COS[#121]*#108]]Y[#135+[SIN[#121]*#108]]Z[#136+[#140*COS[#121-#106]]+[#3*[SIN[[#121-#106-90]]]]+[#1*[COS[[#121-#106-90]]]]]R#108 
    END2 
    #121=#121+180(RAPID EMPTY CUT) 
    G0X[#134+[COS[#121]*#108]]Y[#135+[SIN[#121]*#108]]Z[#136+[#140*COS[#121-#106]]+[#3*[-SIN[[#121-#106-90]]]]+[#1*[COS[[#121-#106-90]]]]] 
    #121=#106-90(WE'RE BACK AT THE ORIGINAL ANGLE) 
    #134=#134+[COS[#106]*#107]	(NEW X) 
    #135=#135+[SIN[#106]*#107]	(NEW Y) 
    #136=#136+#110			(NEW Z) 
    G1X[#134+[COS[#121]*#108]]Y[#135+[SIN[#121]*#108]]Z[#136+[#3*[SIN[[#121-#106-90]]]]+[#1*[COS[[#121-#106-90]]]]](ADVANCE Q) 
    #120=#120-#107	(SUBTRACT Q FROM DISTANCE TO GO)
    END1 
    (LAST ROTATION)
    #121=#106-90 
    #122=#121+180
    G1X[#124+[COS[#121]*#108]]Y[#125+[SIN[#121]*#108]]Z[#126+[#1*[COS[[#121-#106-90]]]]] 
    WHILE[#121LT#122]DO1(TARGET ANGLE FORWARD DIRECTION) 
    #121=#121+#111 
    G3X[#124+[COS[#121]*#108]]Y[#125+[SIN[#121]*#108]]Z[#126+[#140*COS[#121-#106]]+[#3*[SIN[[#121-#106-90]]]]+[#1*[COS[[#121-#106-90]]]]]R#108 
    END1 
    G0X[#124]Y[#125]Z[#126](FINISHING CUT) 
    M99
     
    (ARGUMENT) 
    (G101 X Y Z A C D E F Q V) 
    (X Y Z IS TARGET X Y Z)
    (A #01 IS ANGLE IS VERTICAL SKEW PARALLEL TO THE MOTION DIRECTION) 
    (C #03 IS CONVEXITY IN MM PARALLEL TO THE MOTION DIRECTION)
    (D #07 IS TOOL DIAMETER) 
    (E #08 IS SIMULATED TOOL DIAMETER) 
    (F #09 IS FEED)
    (U #21 IS FEED MULTIPLIER) 
    (Q #17 IS AE DEPTH OF CUT IN MM) 
    (V #22 IS VARIANT) 
    (V 0 IS CIRCULAR TROCHOIDAL AND SUPPORTS ALL BELLS AND WHISTLES) 
    (V 1 IS SIMPLIFIED. G0 BACKFEED. SOME STRAIGHT LINES.) 
    %

  9. #8
    Join Date
    Feb 2008
    Location
    MI, USA
    Posts
    1,069
    Post Thanks / Like
    Likes (Given)
    75
    Likes (Received)
    442

    Default

    I downloaded ncplot as suggested above. Great suggestion! I didn't know it would backplot macros!

    SO I ran this code:

    O1
    G90G80G40G17
    G0G54X0Y0S2000M3
    G43H1Z.1M8
    G1Z-.5
    G65P9016X10.Y5.Z-.5A0.C0.D.5E1.F100.U1.Q.1V0.
    M30


    My system is set in inches but it doesn't matter, it's just a matter of scale.

    It seemed to work okay? it kept the same z level. I don't have the time right now to plug it in my machine and see what it does, but maybe I might get to it tomorrow? I have a few 16i's, a and b included.

  10. #9
    Join Date
    Jan 2019
    Country
    SWEDEN
    Posts
    220
    Post Thanks / Like
    Likes (Given)
    68
    Likes (Received)
    26

    Default

    The macro works fine in simulation and it works on the machine but it will not work with G05.1Q1 which the previous version did, and without G05.1 the macro is lagging, stuttering instead of running smoothly, due to the processing power involved.

  11. #10
    Join Date
    May 2017
    Country
    UNITED STATES
    State/Province
    Minnesota
    Posts
    2,253
    Post Thanks / Like
    Likes (Given)
    3123
    Likes (Received)
    1644

    Default

    Perhaps the control just isn't up to it.

    I wrote a macro a number of years ago to engrave serial numbers, date, and time. It would scale, write at a specified angle, or on a specified arc, and optionally project onto a cylinder. It worked, but on many controls was painfully slow.

  12. #11
    Join Date
    Feb 2008
    Location
    MI, USA
    Posts
    1,069
    Post Thanks / Like
    Likes (Given)
    75
    Likes (Received)
    442

    Default

    I put the macro in my control (16imb). When running without g5.1, it works fine. but it pauses after each half circle.

    I put G5.1Q1 in there, and the first thing it does when it starts the macro is it wants to go way way way up in z.

    On the first iteration, variable #136 is calculated at a huge value (like +14" when i'm at machine -12"), and it wants to overtravel in z+


    without going into it further right now (i've gotta get some stuff done), I would think that with g5.1 it is simply looking too far ahead in part of the code and evaluating something it shouldn't be evaluating yet. you might need more codes that stop it from evaluating macros too far in advance? if it's even possible.

  13. #12
    Join Date
    Nov 2021
    Country
    UNITED STATES
    State/Province
    New York
    Posts
    17
    Post Thanks / Like

    Default

    Here is a trick I have used before to replace the crappy G5.1Q1 line of code or any other Fanuc "buffer" suggestions. Where you need a microsecond of a pause for the control to "buffer" or calculate a line of code correctly, before that line code place an M97 Pxxxx internal sub program call. In that sub program at the bottom place like 30 G04; codes with no X value one after another to start, then an M99 to return. You then can delete or add G04's to tailor your control's processing speed and have the fastest and smoothest macro program you could want. I had this problem with a VERY complex macro in a 31iB5 control and showed Bob Stafford from Fanuc and he could not believe the performance over their "buffer" codes. We even set up a macro to time each setup and this format smokes any other method.

    The beauty of this method is you can place the M97 Pxxxx before and after a calculation anywhere in the macro and it works perfect. Simulation software only helps so much. We had 4 Robodrills all in a row and each machine needed their own specific amounts of G04's to run perfectly. Crazy as it sounds, it's the truth.
    Last edited by RedBarn Research; 11-23-2021 at 11:08 AM. Reason: Forgot to add a note

  14. Likes sfriedberg, Tichy, reddman liked this post
  15. #13
    Join Date
    Oct 2007
    Country
    SPAIN
    Posts
    5,681
    Post Thanks / Like
    Likes (Given)
    1533
    Likes (Received)
    833

    Default

    Quote Originally Posted by dandrummerman21 View Post
    I put the macro in my control (16imb). When running without g5.1, it works fine. but it pauses after each half circle.

    I put G5.1Q1 in there, and the first thing it does when it starts the macro is it wants to go way way way up in z.

    On the first iteration, variable #136 is calculated at a huge value (like +14" when i'm at machine -12"), and it wants to overtravel in z+


    without going into it further right now (i've gotta get some stuff done), I would think that with g5.1 it is simply looking too far ahead in part of the code and evaluating something it shouldn't be evaluating yet. you might need more codes that stop it from evaluating macros too far in advance? if it's even possible.
    ^^^^This
    Same as issues with probe macros - I remember reading here Robodrills with problems where you have to dwell/slow certain things down, so it can read and execute a function before passing to the next.

    I think OP is potentially going to get bitten....because it's not just control specific, it's also MTB spec (options i.e. processor speed etc) of control specific, and also parameter specific/settings too.
    So what works on one 21 control, may crash on another....?

  16. #14
    Join Date
    Mar 2013
    Country
    UNITED STATES
    State/Province
    Oregon
    Posts
    2,268
    Post Thanks / Like
    Likes (Given)
    945
    Likes (Received)
    2949

    Default

    What you've effectively done is taken a line of trochoidal motion code generated offline (by CAM) and turned it into 75 lines of macro code you are processing in real-time. You need look-ahed to fill the buffer, but you can't fill the buffer because your code is calling current position. There is no real way around this situation if you want to run real-time.

    If the goal here is to enjoy writing macros; ditch the real-time component. Use the macro to write into a sub-program without real-time motion, then run the sub-program.

  17. Likes mhajicek liked this post
  18. #15
    Join Date
    Feb 2008
    Location
    MI, USA
    Posts
    1,069
    Post Thanks / Like
    Likes (Given)
    75
    Likes (Received)
    442

    Default

    So I took another stab at it before doing something else.

    To the op: have you tried single blocking the code? Because when i did that, it worked perfectly.

    In fact, after single blocking it until it made it to the loop inside, i was able to turn off single block and let it run. I only let it run for a minute so it didn't complete to the end, but Z was stable and where it was programmed to go.

    Then ran it without single block, it still fucked up Z.

    So then I decided to put some G4's and M1's after G5.1Q1 but before the g43 line. This resulted in a smaller error, but z was not where it was programmed to go and was ramping slightly upward.

    So then I put some g4's and M1's after the g43 line as well, but before the macro call. And that seemed to work.

    Below is the macro call that worked with your macro:


    Code:
    % 
    O7777(TRY MACRO) 
    G90G80G40G17 
    G0G54P20X0Y0S2000M3
    G5.1Q1 
     
     
     
     
    G43H1Z.1M8 
     
    M1 
    M1 
    M1 
    M1 
    M1 
    M1 
    G1Z-.5F50
    G4 
    G4 
    M1 
    M1 
    M1 
    G65P9777X10.Y5.Z-.5A0.C0.D.5E1.F100.U1.Q.1V0.
    G5.1Q0 
    M30
     
    %

    So I'm thinking that when G5.1 is active, it reads ahead into your macro, evaluates it, and the g04 that you have in it isn't enough, or it ignores it.

    I wasn't 100% positive that M1 will work the same as G4 but I think it does.

    Try it out op. See if yours works with single block on until you reach the loop in your macro, then turn it off.


    I agree with barbter, it is sketchy that it works funky and obviously you would need to be wary that it could cause you issues between machines. I would even worry about how it repeats, because it didn't even repeat the same z coordinates it calculated wrongly. They varied depending on... something?

  19. Likes Tichy liked this post
  20. #16
    Join Date
    Jan 2014
    Country
    UNITED STATES
    State/Province
    Washington
    Posts
    5,787
    Post Thanks / Like
    Likes (Given)
    1010
    Likes (Received)
    3249

    Default

    If you need to stop the look ahead insert a G31 or G53 at the point you want it to pause look ahead.

  21. #17
    Join Date
    Jan 2019
    Country
    SWEDEN
    Posts
    220
    Post Thanks / Like
    Likes (Given)
    68
    Likes (Received)
    26

    Default

    Hi again and thanks for all the feedback and many useful suggestions!

    @RedBarn Research; Yes, sounds non-intuitive but definitely promising! I'll play around with that, thanks so much for the tip. I'm not totally sure if subprogram is the way to go for me tho in a cpu intensive task because there's a bit of a delay in loading the subprogram on my Fanuc 21i but maybe you have good results with that version?
    @Vancbiker: Yes, I remember there was such a code, thank you for pointing it out, that may too be useful.
    @dandrummerman21: Thanks a bunch for testing out the macro on your machine! Your observations echo mine, except for the G4 stuff.

    I'm sorry the macro is so messy. It's old and has been lying around for a while but wanted to take a stab at perfecting it.

    So, update:

    I tested the macro in MDI today again at work with g05.1Q1 and... uh, it worked. No Z issue. Had no idea why (but your comments have given me hints.) Maybe some slight code changes that I haven't documented. However, like you noted, Dan, it pauses after each half circle.

    I couldn't find the exact "original" G101 macro that had no issues (because I'm messy) but: Ripping out #1 and #3 (skew and convexity) variables and calculations made it run smoothly. Meaning I now had a macro that could at least do stable 3-axis travel.

    Then at the end of the day after I signed out I tried to make a short program out of it and I got "over tolerance of radius", lol. Before it even made the first move. Then I tried the exact code that'd worked in MDI. Over tolerance of radius. Yeah, it's flaky. Have to check some system variables when I have time. Maybe it's because I didn't give any coordinates after G54 before I started the macro.

    I always activate G05.1 like so:
    G49
    G05.1Q1
    G54 ... (rest)

    This time the program was just:
    G49
    G05.1Q1
    G54S3000M3F3000
    G101 ********

    (Tried with both the #1-#3 macro and the simplified.)

    I'll try to tinker with it some more tomorrow if I have time, will post updates if I manage any worthwhile results.

    Addendum:

    Quote Originally Posted by mhajicek View Post
    Perhaps the control just isn't up to it.

    I wrote a macro a number of years ago to engrave serial numbers, date, and time. It would scale, write at a specified angle, or on a specified arc, and optionally project onto a cylinder. It worked, but on many controls was painfully slow.
    Not sure if it helps or if it's still of any interest but I had the same exact problem with an engraving macro of mine (is there any macro coder who hasn't done one) and I solved it for my control by splitting it into smaller subprograms. (Quite simple macro tho, only engraving straight lines.) GOTO was the villain. GOTO only searches forward and the code was too long. So I made a master program that passed the character codes to subprograms like:

    Code:
    % 
    :0020(FIL=M-GRAVGRAB)
    (PRODUCTION LINE ENGRAVING SYSTEM) 
    G9(EXACT STOP) 
    #121=#5001(START X)
    #122=#5002(START Y)
    #123=#5003(START Z)
    #131=#121(CURRENT X) 
    #132=#122(CURRENT Y) 
    (GRAB Y COORDINATES) 
    #110=0 
    WHILE[#110NE7]DO1
    #[140+#110]=[#132-[#110*#1/6]] 
    #110=#110+1
    END1 
    #111=4 
    #129=#1+#2 
    N900 
    WHILE[#[#111]NE#0]DO1
    (GRAB X COORDINATES) 
    #110=0 
    WHILE[#110NE7]DO2
    #[100+#110]=[[#110*#1/6]+#131] 
    #110=#110+1
    END2 
    G65P[8050+[FIX[#[#111]/10]]]I[#[#111]]C#3
    (CALLS 8050, 8051, 8052, ETC DEPENDING ON CHAR CODE) 
    #111=#111+3
    IF[#111EQ34]THEN#111=#0(LOOP KILLER) 
    N902 
    G0Z#123
    #131=#131+#1+#2
    X#131Y#132 
    END1 
    M99
    %

  22. #18
    Join Date
    Nov 2021
    Country
    UNITED STATES
    State/Province
    New York
    Posts
    17
    Post Thanks / Like

    Default

    G31 and G53 won't have the desired result either. Using an M97 Pxxxx with the sub containing G04's is the only way to go. Totally remove the G05.1 codes.

  23. #19
    Join Date
    Jan 2019
    Country
    SWEDEN
    Posts
    220
    Post Thanks / Like
    Likes (Given)
    68
    Likes (Received)
    26

    Default

    Quote Originally Posted by RedBarn Research View Post
    G31 and G53 won't have the desired result either. Using an M97 Pxxxx with the sub containing G04's is the only way to go. Totally remove the G05.1 codes.
    I would be very happy to be able to remove the G05.1 codes! They're a pain! I'll test your solution.

  24. #20
    Join Date
    Sep 2010
    Location
    Victoria Australia
    Posts
    4,210
    Post Thanks / Like
    Likes (Given)
    0
    Likes (Received)
    1799

    Default

    Quote Originally Posted by RedBarn Research View Post
    G31 and G53 won't have the desired result either. Using an M97 Pxxxx with the sub containing G04's is the only way to go. Totally remove the G05.1 codes.
    If G31 and G53 aren't having the desired result, it's because they're being used in the wrong location; your method is a clumsy way of creating a function to do what G31/G53 do. They have to be located in the program before any Block that is reading a coordinate from a System Variable, where the axis is in motion.

    G01 Z-20.00
    #1 = #5043
    G31 (or G53)

    The above will give an erroneous result, but the following will be correct. Even with the Subprogram method you suggested, the M97 call would have to be in the same location as the G31/G53 in the following snippet.

    G01 Z-20.00
    G31 (or G53)
    #1 = #5043


Tags for this Thread

Bookmarks

Posting Permissions

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