PDA

View Full Version : Repeat g-code with y offset



tpaulson
10-27-2004, 11:40 AM
I have some g-code to mill 2 pockets in a box. The final fixture will have 5 of these pocket pairs with a 2.5" Y offset. That way I can mill 5 boxes at a time. Is there a way to have the g-code I already have repeat 4 more times, offseting the Y 2.5" each time?

I have attached a zip file containing the g-code and the dxf showing all of the pockets.

Thanks
Tim

E-Stop
10-27-2004, 01:27 PM
There are several ways to do this but I think the simplest would be to save your existing program as a subroutine and then call it up after changing the "start" position. Your "start" position, or Y offset, can be changed in your program several ways also. You can use G10 to input the offsets, you can use G52 to shift the offsets or you can set the 5 positions with G54-G59 and call a new offset before running the subroutine. You didn't say what machine or control you are using so check your manuals for the proper way to use the G-codes and subroutines.

tpaulson
10-27-2004, 02:02 PM
E-stop
Thanks for the reply.

I am pretty new to g-code. Could give me a short snippet of code demonstrating one of the methods you suggest?

I am using a gantry style cnc router like this one.
http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&category=3131&item=3847964271&rd=1

I use CNCZeus to control the router.

Thanks
Tim

E-Stop
10-27-2004, 04:05 PM
I'm not at all familiar with the CNCZeus control but here's the way I would do it, if your control accepts the G10 command.

G10G90L2P2X0Y0 <---Sets G55 to X0 Y0
G10G90L2P3X0Y2.5 <---Sets G56 to X0 Y2.5
G10G90L2P4X0Y5.0 <---Sets G57 to X0 Y5.0
G10G90L2P5X0Y7.5 <---Sets G58 to X0 Y7.5
G10G90L2P6X0Y10. <---Sets G59 to X0 Y10.0

The G10 is a command to load or store the offsets
The G90 is for Absolute input.
The L2 designates a fixture offset (as opposed to tool offsets or something else)
The P# designates which fixture offset. P1=G54, P2=G55, ect.
Then the X and Y values are self explanitory.

Then for your program you would call the G55 and run the subprogram (which is the G-code program that you already have. When the first part is done then call G56 and run the subprogram again. And repeat.

%
G0G40G90G17
G10G90L2P2X0Y0
G10G90L2P3X0Y2.5
G10G90L2P4X0Y5.0
G10G90L2P5X0Y7.5
G10G90L2P6X0Y10.0
G0G40G90G55
M98P1234 <<<<<M98 CALLS THE SUBROUTINE; P IS THE PROGRAM NUMBER OF THE SUB.
G0G40G90G56
M98P1234
G0G40G90G57
M98P1234
G0G40G90G58
M98P1234
G0G40G90G59
M98P1234
M30
%

Something like that. You'll have to check you manuals for the correct usage of offsets and subprograms but that's the basic idea behind it. Hope this helps.

tpaulson
10-28-2004, 08:30 AM
E-stop
Thanks!!!!
Your code helped a great deal, I think I understand now.
I didn't get a chance to try it last night. I will let you know if I have any problems.

Tim

Ken_Shea
10-28-2004, 09:43 AM
I thank you as well E-Stop, very informative.

Ken

Swami
10-28-2004, 11:04 AM
I am new to G-Code programming too, and I solved this problem using one of the other techniques E-Stop recommended. "Changing the Start Position" I do this a lot with my code.

Maybe this would help someone, so here is an example of that:

G0 X0 Y0
M98P1000
G0 X0 Y2.5
M98P1000
G0 X0 Y5
M98P1000
G0 X0 Y7.5
M98P1000

Another Possibility would be to put the Y-Offset in the subroutines first line using G91 relative coordinates. (G0 G91 Y2.5) Then you could LOOP the M98 command like this:

M98P1000 L5 -- (Where L10 means loop 5 times)

tpaulson
10-29-2004, 09:07 AM
E-stop
I tried the code you suggested, but it did not offset the X Y locations. It just repeated the subrouting in the same 0, 0 location.

I have not tried Swami suggestion yet.

Is there something I need to change in the sub program to get it to use the offsets?

Here are the first few lines of my subroutines code:

O1234
(Created 8:32:10 AM 10/27/2004 from thum-bl-5fixture-y-rev.dxf)
(Post = ISO G-Code - Non Modal)
(Tool 1 = .125 End)
N0001 T1 M03 S30000
N0003 G00 X3.1125 Y1.3325 Z1.0000
N0005 G00 X3.1125 Y1.3325 Z1.0000
N0007 G01 X3.1125 Y1.3325 Z-0.0600 F20.00
N0009 G01 X3.3375 Y1.3325 Z-0.0600 F15.00
N0011 G01 X3.3375 Y1.7075 Z-0.0600

E-Stop
11-19-2004, 11:29 AM
Sorry so long answering. I've been out and busy for awhile.

Your code for the subroutine looks fine. It's what comes before the subroutine that will change the start position of your pocket. The fixture offsets need to be "loaded" into the G54-G59 fixture offsets and then one of the offsets needs to be "called" before the subroutine is run. When the subroutine is done, call another fixture offset and run the subroutine again.

tpaulson
11-19-2004, 01:29 PM
E-stop
I have the code you suggested beform the start of my subroutine(see below).
I think it my be a problem with CNCZeus not handling the offsets via code correctly.


G10 G90 L2 P2 X0 Y0 (<---Sets G55 to X0 Y0)
G10 G90 L2 P3 X0 Y3 (<---Sets G56 to X0 Y3)
G10 G90 L2 P4 X0 Y5.5
G10 G90 L2 P5 X0 Y8
G10 G90 L2 P6 X0 Y10.5
G0 G40 G90 G55
M98 P1234 (<<<<<M98 CALLS THE SUBROUTINE P IS THE PROGRAM NUMBER OF THE SUB.)
G0 G40 G90 G56
M98 P1234
G0 G40 G90 G57
M98 P1234
G0 G40 G90 G58
M98 P1234
G0 G40 G90 G59
M98 P1234
M30

O1234
(Created 8:32:10 AM 10/27/2004 from thum-bl-5fixture-y-rev.dxf)
(Post = ISO G-Code - Non Modal)
(Tool 1 = .125 End)
N0001 T1 M03 S30000
N0003 G00 X3.1125 Y1.3325 Z1.0100
N0005 G00 X3.1125 Y1.3325 Z1.0100
N0007 G01 X3.1125 Y1.3325 Z-0.0600 F20.00
N0009 G01 X3.3375 Y1.3325 Z-0.0600 F15.00
N0011 G01 X3.3375 Y1.7075 Z-0.0600
N0013 G01 X3.1125 Y1.7075 Z-0.0600
N0015 G01 X3.1125 Y1.3325 Z-0.0600
.....other code
N0045 M5
N0045 M99

cncwhiz
11-19-2004, 07:34 PM
Try removing the "G90" this could be causing the problem. You do not need this to input "G10's" into the work offsets.

E-Stop
11-20-2004, 11:05 AM
Leave the G90. It may be redundant but it is safe. The G90 inputs an absolute value into the offset, G91 an incremental value. So if for some reason the control was in incremental mode as it reads the G10 lines, those values will be added to the values already in the offset. It is correct that the G90 is not needed to input the offsets with G10, I just always feel safer with it there. Operators have a way of making things happen that aren't supposed to so any additional safegaurds in place are a plus.

tpaulson... Do you have an offset page where you can verify that the offsets have loaded correctly? I still can't see any problems with the code itself. Does your control support parametric programming? If so, you could do it with variables. It's not as easy but it works.

cncwhiz
11-22-2004, 10:41 AM
E-Stop,
The line that should be before the "G10's" should contain the "G90" as well as all the other g codes to cancel drilling, cut comp etc. I also like to use a "G49" to make sure that the "G10's" don't double load the work offsets. The "G49" is a pretty important command in this line, however there can be times in setup that if it is read after a tool offset it can result in the tool moving to the "0" offset position. I personally do not put the "G90" in my "G10" line and have my posts built to not output it. I do make sure that it gets called before and after the "G10" lines. I have places in my programs where I use "G91" but I always make sure that the next line has "G90" even if it is a forth axis index move. I agree with the statement about the operators I have built macro's and all kinds of insurance into my programs too keep operators from having problems, but they still from time to time find a way to get in trouble.

rob2424
11-23-2004, 07:08 AM
is the G10 supported in cnc zeus?

tpaulson
11-23-2004, 08:32 AM
is the G10 supported in cnc zeus?

That appears to be the problem. According to CNCZeus support, currently G10 is Not supported.

I guess I will just have to generate the code for each box instead of doing a subprogram. Not a big deal, I just figured there was any easy way to repeat the code with offsets. Which there is, but CNCZeus doesn't support it. I will probably look at using Mach2 sometime in the future, but CNCZeus works well for now.

Thanks again
Tim

Swami
11-23-2004, 08:42 AM
You can still subroutine. Just write the subroutine with all G91 codes. When the subroutine is over, move to a new absolute location (G90) and fire the subroutine again, as often as needed. Does that make sense? You just keep using G90s to get the cutter in your "start" position.

Swami

tpaulson
11-23-2004, 09:14 AM
Swami
I am very new to G code, but I think I understand. The problem is that the software I usually use to create the g-code from dxf doesn't appear to have the ability to generate incremental programming. DeskCNC is the only software I currently have access to that can create pockets.
Is there other software available inexpensive or free that will generate relative g-code for pockets?

Thanks
Tim

cncwhiz
11-23-2004, 10:26 AM
If this is an older fanuc controller 11 or 15, I can give you the option code to turn on the option. think that it is 9102 bit O.

Swami
11-23-2004, 11:09 AM
Oh! No incremental...I understand why you needed to do it with G10 then now....

I dont know of a program that will generate the pocket using G91, but you could manually edit the code most likey.

Assume your machine is at 0,0 (or something else convenient). Program your first pocket You should be able to take that code and just append G91 (or remove G90) codes from what was produced. When you could make that modified code into a subroutine (by putting O1000 to start the block and M99 to end it) Now you should have a block of code that will work from whatever startingpoint you are at prior to calling it.

Example:
G0 G90 X0 Y0
M98P1000

G0 G90 X7 Y0
M981000

Hopefully that can help you out.

I was wondering, if you have a DXF to code generator, why not DXF all the pockets you want to make and let the program write the whole thing? Sheetcam would be very good for that. www.sheetcam.com

Good Luck,
Swami

tpaulson
11-29-2004, 02:36 PM
Swami
Thanks for your help.


I was wondering, if you have a DXF to code generator, why not DXF all the pockets you want to make and let the program write the whole thing? Sheetcam would be very good for that. www.sheetcam.com


I ended up letting the software generate all of the pockets like you mentioned.

The main reasons why I was trying subroutines was:
1. To allow for quick changes of pocket size. Just make the change on one pocket location in the DXF instead of 5.
2. The subroutine method would also complete an entire box before moving to the next box. Having the g-code generater create all pockets, creates code to make the first pocket on all 5 boxes before creating the second pocket on the first box. This is a waste of time if I only need to make one box instead of all 5.
3. Easily change the number of boxes to be machined in a run

Tim