Linear Feeds

Welcome back.  So far we have learned about program numbers with the N code, comments with the ;, ( and ), rapid motion with the G0 command and finally setting the units with the G20 and G21 commands.  These are fine and dandy if you just like moving the machine around and watching.  However, we need it to do some work for is.  The most basic type of motion for a CNC router would be linear feeds.  This will allow us to cut straight lines.  Before we can do that, we need to learn a little more preparatory commands to make that possible.  So let's get started.

Selecting a Tool

At this stage of the game, I am guessing you are using an emulator of some sort to test your G-Code.  But we will proceed like we are actually going to make a real cut in something.

So in order to cut something the machine needs to know what tool it is using.  Some machines have an automatic tool changer while other machines you have to make the tool change yourself.  Not knowing Mach3, I will talk about how LinuxCNC works.  My home made JGRO CNC Router does not have a tool changer so obviously all the tool changes I make are by hand and when the code does a tool change, I get a dialog that tells me to insert toll number such and such.  This gives me the opportunity to get the tool in the router and continue.  LinuxCNC knows that I do not have a tool changer so does this for me.  If I had a machine with an automatic tool changer then LinuxCNC can be configured to use it.  The moral of the story is see what your controller does.

When we write G-Code or even use a CAM package to generate it, we derive our tool paths based on a particular tool.  These tools are stored in a table in the controller and if you have an automatic tool changer, it will be assigned to a particular slot.  For example, on my machine I have the tool table set to something like:

  • T1 - 1/4" flat end mill
  • T2 - 1/8" flat end mill
  • T3 - 1/4" ball mill
  • T4 - 1/8" ball mill
  • T5 - 1/2" 90° V Bit
  • T6 - 1/4" 60° V Bit
  • ...

You get the idea.  To select a tool using G-Code requires two steps.  1) Selecting the tool and 2) issuing a tool change command.  Selecting the tool is really simple, you use the T word with the tool number that you wish to use.  So looking at my list of tools above, if I wanted to make a cut with the 1/4" Ball Mill I would issue the command T3 in my G-Code.  This lets the controller know that when we make a request for a tool change, then that is the tool to go get.  Finally, making the tool change is very simple as well.  Simply issue the tool change command of M6.  When the controller sees the M6 command it knows to change the tool if you have an automatic tool changer and if you don't, LinuxCNC pops up a dialog asking you to load Tool # 6 into the machine.  Pretty easy.  There are other things to talk about tools, but we will discuss them later.  For now we are only worried about enough information to make a simple cut.

Controlling the Spindle

The spindle as you know holds the tool that you are cutting with.  The spindle on my JGRO CNC Router is a Hitachi router.  Bigger and better machines have a real spindle.  The spindle can be controlled by certain codes in your program.  They are pretty straight forward.  To start the spindle you will give either a M3 or M4 command followed by an S### command to tell it the speed. The M3 command will turn on the spindle in the clockwise direction at S### speed.  The M4 command will start the spindle in the counter clockwise direction at S### speed.  As mentioned earlier, the speed of the spindle is controlled by the S word followed by the speed at which you wish to run it.  If I wanted the spindle to run at 1,000 rpm, I would use S1000, if I wanted 25000 rpm, I would use S25000.  Now in reality, on my JGRO CNC Router it does not matter because I do not have the ability to turn on the router or control the speed with the controller.  Many people will install a solid state relay so that the M3 or M4 command actually does turn on the router.  I place these commands in my G-Code, but I manually turn on my router and set the speed with the dial located on the router.  So to turn on the spindle in the clockwise direction at 3000 rpm, I would use the command M3 S3000.  Finally, when I am done I need to turn the spindle off.  To do this we use the M5 command.  When the controller sees this command it will shut down the spindle if your spindle is controlled by the controller.

Controlling the Coolant

When you cut metal and other hard materials you have to have some sort of coolant running to keep the bits cool or you will just dull and burn them up and probably break them as well.  In my case, routing wood with a router there is no need for coolant.  But let's pretend we are on a real milling machine and we need to mill a slot in a piece of steel.  We have to keep it cool.  These machines are equiped with pumps that will either spray of flood the work area with coolant.  This coolant pump can be controlled with your G-Code by issuing the following commands. M7 will turn mist on.  M8 will turn flood on and M9 turns all coolant off.  So back to milling our slot, to turn on the coolant so that it floods the work we would issue the M8 command.  At the end of the job to shut the coolant flow off, we issue the M9 command.

Setting the Feedrate

The last item to cover before we can actually do the linear feed is talk about the feed rate at which it will run.  Feed rates are dependant on a lot of things.  The machine rigidity, the desired surface finish, the amount of material being removed, flute loading and more.  Determining feed rates can be more of an art than a science.  Setting the feed rate in your G-Code program is done with the F command followed by the desired feed rate.  Feed rate for a mill will depend on what units of measure you are in.  It will be either Inches per minute if in inch mode using the G20 command or millimeter per minute if you are in mm mode using G21.  So, if I were cutting a profile on my JGRO CNC Router, I may set it to something like 15 inches per minute.  Why so low, well more than that I get flex causing dimensional errors in the final part.  To set this feed rate in G-Code I would write F15.

Linear movement

We are nearing the point that we can write some G-Code.  The next item is the actual command that makes the machine do a linear move.  The command for this is G1.  This is a modal command meaning that it stays in effect until it is changed by another command such as G0 (Rapid move).  When G1 is issued the machine will use the feed rate from above.  When more than one axis is given both axis are moved so that the meet at the destination at the same time.  So if the tool was at the origin of X0 Y0 and the feed rate was set at F15, the I issued the command G1 X1 Y2 the tool will move from the origin to X1 Y2 as a straight line at 15 inches per minute.

Putting it all together

Let's say we have a job to cut a groove in an aluminum block.  The block is 2 inches on each side and .500 inches tall.  The bottom left corner of the block is sitting on X1 Y1.  We want to cut a groove .250 inches wide and .125 inches deep across the middle of the block from X1 Y2 to X3 Y2.  For this job we will use a .25 inch carbide 2 flute end mill.  Going to a calculator the spindle speed should be about 13000 rpm and the feed rate should be about 50 inches per minute.  Let us assume that the tool is at the origin X0 Y0 and 2 inches above the surface of the block.  Also we have set the Z origin to the surface of the aluminum block.  Let's write a program to make the groove for us.

(Cut a .125 deep .250 wide groove across a 2 inch block)
G20 ;Put the machine in inches T1 M6 ;Select the 1/4" end mill and change the tool F50 ;Set the feed rate to 50 Inches per minute M3 S13000 ;Turn the spindle on clockwise as run it at 13,000 RPM G0 X.5 Y2 Z-.125 ;Rapid the tool to the left of the block at .125 inch deep M8 ;Turn the coolant on flood G1 X2.5 ;Make the cut across the block G0 Z2 ;Bring the Z-Axis back to a safe height G0 X0 Y0 ;Bring the tool back to the origin M9 ;Turn the coolant off M5 ;Turn the spindle off M30 ;End of program

I have commented each line of the code.  Reading through it will tell you exactly what each line does.  There are two things to notice here.  First, I did not use line numbers.  Remember, I said they were optional. And second, you will notice that I threw a new G-Code at the end of the program.  To signify to the machine the the program has completed we use the M30 code meaning end of program.  This technically rewinds the program to the beginning.  If we were to remove the block we just cut and fastened another on in its place we could hit the cycle button on the controller and it would run again from the beginning.

The next installment we will cover Arc Feeds and cut a circle!  See you then.