587,523 active members*
3,612 visitors online*
Register for free
Login
Page 1 of 3 123
Results 1 to 20 of 48
  1. #1
    Join Date
    Feb 2011
    Posts
    0

    Need help with G3 code

    I am a noobie... that said I wrote the following program and it does exactly what I intended:

    G21 (sets the file units to millimeters. )
    #1 = 38 (Rough Diameter of Post)
    #2 = 12.7 (Cutter diameter)
    #3 = -5 (Z depth increment value )
    #4 = [#1 + #2] (Diameter of POST to mill... post diameter + tool diameter )
    #5 = [#4 / 2] (Radius of POST to mill )
    #8 = 100 (travel speed )

    (rough cut the post)
    G90
    G0 X[#5 * -1] Y0 Z5 F#8
    #6 = 1 (tool depth counter)
    #7 = 0 (actual Z depth variable )
    M98 P100 L4

    (finish cut the post)
    #1 = 35.50 (Finish Diameter of Post)
    #4 = [#1 + #2] (Diameter of POST to mill... post diameter + tool diameter )
    #5 = [#4 / 2] (Radius of POST to mill )
    G1 X[#5 * -1] Y0
    G17 G3 x[#5 * -1] y0 i#5 j0 (select the XY plane and do arc counter clockwise )

    (cut relief for tube seam weld)
    G0 Z5
    G0 X#5 Y0
    G0 Z#7
    G1 X [#5 - 1]

    (cut the hole---lighten the finished piece)
    #1 = 25 (Diameter of Hole)
    #4 = [#1 - #2] (Corrected Diameter of HOLE to mill... hole diameter - tool diameter )
    #5 = [#4 / 2] (Radius of HOLE to mill )
    G0 Z5 (clear the Z axis from the work surface)

    G0 X[#5 * -1] Y0 Z5 F#8
    #6 = 1 (tool depth counter)
    #7 = 0 (actual Z depth variable )
    M98 P110 L4

    M30

    O100 (mill a POST)
    #6 = [#6 + 1] (increment counter)
    #7 = [#3 * #6] (adjust tool depth for this count)
    G1 Z#7 (set tool depth)
    G17 G3 x[#5 * -1] y0 i#5 j0 (select the XY plane and do arc counter clockwise )
    M99 (return from subroutine)

    O110 (mill a HOLE)
    #6 = [#6 + 1] (increment counter)
    #7 = [#3 * #6] (adjust tool depth for this count)
    G1 Z#7 (set tool depth)
    G17 G2 x[#5 * -1] y0 i#5 j0 (select the XY plane and do arc clockwise )
    M99 (return from subroutine)



    Then I wrote the following and it did exactly what I expected:

    G21 (sets the file units to millimeters. )
    #1 = 38 (Diameter of large arc)
    #2 = 12.7 (Cutter diameter)
    #3 = -5 (Z depth increment value )
    #4 = [#1 + #2] (Diameter of POST to mill... post diameter + tool diameter )
    #5 = [#4 / 2] (Radius of POST to mill )
    #8 = 100 (travel speed )
    #9 = 11.4 (diameter of small arc)

    G90

    G0 X0 Y#5 Z5 F#8
    #6 = 1 (tool depth counter)
    #7 = 0 (actual Z depth variable )
    M98 P100 L4

    M30

    O100 (mill a POST)
    #6 = [#6 + 1] (increment counter)
    #7 = [#3 * #6] (adjust tool depth for this count)
    #4 = [#1 + #2] (Diameter of large arc to mill... post diameter + tool diameter )
    #5 = [#4 / 2] (Radius of large arc )
    G1 Z#7 (move the tool to starting depth)
    G17 G3 X0 Y[#5 * -1] i0 j[#5 * -1] (select the XY plane and do large arc counter clockwise )
    #4 = [#9 + #2] (Diameter of small arc to mill... post diameter + tool diameter )
    #5 = [#4 / 2] (Radius of small arc )
    G1 X25.45 Y[#5 * -1] (cut to starting point of small arc)
    G17 G3 X25.45 Y#5 i0 j#5 (select the XY plane and do small arc counter clockwise )
    #4 = [#1 + #2] (Diameter of large arc to mill... post diameter + tool diameter )
    #5 = [#4 / 2] (Radius of large arc )
    G1 X0 Y#5 (cut to starting point of large arc)
    M99 (return from subroutine)


    Now comes the problem:
    I want the second program to create the large arc and the small arc such that they end on a line that is tangent to both arcs. That way I have a smooth transition from the large arc to the small arc. I have wrote many test programs trying to understand the G3 command but try as I might... I can only seem to get it to do a half circle instead of the "little more" that I need

    can anyone help me? If you consider that the center point of the large arc is 0,0 I know where I want to start milling the arc and I know where I want to stop milling the arc. From there I want to mill a "straight line" to the tangent of the small arc, mill the small arc, and mill a "straight line" back to my starting point.

    thanks in advance
    cj

  2. #2
    Join Date
    Sep 2010
    Posts
    1230
    A quick look at your program, gives me to believe that in the attached picture, the Green is the tool path that you currently achieve, but your question indicates that you want a combination of the Green Arcs and the Red Lines.

    Click image for larger version. 

Name:	LS_Circles.JPG 
Views:	45 
Size:	16.3 KB 
ID:	129614

    The above being the case, you need to do some maths with your User MAcro code to calculate the 4 Tangent Points of the 2 circles and 2 Red lines. Having done that, you will have the Start Point, End Point, I and J values to use in the G03 command line. The blue triangles in the attached picture have to be calculated to gain this information. Its not shown in the picture, but you would use the same method to calculate the tangent points of the small circle as was used for the large circle.

    Click image for larger version. 

Name:	LS_Circles2.JPG 
Views:	46 
Size:	23.0 KB 
ID:	129617
    The following code is an example of what your coordinates should be, and how applied to the G03 command lines. Of course, you would substitute the X, Y, I, and J values where applicable with the Macro Variables used to receive the calculated data.

    Regards,

    Bill

    G01 X13.790 Y21.271
    G03 X13.790 Y-21.271 I-13.790 J-21.271
    G01 X31.005 Y-10.111
    G03 X31.005 Y10.111 I-6.555 J10.111
    G01 X13.790 Y21.271

  3. #3
    Join Date
    Feb 2011
    Posts
    0
    you are correct Anglew. That is the end result I am looking for but my problem is not the math to calculate where the two tangent lines begin and end. My problem is making the arcs start and end at those tangent points. I just can't seem to make the arc begin and end where I want them to

  4. #4
    Join Date
    Feb 2011
    Posts
    0
    Angelw.... I love u

    I ran your little code snippit and it does exactly what I want. After playing with it some... commenting out some steps... I figured out why I was having problems.

    I'm off and running now... thanks a bunch

  5. #5
    Join Date
    Feb 2011
    Posts
    0
    I need to ask you one more thing Anglew. You came up with the correct numbers for the tangent intercepts awfully quickly... how did you do that?
    cj

    and thanks again for the help

  6. #6
    Join Date
    Sep 2010
    Posts
    1230
    Quote Originally Posted by cjluke View Post
    I need to ask you one more thing Anglew. You came up with the correct numbers for the tangent intercepts awfully quickly... how did you do that?
    cj

    and thanks again for the help
    Like a lot of people that answer questions on this forum, I've been doing this a long time. I started in the days of NC, when paper tapes had to be created to run a program and programming was predominately done by calculating the tool path manually (no CAM systems). The math in your problem is simple so its a relatively quick program to do.

    By the way, the early Fanuc Mill, Conversational program was based on the User Macro executable, (not sure about more recent models; I haven't bothered to look). Pocket clearing was achieved by altering the value of the Macro Variable holding the Tool Radius data. This method was also used to accurately size the feature, by applying a value to the Tool Radius Variable and not using G41 or G42 (cutter radius comp). This worked pretty well, as you didn't have to worry so much about how you had the cutter approach the cutter path, as you do when using G41 or G42.

    You could expand your Macro program by applying a Tool Radius System Variable to #2 used in your program. That way you could tweak the size of the feature via a Tool Offset, rather than hard coding the value. You will find the reference to the System Variables in your Fanuc programming manual.

    Regards,

    Bill

  7. #7
    Join Date
    Feb 2011
    Posts
    0
    And you thought you were through with me

    I have one more question. I have figured out everything you calculated but one value:

    G0 X13.790 Y21.271
    G03 X13.790 Y-21.271 I-13.790 J-21.271
    G01 X31.005 Y-10.111


    G03 X31.005 Y10.111 I-6.555 J10.111
    ______

    G01 X13.790 Y21.271

    how did you arrive at the value I-6.555?????

  8. #8
    Join Date
    Sep 2010
    Posts
    1230
    Quote Originally Posted by cjluke View Post
    And you thought you were through with me

    I have one more question. I have figured out everything you calculated but one value:

    G0 X13.790 Y21.271
    G03 X13.790 Y-21.271 I-13.790 J-21.271
    G01 X31.005 Y-10.111


    G03 X31.005 Y10.111 I-6.555 J10.111
    ______

    G01 X13.790 Y21.271

    how did you arrive at the value I-6.555?????
    No problem, ask as many questions as you like; I'm glad to be able to help.

    I and J are specified in the circular interpolation (G02/G03) command line in terms of distance and direction from the Start Point of the arc, to the Center Point of the same arc. Coincidentally, during the process of calculating the tangent point of the small circle and line, you also gain the I and J value. See the attached picture.

    Click image for larger version. 

Name:	LS_Circles3.JPG 
Views:	56 
Size:	28.4 KB 
ID:	129657


    Regards,

    Bill

  9. #9
    Join Date
    Jul 2003
    Posts
    1220
    This may help with your macro.
    R1 = radius of larger circle
    R2 = radius of smaller circle
    CC = centre to centre

    Angle = ASine(R1-R2) / CC

    X1 = Sine(Angle) * R1
    Y1 = Cos(Angle) * R1

    X2 = (Sine(Angle) * R2) + CC
    Y2 = Cos(Angle) * R2
    Attached Thumbnails Attached Thumbnails Tangent Points.JPG  
    Attached Files Attached Files

  10. #10
    Join Date
    Feb 2011
    Posts
    0
    Thanks Kiwi and thanks Angelw.... problem was this 65 year old man's brain not wanting to get back into trig and geometry

    I finally managed to see what I was doing wrong and have generated the following code that behaves like I wanted it to. If not for you two, I would still be working on it. Thanks again and I will probably come knocking on your doors again. A friend and I bought a Kondia Powermill 3 axis CNC running Mach 3. Neither of us are machinist so we have much to learn

    here is the code I wrote. I have a lot I need to add to it but the hard part was the outside shape:
    thanks again
    cj

    G21 (sets the file units to millimeters. )
    #1 = 38 (Diameter of large arc)
    #2 = 12.7 (Cutter diameter)
    #3 = -5 (Z depth increment value )
    #4 = [#1 + #2] (Diameter of large arc to mill... arc diameter + tool diameter )
    #5 = [#4 / 2] (Radius of Large arc to mill )
    #8 = 100 (travel speed )
    #9 = 11.4 (diameter of small arc)
    #10 = [#9 + #2] (diameter of small arc to mill )
    #11 = [#10 / 2] (radius of small arc to mill )
    #12 = 25.5 (distance between the two arc centers)
    #13 = [2*ACOS[[#5-#11]/#12] * 57.2957795] (angle Theta in degrees start of large arc)
    #15 = [#5 * COS[#13]*-1] (x position to start of large arc)
    #16 = [#5 * SIN[#13]*-1] (y position to start of large arc)
    #17 = [[#9 * COS[#13]*-1] + #12] (x position to start of small arc)
    #18 = [#9 * SIN[#13]*-1] (y position to start of small arc)
    (rough cut the outside of the part)
    G0 X#15 Y#16
    #6 = 1 (tool depth counter)
    #7 = 0 (actual Z depth variable )
    M98 P100 L4
    M30
    O100 (mill the shape)
    #6 = [#6 + 1] (increment counter)
    #7 = [#3 * #6] (adjust tool depth for this count)
    G1 Z#7 (set tool depth)
    G17 G03 X[#15] Y[#16 * -1] I[#15 * -1] J[#16 * -1]
    G01 X#17 Y[#18*-1] (cut to start of small arc)
    G17 G03 X#17 Y[#18] I[[#17 - #12]*-1] J#18 (select the XY plane and do small arc counter clockwise )
    G01 X#15 Y#16 (cut to starting point of large arc)
    M99 (return from subroutine)

  11. #11
    Join Date
    Feb 2006
    Posts
    1792
    Instead of multiplying a variable with -1, why don't you just put a minus sign before the variable? It works on my machine.

  12. #12
    Join Date
    Sep 2010
    Posts
    1230
    Quote Originally Posted by cjluke View Post
    Thanks Kiwi and thanks Angelw.... problem was this 65 year old man's brain not wanting to get back into trig and geometry


    G21 (sets the file units to millimeters. )
    #1 = 38 (Diameter of large arc)
    #2 = 12.7 (Cutter diameter)
    #3 = -5 (Z depth increment value )
    #4 = [#1 + #2] (Diameter of large arc to mill... arc diameter + tool diameter )
    #5 = [#4 / 2] (Radius of Large arc to mill )
    #8 = 100 (travel speed )
    #9 = 11.4 (diameter of small arc)
    #10 = [#9 + #2] (diameter of small arc to mill )
    #11 = [#10 / 2] (radius of small arc to mill )
    #12 = 25.5 (distance between the two arc centers)
    #13 = [2*ACOS[[#5-#11]/#12] * 57.2957795] (angle Theta in degrees start of large arc)
    #15 = [#5 * COS[#13]*-1] (x position to start of large arc)
    #16 = [#5 * SIN[#13]*-1] (y position to start of large arc)
    #17 = [[#9 * COS[#13]*-1] + #12] (x position to start of small arc)
    #18 = [#9 * SIN[#13]*-1] (y position to start of small arc)
    (rough cut the outside of the part)
    G0 X#15 Y#16
    #6 = 1 (tool depth counter)
    #7 = 0 (actual Z depth variable )
    M98 P100 L4
    M30
    O100 (mill the shape)
    #6 = [#6 + 1] (increment counter)
    #7 = [#3 * #6] (adjust tool depth for this count)
    G1 Z#7 (set tool depth)
    G17 G03 X[#15] Y[#16 * -1] I[#15 * -1] J[#16 * -1]
    G01 X#17 Y[#18*-1] (cut to start of small arc)
    G17 G03 X#17 Y[#18] I[[#17 - #12]*-1] J#18 (select the XY plane and do small arc counter clockwise )
    G01 X#15 Y#16 (cut to starting point of large arc)
    M99 (return from subroutine)

    I'm sure I speak for Kiwi and all contributors of this forum, when I say that its good to get some feedback and see a positive outcome as a result of suggestions made.

    As with most things, there are a number of ways to skin this cat. Shown in Red is one of a few ways of repeating a profile down in Z without having to be concerned about over cutting, whilst giving you the opportunity of changing the depth of cut without having to ensure that its exactly divisible into the full depth.

    Also, you should take a look at passing your variable values to the Macro using a simple call statement as follows. This example is only passing the values for the cut in and full depth, but other variables could be passed as well. It just makes for a more organized program; you will create better structured programs as you do more.

    G65 C-5.0 D0.0 I-23.0 P100

    In the above example C=#3, D=#7 and I=#4 when passed to you Macro program

    I've just used -23.0 for full depth to show that the cut in depths don't have to be exactly divisible into the full depth.

    Regards,

    Bill


    M98 P100 (just call the program once without repeats)

    O100
    (#7 = 0 (Z start level)) from main program
    (#3 = -5.0 (Z depth of cut)) from main program
    #4 = -23.0 (Z full depth) example depth
    N10
    #7 = #7 + #3 (adjust tool depth)
    IF [#7 LT #4] THEN #7 = #4
    (make #7 = full depth to stop over cutting)

    G1 Z#7 (set tool depth)
    G17 G03 X[#15] Y[#16 * -1] I[#15 * -1] J[#16 * -1]
    G01 X#17 Y[#18*-1] (cut to start of small arc)
    G17 G03 X#17 Y[#18] I[[#17 - #12]*-1] J#18 (select the XY plane and do small arc counter clockwise )
    G01 X#15 Y#16 (cut to starting point of large arc)
    IF [#7 GT #4] GOTO10 (go back to N10 if not to depth)
    M99 (return from subroutine)

  13. #13
    Join Date
    Jul 2003
    Posts
    1220
    Quote Originally Posted by cjluke View Post
    #13 = [2*ACOS[[#5-#11]/#12] * 57.2957795] (angle Theta in degrees start of large arc)
    #15 = [#5 * COS[#13]*-1] (x position to start of large arc)
    #16 = [#5 * SIN[#13]*-1] (y position to start of large arc)
    #17 = [[#9 * COS[#13]*-1] + #12] (x position to start of small arc)
    #18 = [#9 * SIN[#13]*-1] (y position to start of small arc)
    Is #9 in line #17 and #18 correct? shouldn't these be #11.
    I'm not sure angle #13 is correct. My calculation using your maths:
    #15 = 11.5579
    #16 = -22.5619
    #17 = 30.994 (using #11)
    #18 = -10.7247 (using #11)

    #13 Not sure why the angle is multiplied by 2
    Also does the radians need to be converted to degrees?
    Suggest the '*-1' not required. Add the minus in the code line where required.
    #17 does not add up correctly when part is a minus number.

    Just my 2 cent worth.

  14. #14
    Join Date
    Feb 2011
    Posts
    0
    Wow! This is one helluva forum. Thanks for all the help and suggestions. If you refer back to my original post, I started out telling everyone that I am a noobie

    I didn't know I could just assign a negative value to a variable with the minus sign.

    Bill, you keep referring to my "macro" program... not sure what you mean. I hand wrote this code. I don't know how to write macro's for Mach3 yet. I still have a lot of learning to do with this stuff.

    Also as far as I know... I am limited to giving the variables an integer label, which is really frustrating, as a programmer, I used variable names to make code more readable. Mach3 has another serious limitation as far as I can tell, it doesn't have any conditional statements I seem to be stuck with the gosub and repeat value.

    If anyone out there knows different, please let me know.

    Kiwi,
    I actually laid this out on a spread sheet to check my math. I used
    theta = 2cos^1((r1-r2)/P) where P = separation of the two circles/arcs. Once I had that angle I could use sin theta = y/r and cos theta = x/r to solve for my x,y coordinates for both arcs and add in my P offset. My only excuse is I haven't fooled with plane geometry or trig in a long time ( I'm almost 65) and it was the first way that came to mind for me to find the x,y point where the tangent intercepted the large arc.

    Hopefully I will get better with the math and the Mach3 capabilities over time. I have certainly come a long way in the last week
    thanks again to all of you for the help
    cj

  15. #15
    Join Date
    Sep 2010
    Posts
    1230
    Quote Originally Posted by cjluke View Post
    Bill, you keep referring to my "macro" program... not sure what you mean. I hand wrote this code. I don't know how to write macro's for Mach3 yet. I still have a lot of learning to do with this stuff.

    Also as far as I know... I am limited to giving the variables an integer label, which is really frustrating, as a programmer, I used variable names to make code more readable. Mach3 has another serious limitation as far as I can tell, it doesn't have any conditional statements I seem to be stuck with the gosub and repeat value.

    If anyone out there knows different, please let me know.


    cj
    Looking back over this thread, the type of control is not stated. However, from the syntax of your code I assumed that it was a Fanuc control. The parametric programming format you're using, employing variables and calculation blocks is referred to as "User Macro B" language in Fanuc speak and the code you have listed thus far is exactly the same syntax as the Fanuc User Macro B syntax. A program that uses this syntax is referred to as a Macro program. It seems strange that your control would emulate the Fanuc User Macro system so closely in what you have listed, and not go the whole hog. Sorry if I've confused the issue.

    Regards,

    Bill

  16. #16
    Join Date
    Feb 2011
    Posts
    0
    Kiwi... you were absolutely correct!

    Is #9 in line #17 and #18 correct? shouldn't these be #11.
    I'm not sure angle #13 is correct. My calculation using your maths:
    #15 = 11.5579
    #16 = -22.5619
    #17 = 30.994 (using #11)
    #18 = -10.7247 (using #11)

    #17 and #18 should be using #11... and I am just now trying to figure out how it gave me the results it did. I tried changing:

    #9 = 11.4 (diameter of small arc)
    to
    #9 = 23 (diameter of small arc)
    and the program blows up.... mills something entirely different

    So my math is screwed up somewhere and I am back taking a look at it.


    Angelw...
    It won't let me assign a negative either I have to multiply by -1 as far as I can tell.

    thanks again to both of you
    cj

  17. #17
    Join Date
    Feb 2011
    Posts
    0
    well thanks to you guys, I found the problem with my code and have increased the scope of the program some. I am beginning to understand the G2/G3 function now and think I will be able to use it more easily

    thanks again
    cj

  18. #18
    Join Date
    Jul 2003
    Posts
    1220
    These diagrams may help.
    Attached Thumbnails Attached Thumbnails cjluke1.JPG   cjluke2.JPG  

  19. #19
    Join Date
    Feb 2011
    Posts
    0
    Thanks Kiwi, that helps a lot. Thanks to you and Angelw, I am starting to get the hang of the G2/G3 function as well as the way the coordinate system works.

    I do have a machining question (a subject I am also a noobie in)... can you use a vertical mill turning a small 'v' shaped cutter (the geometry of which I think I can master) to cut threads, let's say 16 tpi on the inside of a hole that is about an inch in diameter? I was thinking of trying to use the helical cutting action of the G2 function to control the Z axis at a rate that would yield the correct pitch of thread. The cutter geometry seems possible to me but I don't know so I thought I would ask you guys.

    I could always buy a tap... but milling the threads seems so much more elegant

    thanks guys
    cj

  20. #20
    Join Date
    Apr 2005
    Posts
    175

    G Code

    Look at G12 or G13. This gives you circular interpolation in the XY plane ,synchronized with the linear interpolation in the Z axis.

Page 1 of 3 123

Similar Threads

  1. Replies: 4
    Last Post: 03-29-2011, 02:39 PM
  2. fanuc program code vs. Haas code
    By sixty8frbrd in forum Fanuc
    Replies: 6
    Last Post: 03-11-2011, 04:05 AM
  3. Converting Fanuc G code to Seimens 840D G code
    By Jasbinder in forum SIEMENS -> Sinumerik 802D/808D/810D/828D/840D
    Replies: 2
    Last Post: 02-20-2011, 05:02 PM
  4. Replies: 8
    Last Post: 12-15-2010, 09:32 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
  •