588,522 active members*
7,750 visitors online*
Register for free
Login
IndustryArena Forum > Machine Controllers Software and Solutions > G-Code Programing > Ok, how do I do write a simple program in gcode?
Results 1 to 16 of 16
  1. #1
    Join Date
    Feb 2004
    Posts
    427

    Ok, how do I do write a simple program in gcode?

    Ok, how do I do write a simple program in gcode?

    I want to make the mill go from say 0 to 100, then back to 50 then up to 200 and back to 150 then up to 250 etc.

    So far I know G0y100 will move me from home, to y100mm position at full speed.

    There is an F200 command for feed speed, but where abouts in that line would that F code go?

    And can I add in a dwell too.
    And do I have to then number the lines as N1, N2, N3 with each seperate command on each line etc.

    Peter
    My little site on MIG welding http://www.learn-how-to-weld.com/mig-welding/

  2. #2
    Join Date
    Jan 2005
    Posts
    15362
    Apples

    G0 is for rapid moves, G1Y100F50. G1 is what you want to use for a feed move

    G1Y100F50.
    G1Y-50F50.

    A Dwell is G04P500 The 500=0.5 second dwell (place this on a line by its self were ever you want it to stop/Dwell)

    Try this to start to see how it will work for you, You can ajust the numbers to suit
    Mactec54

  3. #3
    Join Date
    Feb 2004
    Posts
    427
    Cool thanks for that, I will give it a shot tomorrow and see how I go.

    yes G01 makes sense now..

    In this code G04P500 What does the 4 mean? Or is it G04 together which means dwell, it looks like that.
    My little site on MIG welding http://www.learn-how-to-weld.com/mig-welding/

  4. #4
    Join Date
    May 2007
    Posts
    781
    Here is a run down on G-Code, standards are not strictly adhered to so things do change from machine to machine.
    G-code - Wikipedia, the free encyclopedia

    One of the better books I have found on CNC programming.
    CNCProgramming Handbook: Acomprehensive Guide to Practical Cnc Programming by Peter Smid - ISBN 9780831133474

    And yes the dwell command is G04 or most machines will also take G4

  5. #5
    Join Date
    Jul 2007
    Posts
    1602
    Apples, whitespace within a block and leading zeros aren't significant in G-Code so G04P500 is the same as:

    G04 P500
    G4 P500
    G4P500

    I suggest you download http://www.machsupport.com/docs/Mach3Mill_1.84.pdf and read chapter 10. It gives a good introduction to g-code and will answer a lot of your questions.

    bob

  6. #6
    Join Date
    Jan 2005
    Posts
    15362
    Apples

    G04 is the code P500 is the time for the Dwell
    Mactec54

  7. #7
    Join Date
    Feb 2004
    Posts
    427
    Hey, I could get it to dwell. But then it just kept on dwelling, like chilling out and not moving at all.

    Here is a similar code

    o0001 (program name)
    N10 G00 Y100
    N20 G4 P500
    N30 G00 Y0

    Do I need to add a start/go code after the dwell command?
    My little site on MIG welding http://www.learn-how-to-weld.com/mig-welding/

  8. #8
    Join Date
    Jan 2005
    Posts
    15362
    Apples

    Try this G0Y0.

    You need a ./ period after the zero
    Mactec54

  9. #9
    Join Date
    Sep 2010
    Posts
    1230
    Quote Originally Posted by Apples View Post
    Hey, I could get it to dwell. But then it just kept on dwelling, like chilling out and not moving at all.

    Here is a similar code

    o0001 (program name)
    N10 G00 Y100
    N20 G4 P500
    N30 G00 Y0

    Do I need to add a start/go code after the dwell command?
    What controller is on the machine you're using?

    Posted by mactec54

    Try this G0Y0.
    You need a ./ period after the zero

    If its a Fanuc Control a period (decimal point) makes not difference for a zero value, Y0, Y0., Y0.0 are treated all the same by the Fanuc control. If a period is omitted in a coordinate value, the control will count 3 or 4 places to the left, depending on whether the control is in imperial or metric mode. In metric mode G21, Y100000 is read as Y100., similarly, Y100 is read as Y0.100

    With a Fanuc control, G04 can be specified as Revs of the spindle by specifying G95 before the G04 dwell call, either on the same line of prior to the call. If your machine is in G95 (feed per revolution) mode and the spindle is not running, the program will stop at the dwell line waiting for the required number of rotations to be completed. You only show the move lines in your program snippet, so I don't know if you have the spindle running or not. If the spindle is not running, that may be the reason for the program dwelling for an indefinite period.

    The fact that the move lines are in rapid traverse will allow those moves to occur irrespective of the control being in G95 (feed per revolution), or G94 (feed per minute) mode as rapid positioning does not rely on the spindle rotating. Put G94 in your program prior to the G04 command and that should fix the problem if the spindle is not running.

    That's about the only thing that I can see in your program that would make it stop indefinitely once the G04 command has been launched.

    Again depending on the control, an X value will work with a G04 and is my preference. G04 X0.5 will initiate a dwell of 0.5 seconds in G94 mode and 0.5 spindle revs in G95 mode. With a Fanuc control, there is a parameter that can be set that will cause the G04 to be treated as a dwell in seconds for both G94 and G95 mode.

    Regards,

    Bill

  10. #10
    Join Date
    May 2005
    Posts
    2502
    Yes indeed, welcome to the wonderful world of different controls which have slightly different g-code dialects.

    Some controls want that trailing decimal point even if there is no fraction, so we have to write "X1.". Some don't care and we can write "X1".

    RE your G4 (and there are controls that make you write G04) Dwell, the P500 may be interpreted as 500 milliseconds = 1/2 second on some controls or 500 seconds = over 8 minutes on others. That may be one reason why your Dwell just went on and on. As was pointed out, Dwell may also be expressed as revolutions (handy for some operations like making sure the bottom of the hole has seen a rev or two before you withdraw the twist drill).

    So, your first task is to lay hands on the programming book for your controller. Otherwise all these little idiosyncracies will make no sense as each person gives you advice from the context of their controller.

    You might find my G-Wizard G-Code Editor a helpful tool for learning:

    GWizardE: A Machinist's CNC G-Code Editor

    It lets you setup the g-code to match your controller's preferences. BTW, CAM programs call that a "post" informally. GWE has a "post" capability.

    In addition it has "Wizards" to help you get the syntax right entering the g-codes and "Hints" that tell you what the g-code does in plain English.

    Since it's in Beta test, it's free to play around with.

    Cheers,

    Bob Warfield
    Try G-Wizard Machinist's Calculator for free:
    http://www.cnccookbook.com/CCGWizard.html

  11. #11
    Join Date
    Jan 2009
    Posts
    24

    G code programming

    For Fanuc style controls, always use a decimal point in your moves. Example
    X5 means move .0005, X5. means move 5 inches. Big difference. Use your G0 to X, Y, rapid to where you want to do your work. You have to use height offset to rapid to where you want to start. Example G43H1Z.1 would use the value in height offset register 1 to move your Z axis to .10 above the top of your part. Use a G1 with a feedrate of say F5. for 5 inches per minute to feed to the depth required, since the G1 is modal, that means it is in a feed rate mode until you give it a different G0 code, you can just write the coordinates that you want to machine too. Example G1 Z-.25 F5.; X-1.Y1.;
    Y-1.;X1.;Y1.;X-1.;X0.Y0.;G0Z1.;M30; If you were using a .50 mill, the above program would cut you a 1.5 square pocket .25 deep, go back to the center and rapid the Z up 1.0 from the top of your part. Hope this helps from an old timer.

  12. #12
    Join Date
    Nov 2004
    Posts
    260
    Quote Originally Posted by Apples View Post
    Hey, I could get it to dwell. But then it just kept on dwelling, like chilling out and not moving at all.

    Here is a similar code

    o0001 (program name)
    N10 G00 Y100
    N20 G4 P500
    N30 G00 Y0

    Do I need to add a start/go code after the dwell command?
    May need to make sure the Controller is in G90 absolute mode.
    Else if a G91 incremental mode is active the N30 G00 Y0 line will not move anywhere.

  13. #13
    Join Date
    Jun 2008
    Posts
    1511
    On the Fanuc controls it is a parameter setting that dictates the decimal needed or not needed. This is not specific to a control or MTB. I don't have a manual in front of me but it is labeled as conventional or calculator method. Calculator method will read X1 as X1.000 I always set up my controls this way so I don't have to use the decimal.

    Stevo

  14. #14
    Join Date
    Sep 2010
    Posts
    1230
    Quote Originally Posted by stevo1 View Post
    On the Fanuc controls it is a parameter setting that dictates the decimal needed or not needed. This is not specific to a control or MTB. I don't have a manual in front of me but it is labeled as conventional or calculator method. Calculator method will read X1 as X1.000 I always set up my controls this way so I don't have to use the decimal.

    Stevo
    So how is X1.25 written as apposed to X125.0? To write the former, the decimal point is required. It comes down to preference at the end of the day. I prefer to consistently use a decimal point format so that if a decimal point is accidentally omitted, there is no confusion as to whether the period is required or not, and that X1.25 doesn't suddenly become X125; processed as X125.0 in calculator method.

    Regards,

    Bill

  15. #15
    Join Date
    Feb 2006
    Posts
    1792
    X1.25 is always X1.25 irrespective of parameter setting.
    The problem starts when you skip decimal. In such a case, interpretation would depend on parameter setting. For example, X125 may be interpreted as 125 inch or 0.0125 inch (125 steps in the least input increment). It is, therefore, a good practice not to skip decimal if the program is to be used on other machines also. Many a time, you cannot be sure about parameter settings of all the machines.
    Skipping decimals of course reduces typing efforts and saves some memory space.

  16. #16
    Join Date
    Jun 2008
    Posts
    1511
    Bill I agree it all comes down to preference. X125 is X125.000 and X.125 is X.125

    There are a few reasons I like to stay with calculator method. If I write a clearance plane into a program of say Z5 and forget the decimal then in conventional method is Z.0005. That’s a pretty low clearance plane for clearing parts.

    I am sure once you are use to it visually it makes sense but when you have X125 it looks like X125. to me. I don’t want to have to look at a number and say ya it has 3 places but I must add a fourth place and visually put in the decimal and say X125 is really X.0125. Calipers, mics, calculators etc all measure using the decimal.

    I also write a lot of macros when setting up a product line and I want to specify things like A=tool number B=# of holes to drill. There is a potential that someone may interpret that #of holes or tool number does not require a decimal. So G65P()A5B10 would try to call T.0005 and drill .001 holes.

    Again it is all preference.

    Stevo

Similar Threads

  1. Simple GCode Reference / Commands?
    By WarrenW in forum G-Code Programing
    Replies: 14
    Last Post: 11-30-2010, 10:03 AM
  2. Write knife grinding program
    By tr4252 in forum Employment Opportunity
    Replies: 17
    Last Post: 03-11-2010, 02:57 AM
  3. How to write a code program to cut threads
    By jjenks in forum NCPlot G-Code editor / backplotter
    Replies: 7
    Last Post: 04-22-2008, 03:18 AM
  4. Possible to write variables to a program?
    By Heavy D in forum G-Code Programing
    Replies: 2
    Last Post: 08-22-2006, 05:08 AM
  5. someone wanna write a program?
    By ljoe1969 in forum DIY CNC Router Table Machines
    Replies: 2
    Last Post: 06-07-2004, 01:47 AM

Posting Permissions

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