CNCzone.com-The Largest Machinist Community on the net!



Home Page Mark Forums Read Today's Posts My Replies Classifieds Reviews Photo Gallery Web Links Share Files Advertise With Us Ad List
Go Back   CNCzone.com-The Largest Machinist Community on the net! > MetalWorking Machines > General Metal Working Machines


General Metal Working Machines General discussions of all metal working machines from drill presses to band-saws.


This forum is sponsored by:

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Ban this user!
Old 11-13-2009, 06:30 PM
 
Join Date: Nov 2009
Location: Canada
Posts: 4
Dr Bob is on a distinguished road
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
Tweet this Post!Share on Facebook
Reply With Quote

  #2   Ban this user!
Old 11-14-2009, 01:57 AM
CaseyCAM's Avatar  
Join Date: Jun 2008
Location: So. California, USA
Age: 27
Posts: 27
CaseyCAM is on a distinguished road
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)
Tweet this Post!Share on Facebook
Reply With Quote

  #3   Ban this user!
Old 11-14-2009, 04:01 AM
 
Join Date: Jul 2009
Location: USA
Posts: 12
whitis is on a distinguished road
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.
Tweet this Post!Share on Facebook
Reply With Quote

  #4   Ban this user!
Old 11-14-2009, 07:04 AM
 
Join Date: Nov 2009
Location: Canada
Posts: 4
Dr Bob is on a distinguished road
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
Tweet this Post!Share on Facebook
Reply With Quote

  #5  
Old 11-14-2009, 08:26 AM
HuFlungDung's Avatar
Moderator
 
Join Date: Mar 2003
Location: Canada
Posts: 4,823
HuFlungDung is on a distinguished road
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)

Last edited by HuFlungDung; 11-14-2009 at 10:37 AM. Reason: typo fixed
Tweet this Post!Share on Facebook
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 11-14-2009, 09:57 AM
 
Join Date: Nov 2009
Location: Canada
Posts: 4
Dr Bob is on a distinguished road
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.
Tweet this Post!Share on Facebook
Reply With Quote

  #7  
Old 11-14-2009, 10:50 AM
Switcher's Avatar
Moderator
 
Join Date: Apr 2005
Location: Vectorink.com
Posts: 3,659
Blog Entries: 2
Switcher is on a distinguished road
I think this is what you want?

http://www.cnczone.com/vb...at-165480.html
__________________
Free DXF Files - Vectorink.com - myDXF.blogspot.com
Tweet this Post!Share on Facebook
Reply With Quote

  #8   Ban this user!
Old 11-14-2009, 01:08 PM
 
Join Date: Nov 2009
Location: Canada
Posts: 4
Dr Bob is on a distinguished road
Thanks Switcher
I will give this a try on Mon
Tweet this Post!Share on Facebook
Reply With Quote

  #9  
Old 11-14-2009, 02:16 PM
Switcher's Avatar
Moderator
 
Join Date: Apr 2005
Location: Vectorink.com
Posts: 3,659
Blog Entries: 2
Switcher is on a distinguished road
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 Files - Vectorink.com - myDXF.blogspot.com
Tweet this Post!Share on Facebook
Reply With Quote

  #10   Ban this user!
Old 12-03-2009, 02:39 PM
 
Join Date: Dec 2009
Location: Sweden
Posts: 1
havstruten is on a distinguished road
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
Tweet this Post!Share on Facebook
Reply With Quote

Sponsored Links
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
G-code by PMTurn Problem dgoddard Dolphin CADCAM 1 05-20-2009 10:27 PM
G-code output problem NewToGibbs Post Processor Files 8 01-31-2009 12:20 AM
Problem with code G0 harm190 Mach Mill 3 03-17-2008 04:13 AM
g code problem SIMONSIGNS Kellyware CAM 7 03-22-2007 11:46 AM
g code problem chrisw765 Fadal 11 04-26-2006 11:13 PM




All times are GMT -5. The time now is 09:10 AM.





Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO
Template-Modifications by TMS

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353