Back when I was trying to figure out what I needed to know to build and use a homemade CNC Router, I was overwhelmed with all the information I was staring at. At that time I thought I would make some notes on what G-Code was and how it was used, but like many things, it fell to the wayside because there was another piece of the puzzle to figure out. As a result it was left horribly incomplete and not really much use to anyone. So I thought I would revisit the subject and see if I can elaborate on it any more.
I have to give you a disclaimer here. I don't know all that much about G-Code, but will share what I have figured out with you. I am only human so I am sure that everything I tell you may not be totally correct but I will do my best to make it so. If you find an error and want to share your correction with me, please email me and I will update the pages.
What is G-Code
One definition I found on the Internet from 'Wikpedia' is: G-code is a common name for the programming language drive NC and CNC machine tools. It was developed by EIA in the early 1960s, a final revision was approved in February 1980 as RS274D.
Well, that was really helpful! G-Code it seems is a language used to program machines. The Machine it turns out can be anything really, like a lathe, a robot like a line picker, or a CNC Router. The language as it was initially written was supposed to follow a strict set of rules or standards, These standards were the RS274D. These standards defines what each code would do. For example a G01 would be a linear feed and that sort of thing. Now that we know, at least rudimentary, what G-Code is, what does it look like and how do you write it?
Before we get too deep into this discussion, I would like to point out a couple of tools you can get to help you along the way.
1st - You will need something to write your G-Code with. Any simple editor will work, for example Notepad, Notepad++ or wordpad for windows. The important thing is that you do not want any formatting information embedded in the document, so Office would be a bad decision. I mentioned wordpad but be sure to save your code as text only. Any formatting information embedded in your G-Code will break it and make it unusable. For Windows users there is an application called Auto Edit NC that you can use to write your G-Code. You can get a copy of Auto Edit NC by clicking this link. Also, a tutorial on using Auto Edit NC can be found at this site. There may be others. Google is your friend here. For Linux users I you can use GEdit or any other text editor of your choice. Again the important thing to remember is that you want only plain text and no formatting information embedded in the document.
2nd - It would be nice if there were an application that you could use to visualize the G-Code paths as they are being run. There are a few applications that will do this for you. In Linux you can use LinuxCNC (Formally known as EMC2) LinuxCNC can be installed in simulator mode. You can find information on doing this at the LinuxCNC Wiki - LinuxCNC Pure Simulator pages. For the Windows users out there, there are a couple of options that come to mind. The first is CutViewer and a 30 day free trial can be downloaded from tahlinc.com. Another option for Windows users is CNCSimulator from cncsimulator.com. As far as I know this is a free program. Again, there probably are more solutions available. Google may be helpful here. If you find one, use the CONTACT US menu option above and send us a link and I will include it here.
OK, before we start our discussion about G Code we need to come to some common ground. The reason why I say this is because it seems that everything about these machines is relative to something else. So, if we are on the same page about a few things the information I am trying to convey will be much easier to understand.
Axis Names and Direction
It seems that there is a bit of controversy about the name of a particular axis and the direction it travels. I think both sides of the argument have their merits but like every other obstinate fool out there I have my opinion too. Since this is my website and my opinion, I will be going with mine, but will touch on both sides of the issue.
The first thing to discuss is the naming of the axis. I will be using the right hand rule. Now if you do a Google image search on the right hand rule, you will see several different images expressing it and it still is a little confusing. But using the image at the left, I use the right hand rule as follows. Extend your right hand in front of you with your palm facing up and your fingers extended away from your body. Now point your thumb to the right, your index finger forward and your middle finger straight up. Curl your ring and pinky fingers into your palm. Now, as you look at your hand your thumb is the X-Axis, your index finger is the Y-Axis and your middle finger is the Z-Axis and they are point to the positive direction. Now most people will agree with that representation. The controversy starts when assigning axis to the machine itself. I think most people will call the axis holding the spindle (router) the Z-Axis. However, the X and Y axis becomes a debate. Peter Smid, the author of the CNC handbook says the X-Axis should be the longest of these two axis. Others think that the X-Axis is the axis you are facing as you face the machine during operation. Now this may be improper, but it makes it easy to visualize the coordinates as you look at the machine. It simply becomes a Cartesian coordinate system like you were used to in high school algebra with the Z-Axis moving up and down.
Some thoughts before moving on
There are a couple of things to remember about G-Code. First, it is a programming language first and foremost, so if you are familiar with computer programming of the BASIC slant you should have very little problem getting the syntax of G-Code down and working. For those of you who have never programmed, don't fret, the B in BASIC means beginner so it shouldn't take much to wrap your head around the concepts. Second, there are terms like relative and actual positions, offsets, preparatory command and a bunch of other stuff that comes to mind when writing G-Code. We will cover these as we get to them. With that, lets move on to the next part of the tutorial, making the machine move.