Home     Contact     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS     Terms of services     Privacy policy  
 Home     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science   

Author Topic: CNC machines - G-Codes and M-codes in a glance - Drawing lines using G1  (Read 5137 times)

0 Members and 1 Guest are viewing this topic.


  • Guest
Well, here it goes, my first post for CNC.

CNC actually means Computer Numerical Control. It is the evolution of the NC machine (numerical control) which is the same thing but more modern, operated by computer.

Numerical control means that you "tell" the machine to go somewhere on the grid, and it goes. How this is done i may explain in another post. Right now, i will tell you the language that you have to learn in order to "talk" to the machine.

This language, as every computer language, has commands and syntax. It is the way that you will ask an axis of the machine to go to a place and execute something. Let’s suppose that we are talking about a CNC router with 3 axis, X Y and Z. If you hold a pen over a paper, then X would be the position of the pen on the long side of the paper, Y would be the position of the pen on the short side of the paper, and Z would be de distance that the pen stands over the paper. Pretty simple. Now, suppose that you want to draw a line on this paper. The line should start from X=10 Y=20 and would end to X=10 Y=180. The points are spelled:

From 10 20 to 10 180

First we tell of the X position and then of the Y. Later we will talk about Z.
The position 10 20 is located 10mm from the zero-point on X axis and 20mm from the zero position of the Y axis. As you understand, our machine understands by default all values as millimetres, but this may change from configuration to configuration. The command should be:

N1 G0 X10 Y20 Z30
N2 G1 Z0 F10
N3 G1 X10 Y180 F20
N4 G0 Z30
N5 G0 X0 Y0

Let’s take a closer look. N means line number and is followed by a number, the line number. So N1 means line number 1, N2 line number 2 etc. This is an optional declaration on the code that you may or may not enter. It is mandatory on GOTO commands that they refer to a program control jump to a line number and thus this line should be declared.

Line 1: N1 G0 X10 Y20 Z30
G0 means Rapid positioning of machine. So, in line 1, the machine will go to X10mm, Y20mm and the pen will have 30mm distance from the paper. Nothing is drown so far. The speed (feedrate) of positioning is the default “RAPID” feedrate value on the controller and is mostly measured in meters per minute.

Line 2: N2 G1 Z0 F10
G1 is the definition of Feedrate positioning. The machine will move to the declared position not with default speed, but with the speed declared by parameter “F”. So in line 1, the machine will go downwards to Z0 with feedrate of 10 meters per minute. The pen will touch the paper. Note that if an axis position is not declared on the command (like here there is no X or Y position) then this axis will not move at all and will remain at the previous position.

Line 3: N3 G1 X10 Y180 F20
In line 3 the machine will move to X=10mm, Y=180mm with feedrate 20mt/min. The pen will draw a line as it was in contact with the paper from the previous command.

Line 4: N4 G0 Z30
The Z axis will raise back to 30mm above the paper with default “RAPID” feedrate

Line 5: N5 G0 X0 Y0
The machine will move to position “zero” (as is usually called when refer to point X=0 and Y=0) with default “RAPID” feedrate

I think this is pretty easy to understand the philosophy of CNC motion. You may find attached a G and M - code list for lathe and mill machines. You may also find p1.jpg that shows the result from the previous code.
« Last Edit: August 23, 2008, 17:42:29 PM by stamatis »