585,970 active members*
4,157 visitors online*
Register for free
Login
Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2009
    Posts
    4

    G Code Problem

    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

  2. #2
    Join Date
    Jun 2008
    Posts
    27
    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)

  3. #3
    Join Date
    Jul 2009
    Posts
    12
    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.
    Code:
    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:
    Code:
    // 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.

  4. #4
    Join Date
    Nov 2009
    Posts
    4

    More Info

    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

  5. #5
    Join Date
    Mar 2003
    Posts
    4826
    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

    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.
    First you get good, then you get fast. Then grouchiness sets in.

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  6. #6
    Join Date
    Nov 2009
    Posts
    4

    Not Manipulating

    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.

  7. #7
    Join Date
    Apr 2005
    Posts
    3634
    Free DXF - vectorink.com

  8. #8
    Join Date
    Nov 2009
    Posts
    4
    Thanks Switcher
    I will give this a try on Mon

  9. #9
    Join Date
    Apr 2005
    Posts
    3634
    Quote Originally Posted by Dr Bob View Post
    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
    Free DXF - vectorink.com

  10. #10
    Join Date
    Dec 2009
    Posts
    1

    Repeat Section

    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

Similar Threads

  1. G-code by PMTurn Problem
    By dgoddard in forum Dolphin CAD/CAM
    Replies: 1
    Last Post: 05-21-2009, 03:27 AM
  2. Problem with code G0
    By harm190 in forum Mach Mill
    Replies: 3
    Last Post: 03-17-2008, 09:13 AM
  3. g code problem
    By SIMONSIGNS in forum Uncategorised CAM Discussion
    Replies: 7
    Last Post: 03-22-2007, 04:46 PM
  4. g code problem
    By chrisw765 in forum Fadal
    Replies: 11
    Last Post: 04-27-2006, 04:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •