CNC Machining - How to hand write a CNC lathe program using G & M Code.
CNC Machining is what we do. We are Experts and on this channel we are bringing our knowledge and experience to YOU. Want more? Learn CAD, CAM & CNC Machining through our FREE TITANS of CNC: Academy.
What's up everyone this is Tyson at Titans of CNC. Today I'm going to walk you through how to hand
program on a lathe. Before we get started, I'd like to invite you to subscribe to our channel.
We've got plenty more videos coming. Like this video and feel free to leave comments. We'll get
to you if you have any questions. So on our YouTube channel, my dad has a really good video on how to
program on a mill. If you haven't seen it already, check it out. Following his video, I thought it'd
be a good idea to show you guys how to hand program on a lathe. We'll do a simple face and turning
cycle. It's a really basic cycle, but I'll walk you through step by step. I'm actually running a
job on this machine. It's out of a plastic called Peak. I don't want to break this machine down, so
we're just going to program right in here. I'm going to make sure that it doesn't get in the way
of the job. The speeds and feeds for this material you can use on plastics or aluminum, whichever one
you want. Let's get started. I'm going to walk you through this. So the first thing I'm going to do
is I'm going to make a fresh program. We're going to go to edit, F1 to bring up the menu. I'm going
push right until I get to the program menu, and we're going to hit create new program. It's asking
me right now to enter the program O code. If you've seen my dad's video, you know that we have to give
our program a five-digit number after the O code. So I'm just going to give it a little generic one,
two, three, four, five. So O, one, two, three, four, five, and then we're going to hit enter.
I got my new program made. First thing I'm going to do is I'm going to actually name my program,
give it something so that it shows up on this list here. Anything that isn't a G or an M code,
you have to put in parentheses so it doesn't get mixed in with the actual program.
So I'm going to hit parentheses, and I'm just going to type in the name of my program.
So I'll just do face and turn, end of parentheses, and then I'm going to hit insert. Adds that in.
I'm going to get my cursor to the end of the block here. I'm going to hit the end of block
button a few times. Hit insert. It gives me some space so everything's not bunched up together.
So usually at the top of my program, I like to leave some comments for whoever's running this
machine. I'll put stuff like the company name. I'll put those all in parentheses. I'll put things
like what company this job is for. For the next line, I like to type in setup information, things
that the operator of the program can reference at the top of the program. So I'm going to type in
my material size. We're going to go 1.375 peak. That's the name of the material I'm running. It's
a type of plastic. End of parentheses, end of block, and then I'm going to hit insert, and there we go.
I also like to put my initials here along with a date, and that way whoever's running this machine
knows who programmed it or if it's been edited. If someone's edited my program, they put their
initials there and they put an updated date, and that way there's no question that we're running
the most recent program. Once I've got all my info there, I'll give the program a couple of
end blocks here and give myself some more space, and then we're going to start the actual program
from this point. So we're going to start off with a basic program. It's just going to face down the
front of the part, and it's just going to do one pass across the OD. Doesn't seem like it's a whole
lot, but it's a basic program. You can of course add on to it and make more passes, but I'm just
going to show you one face pass, one turn pass, and just the little things at the beginning and the end
of the program you need, and you can get started hand programming. The first thing I'm going to do
is I'm going to give it an end number here with the number of my tool. All this end number is
is a marker so that when I need to find a certain tool in the program, I just search for it. N1
brings me to tool 1, N2 will bring me to tool 2, and that way I'm not spending a lot of time trying
to find a certain tool. So N1, and then in parentheses right after the end, I'm going to give
it my tool name. So this tool, I'm going to go 0156 Radius OD Rougher, end parentheses, and I'm going
to put an end block here. We're going to insert that. So you can see I put an index number here.
That just tells the operator what tool number this is. It's not actually part of the program,
and then I have a tool label there so you can easily find your first tool and what it does.
Next thing we're going to do is our first tool, T101, tool 1, offset 1,
I'm going to put an end of line block, and we're going to hit insert.
This is going to tell the machine to index to tool 1 and use the first offset on that tool.
Now we're going to do our first g-code. If you've seen my dad's video, he explains
g-codes and m-codes. Usually your g-codes are all movement or offset based settings,
g0 is rapid, g1 is feeding, and then usually your m-codes are all optional or machine settings.
Things like turning on the cooling, bringing up the part catcher, unclamping the chuck,
those will be m-codes. So I'll type in our first g-code. We're going to go g54, end of line block,
insert. Usually I use g54 for the main work offset. Usually I'll use g55 if I'm flipping
around the part and using a different starting z. And then sometimes for setups or cutting jaws,
I might use g59 just because that's an offset that's way out of the way and has nothing to do
with my current setup. But for all the main things, and probably for 90% of the time,
you'll be using g54. The next line we're putting in, g18. This is selecting my x and z coordinate
system. I usually specify it on this machine because this is a live tooling machine. Sometimes
it uses different coordinates like x and y. So I usually tell my tools on this machine,
but it might be a good idea to have on other machines. So I'm doing g18, end of line block,
we'll hit insert. Now it's using x and z. And I'll put in one more g-line here,
g99. And that's going to tell the machine to use inches per revolution. Again, it's a live tooling
machine. Sometimes I switch around to inches per minute. So just to make sure that this program
doesn't get mixed up with any other tools or whatnot that I've got going on in here, I'll tell
it, use that work offset, use these coordinates and use inches per revolution. And now it matches
up with the rest of my lathe programs. I'm going to put the next line of code here. We're going to
go g97, s2500, and m3. So g97, that's going to spin the spindle to whatever rpm I tell in the
s number here. So it's going to spin it at 2500 rpm. And m3 is what direction the spindle is
spinning. So m3 is clockwise, m4 would be counterclockwise. With how this machine is set up
and using right-handed tools, you're going to be using m3 most of the time. So I'm going to start
that, hit insert. We've got our spindle spinning. I'm going to make our first move in the program,
g0. That's your rapid move. I'm going to bring it down to x. And I'm going to bring it down
in front of the part and a little bit above the part. So I'm going to go 100 thousandths bigger
than what the diameter of this material is. So we're going to go x 1 inch 475. It's going to be
a rough face cut. So I'm going to go z 0.005. So x 1.475, 100 thousandths above 1 inch 375,
which is our diameter size. And then z 0.005, that's going to bring this tool
five thousandths away from z 0, which would be the finish z.
I'm going to add our end of block here, and we're going to hit insert.
In a normal program, I'd also add an m8 to the end of this line here,
and that would start my coolant. But because we're filming this, and I know that this is a
plastic part that can handle not having coolant, I'm going to leave that out. I've got our tool
rapid to position. So the next line I'm going to add is a g 50. And this is a spindle limit.
What this line tells it is that the RPM can't go past this number that I'm going to specify as an
s number here. So I'm going to say s 3600 and hit end of line block here. The next line of code I'm
going to add is a g 96, which is surface footage per minute. When you go down to center line using
SFM, your machine speeds up. So I need to set a limit there so that the machine doesn't go crazy
when it's going down to the center. So that said, next line we're going to do is g 96.
We're setting our machine to SFM. I'm going to set it to 1000 SFM, and I'm gonna hit end of
line block here. You might be wondering why I'm putting a g 96 when I've already got a g 97 earlier
in my program. It's because I like to get my machine spinning at a close speed to what that
g 96 number would be when it's at this position. Because if I set it early in the program, it's
just going to be spinning really slow because that tool is away from center line. So I usually give
it a close speed to what it'll be as if it was in position. Set that to g 97, and then when my tool
is in position right before it's ready to cut, I'll give it the g 96 number. And then there's
1000 SFM. It'll be nothing in plastic. It'll work fine in aluminum too. Now that we have our tool
in position, spindle is spinning where we want it, we'll do our very first feed number. We're going
to type in g 01. We're going to be a feed command. We're going to go to x negative point zero three
one, and then I'm going to give it a feed command, and I'm going to type in our inches per revolution
that I want to run our feed rate at. So I'm going to go feed rate of 12 thousandths. End of line,
and we're going to hit insert. So we got our face pass. You might be wondering why I'm not
programming to x zero because I'm going straight down. I'm actually going a little bit further to
x negative point 31 thousandths. The reason for that is because my tool, if you look at my setup
here, it's got a 15 thousandths radius. If I just went to x zero because of that radius, it wouldn't
quite be on the center of the part. I actually have to go down a little bit and compensate for
the radius. So a good rule is when you want to face to your center of your part, go down twice
as much as what your radius is. So double that number and give it a negative version of that
as your x here, and that'll take it straight to center line. So we face the center line. Now I'm
going to back the tool off a hundred thou. When you have an OD that you're cutting, negative moves
will always cut into the part and positive moves will back off the part. I did our face pass. I
want this tool to back off the part. So now I'm going to go in z and I want to back this tool off
a hundred thou. So I'm going to go positive z one hundred and five thousandths. End of line block,
insert. So it went to z five thousandths, fed down the front of the part. Now it's feeding off of the
part a hundred thou, so it's going to z 105. And now that it's away from the part, I'm going to
get the tool into position to turn across the OD of the part now. So I know I'm away from the part
now. We're going to go g zero, a rapid move, and I'm going to bring the x to whatever x I want to
do my first cut at. So because I'm going to give this part a 25 thousandths radius, this starting
x number is going to be a little bit tricky. So I need to give this machine the starting position of
my radius and x. If you have a radius, you have a starting point here, and then you have your actual
radius arc, and then it's turning straight across the rest of the OD. So to find that starting point,
you take your finished OD size for your radius. So in this case, it's going to be 1.25, and that's
the diameter that the radius ends up being after it's made. And then I'm going to subtract it by
what my radius is, plus the radius of the tool. I have a 15 thousandths and six tenths radius on my
tool. I'm going to add that to the 25 thousandths radius that I want to make. You're going to put
together 25 thousandths and 15 and six tenths. That's going to give you 0.0406, and then I'm
going to subtract it. So 1.25, and then because this is a diameter, we're going to subtract it
one more time. So minus 0.0406 equals x 1.1688. End of line block. Insert. If that seems a little bit
confusing, it might make more sense in the next couple lines I'm going to add here. But just know
if I add the radius that I want to make, plus the radius of my tool, if I add that two times to this
number, it'll give me 1.25. So now I've got my pre-starting point for the radius. We're going to
feed into the part now in Z and match up to where we face the part. So we're going to go G01, feed
command. I'm going to put Z positive 0.005, and that matches up with the Z that we had earlier
when we faced down for the front of the part. And I'm going to put end of line block. I don't need
to put a feed rate on this line because I have a feed rate earlier in the program. So as long as my
feed rate hasn't changed, I don't need to keep telling my G1's feed rates. So I can insert my
line here, and we have our Z movement to the front of our part. So now we're going to actually put
the radius into the part. We're going to put a G3. A G3 on an OD tool, that's usually going to give
you an OD radius. You use a G2 for an ID radius. We're going to put the finish X diameter for our
radius, so X 1.25. Then we're going to put our Z move, so how far the radius is going in Z.
So I'm going to put a Z negative, so Z minus point. And then I brought this number up earlier.
We're going to see it on the next move that I'm going to make. But I'm going to take the radius,
what radius size I want to make. So I want a 25 thousandth radius,
0.025, plus the corner radius of my tool, 0.0156. That gives you 0.0406.
But then I'm going to subtract from this number the five thousandths that I'm leaving on the part
because this is a rough part. And the number I'm going to put into my Z here is going to be
0.0356. And it's a negative Z. Right after the Z, I'm also going to give it an R,
and that's going to actually be my radius number here. And same thing for the R, it's going to be
radius plus the tool radius. So on this R, we're going to put 0.0406. That's our tool radius,
plus the radius that I want to make. So a 0.025 radius. End of line. Insert.
So you can see that R number is the same as the Z move because it's at the front of the radius.
We just added five thousandths to it because we were off the part five thousandths. And there we
go. We swung a 0.025 radius on the front of the part. The very next line, we want to feed across
the top of the part now. It's very important to put a G1 after your G3 because you're no longer
in radius mode. Sometimes it's easy to forget to put a G1 after this radius move, and it'll give
you alarms saying you can't do that because you're trying to make another radius. So we're going to
put a G1, and we're going to feed across the part now in Z. So we're going to go Z minus 1.1. I'm
going to feed across the part an inch and 100 thousandths. End of line block. Again, we're
using the same feed so we don't have to put another feed rate. Hit insert. There we go. We
turned across the part. The program is pretty much done at this point. So now I want to back off the
part and get my tool a safe distance away before I home it. I'm actually going to give it the same
X number that I started the program off in. I'm not going to put a G1 because we're still feeding
using the previous feed motion. I'm just going to put an X 1.475. This is going to feed up to
one inch 475. Bigger than my starting diameter away from the material. Put an end of line block
and hit insert. Now that it's away from there, I'm going to bring it a safe distance away in Z.
We're going to go G0. We're going to rapid Z positive 100 thousandths. End of line block.
This is bringing my tool to the front of the part away from all my turn surfaces.
And now that I know my tool is away from my part and away from my chuck,
I'm going to start homing it out. We're going to go G28. That's your home command. Return to
your machine zero. And I'm going to go U0.W0. End of line block. So G28, we're homing the machine.
U0. That's telling the machine to home the machine in X. The U corresponds with X.
Same thing with W. We're homing the machine in Z. Going to Z0. So this is going to take the tool
and it's going to go all the way to the back of the machine to what my machine says when it homes
out the machine. And now the very last thing. I'm going to put an M30 at the end of the program
and that tells the machine that the program's ended and to reset the cursor and bring it to
the start of the program. And there we go. We got a full program. A simple face pass.
We did a little corner break at the start of the program and we turned across the OD of the part.
Let's run the program in graphics and we'll actually cut the material here.
So there we go. I walked you through how to hand program. This is going to be the first in many
videos on different examples of how to hand program. So hopefully I'll be able to walk
you through things like making drill passes, tapping cycles, ID passes. If there's something
you want to see programmed or want to learn how to program, feel free to leave a comment and
maybe we can make that happen. So thanks for watching and see you next time.