Dr Bob
11-13-2009, 05:30 PM
Hi Everyone
I am trying to engrave a ruler with incrament of mm's and I can not figure out how to make a loop that I dont have to repeat the same incrament portion of the ruler over and over in the gcode itself, because I would have to do this about a thousand times.
So is their a code sting that I can put a number in to do an spacific count of times to repeat.
Thanks Dr Bob
CaseyCAM
11-14-2009, 12:57 AM
2 words. "fixture offsets"
so say ur cut move is "Y1." and move over "X.03937" (1mm)
Fixture offset (E1) = X.03937 Y0 Z0
(Tool rpm feed Z depth)
Y1.
E1
Y-1.
E1
Y1.
(Retract, Home etc)
Thats the basic code there for a zig-zag up and down the length of the ruler but your machine should move over the fixture offset amount from where its at every time E1 is called. Not the G54 X, Y and Z.
(careful with using fixture offsets, they can have unpredicted results to new users, Run every tool high 5-10" or so and low rapids)
whitis
11-14-2009, 03:01 AM
You question wasn't very specific, so the answer isn't either. You didn't specify your CNC controller, your computer, your operating system, etc.
Various options:
- Write a program in a real programming language to output G code
- Use loops
- Use conditionals to simulate loops
- Use subroutines
These last few aren't terribly standardized across controllers. One machine might use M94 to call a subroutine and another might use O100. One machine might use O101 for a loop and another might require you to simulate a loop with "IF" statements.
In the case of a program writing a program, you can modify the program to support multiple controllers ideosyncratic g-code. You can also add things like text engraving which many controllers don't do (of course, you will need a vector font and code to handle it).
For a ruler, you probably don't want to make all your lines equal size, so simply repeating an operation 1000 times isn't your best bet. A subroutine
may be more appropriate.
Incremental moves can be used to continue where the last tick mark left off, or you can use absolute moves and a variable, which you offset each time. Or you can move the cordinate space as suggested by previous poster.
This psuedocode shows using subroutines with no loops. Eliminating tencm and replacing onemeter with a loop that calls onecm 100 times would generally be more useful.
onecm()
{
tick();
tick();
tick();
tick();
mediumtick();
tick();
tick();
tick();
tick();
longtick();
}
tencm()
{
onecm();
onecm();
onecm();
onecm();
onecm();
onecm();
onecm();
onecm();
onecm();
onecm();
onecm();
}
onemeter()
{
longtick();
tencm();
tencm();
tencm();
tencm();
tencm();
tencm();
tencm();
tencm();
tencm();
tencm();
}
Of course, this is uglier and machine specific in g-code.
Or a 31 line minimalist C program to generate the g-code. Doesn't do any of the initial setup (feed rates, select metric, etc.), just the repetitive part:
// C language program to draw ruler ticks
// Compile using, for example: cc -lm -oticks ticks.c
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
main()
{
// declare variables
int i;
float ticklength;
float x;
float y;
y=0.0;
for(i=0; i<=1000; i+=1) {
if((i%10)==0) { // i divisible by 10, % is modulo operator
ticklength=6.0;
} else if( (i%5)==0) { // i divisible by 5
ticklength=4.0;
} else {
ticklength=2.0;
}
x=i;
// % is beginning of parameter substitution in format string
// %.3f is a floating point number with 3 digits after decimal point
// \n is a newline (carriage return/line feed)
printf("G01 X%.3f Y%.3f\n", x, y);
printf("G01 Z%.3f\n", -0.1);
printf("G01 X%.3f Y%.3f\n", x, y-ticklength);
printf("G01 Z%.3f\n", 1.0); // traverse height
}
}
This generates 4004 lines of g-code. Replacing the printf() calls for each line of G01 with a subroutine that does the printing allows you to adjust for different formatting for different controllers (some need different number of decimals or omitted decimal point, etc.).
Another approach is to use a CAD package (even a free 2D one will work), and a gcode converter. Or CAM software.
Dr Bob
11-14-2009, 06:04 AM
Ok sorry, I am useing the hass tool room mill, so it is useing basic fanuc gcode, straight user input on the controller pendon.
I have writen the main program of 4 - 1mm line marks and the 5th taller 5mm line mark as a set for the first program to be repeated with the G98 call of the sub program to repeat the main program # amount of times. I wanted to use the L code in the subprogram but I couldn't figure how to get it to work, so I that is what I am looking for. I am not even sure if it will let me use the L code outside a canned program like drilling multipal hole in a row. All I know is the basic Gcode user input nothing fancy.
Hope this helps.
Dr Bob
Sorry for any confusion whitis and caseycam, caceycam has used the more familuar code to me, not familuar with your codeing whitis.
Thanks for helping
HuFlungDung
11-14-2009, 07:26 AM
The L word is part of the sub program call
M98 P100 L10
One precaution in this type of work is the problem of accumulating errors. A small rounding error occurs in each position when commanded in inches, so if you don't correct at the beginning of each loop, then you just made yourself a trick ruler :D
Presumably it is a simple thing to switch your Haas over to metric (if you haven't already) as this problem will likely just go away.
Dr Bob
11-14-2009, 08:57 AM
I am not trying to manipulate a canned program, I am trying to figure out how to write the sub prog. to repeat the main prog. to a user spec. no of times.
Switcher
11-14-2009, 09:50 AM
I think this is what you want?
http://www.practicalmachinist.com/vb/showthread.php/fanuc-21t-program-repeat-165480.html
Dr Bob
11-14-2009, 12:08 PM
Thanks Switcher
I will give this a try on Mon
Switcher
11-14-2009, 01:16 PM
Thanks Switcher
I will give this a try on Mon
I don't run Fanuc, I run Siemens 840D. I just found the link & from the comments looks like what you might need.
I always like Siemens, for running a sub-program n-times I just code a FOR-ENDFOR right inside the g-code, so easy :)
havstruten
12-03-2009, 01:39 PM
Maybe something like this will do
;Start of program
DEF INT MYPARAMETER
;Your lines of code
MYPROGRAM_:
MYPARAMETER=0
;Section you want to loop
MYPARAMETER=MYPARAMETER+1
IF MYPARAMETER==1000
GOTOF NEXT_
END IF
GOTOB MYPROGRAM_
NEXT_:
;Yor program continues