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! > Machine Controllers Software and Solutions > G-Code Programing


G-Code Programing Discuss G-code programing and problems here!


This forum is sponsored by:

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Ban this user!
Old 01-22-2012, 04:30 PM
 
Join Date: Jan 2012
Location: uk
Posts: 3
dinglekiller is on a distinguished road
looping

hi peaple, i've not been programming long and was looking to shorten my progams when i am heilcal milling. i.e machining some soft jaws on the bed of my miller. using fanuc controls.
N10 G17 G3 X5.0 I-5.0 Z-1.0
N20 G3 I-5. Z-2.
N30 G3 I-5. Z-3
and so on.
got a book that says if i progam
N10 G17 G3 X5. I-5. Z-1
N20 G91
=N40/5
N40 I-5. Z-1.
N50 I-5.
not looked into macro's yet trying to get the basics down first.
i'd just like to know if i was on the right path.
bry
Reply With Quote

  #2   Ban this user!
Old 01-22-2012, 05:46 PM
 
Join Date: Mar 2007
Location: Finland
Posts: 19
mystiks is on a distinguished road

G90 is for absolute and G91 is for incremental.

When given new point while using incremental(G91), its from current position, not from zero point (like when using G90)

Havent done much basic milling for while, but if doing deep holes its hard to keep track of the current depth unless you loop it with (WHILE) macros.

But like you said, you want to keep it simple, that works. But id also consider
using subprogram and calling it with repeat.

You'd have the closing on main program, and the helical circle command on subprogram, something like ->

Main:

G0 X5 Y0 Z20
Z2
M98 P100 L10
(P = number of the subprogram)
(L = number of repeats)
G3 I-5
G90
G0 Z10

Subprogram 100:

G91 G3 I-5 Z-1

Whenever using incremental, remember to turn it back to absolute, otherwise crash might happen.

In any case, if i were you, look for M98 command in your manuals, since it might work differently in certain controls.

Aand dont trust my code, like said, rusty.

Whenever you start to mix with G90/G91, G40/G41/G42 you want to have a line on every programs start where it "defaults" these, this includes many other commands but just to advice to be careful with these.
Reply With Quote

  #3   Ban this user!
Old 01-23-2012, 04:22 AM
 
Join Date: Jan 2012
Location: uk
Posts: 3
dinglekiller is on a distinguished road

Thank you for your help, i know about G90/G91. I also use sub programs at times. Just wanted to have a play. Thanks again Bry.
Reply With Quote

  #4   Ban this user!
Old 01-23-2012, 07:52 AM
 
Join Date: Sep 2010
Location: Australia
Posts: 733
angelw is on a distinguished road

Originally Posted by dinglekiller View Post
Thank you for your help, i know about G90/G91. I also use sub programs at times. Just wanted to have a play. Thanks again Bry.
Bry,
You don't state the controller, and I understand that you're not getting into User Macros yet. However, following is a method of looping any profile, and unlike running a Subprogram a number of times, the depth of cut from start point to full depth does not have to be evenly divisible by the depth of each cut. Following is an example using Fanuc User Macro syntax.

#1 = 0 (Z CUT LEVEL)
#2 = 3.0 (Z CUT IN AMOUNT)
#3 = -20.0 (Z FULL DEPTH)
G90 G00 X10.000 Y0.000
G43 Z10.000 H01
G01 Z1.000 F2000
N10 #1 = #1-#2
IF[#1 LT #3] TH #1 = #3
G03 I-10.000 Z#1 F200
IF[#1 GT #3] GOTO 10
............
(PROGRAM CONTINUES HERE ONCE FULL DEPTH HAS BEEN REACHED)
............
............

You will note from the above code example, that if the repeat of a Sub Program method was used, the tool would over cut the depth on the 7th iteration. This method ensures that the tool never goes beyond the programmed full depth.

Regards,

Bill
Reply With Quote

  #5   Ban this user!
Old 01-25-2012, 10:50 PM
 
Join Date: May 2007
Location: USA
Posts: 913
g-codeguy is on a distinguished road

Neat Bill. Can't get any simpler or easier than that.
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 01-26-2012, 04:32 AM
 
Join Date: Jan 2012
Location: uk
Posts: 3
dinglekiller is on a distinguished road

Like I said never looked in to macros and that Bill is abit over my head, Working through a book by Peter Smid at the moment and the next installment is macros. So that should give me a better footing.
Thanks Bry
Reply With Quote

  #7   Ban this user!
Old 01-26-2012, 08:09 AM
 
Join Date: Sep 2010
Location: Australia
Posts: 733
angelw is on a distinguished road

Originally Posted by dinglekiller View Post
Like I said never looked in to macros and that Bill is abit over my head, Working through a book by Peter Smid at the moment and the next installment is macros. So that should give me a better footing.
Thanks Bry
As observed by g-codeguy, the code example in my previous post and following is a simple application of Macro statements, and may only seem daunting to you because, at this stage, you're not aware of the syntax of the User Macro language. However, you will quickly pick this up as you progress through various books on the subject. This is a good example to gain some understanding of Flow associated with the User Macro language; I'll explain how it works in this example.

There are various Types of variables available. You will learn about these in early discussion in just about any manual or book relating to the Macro language. In my example, variables of Type "Local" have been used; these include variables in the range of #1 - #33.

In the following section, the variables used are initialized.
#1 = 0 (Z CUT LEVEL) This is set to the Z start surface. If the machining was to start at Z-5.0mm, then #1 would be initialized to -5.0. Its value is modified as the program Loops and carries out another calculation.

#2 = 3.0 (Z CUT IN AMOUNT) This is the depth of each cut, and is subtracted from #1 to calculate the new absolute Z level. It could also be specified as a minus value, and added to #1 to gain the same result.

#3 = -20.0 (Z FULL DEPTH) This is the full depth in Z of the feature.

G90 G00 X10.000 Y0.000
G43 Z10.000 H01
G01 Z1.000 F2000

N10 #1 = #1-#2 This is where the calculation for the depth of cut is carried out and is the marker of the return for the Loop. As #1 is initially set to Zero in this example, and #2 is 3.0, the resulting value of #1 for the first Loop is -3.0

IF[#1 LT #3] TH #1 = #3 This block is a Conditional, Boolean statement that tests for True or False. LT is the Macro shorthand for LESS THAN, and TH for THEN. In this statement the test is to determine if #1 < #3. If #2 (-3.0) was repeatedly subtracted from #1, eventually #1 would have a value < #3 (-20). On the 7th iteration, #1 would have a value of -21.0, a value less than -20.0. In this case the Macro statement tests True and therefore, #1 will be set to the value of #3, so as not to over cut in Z.

G03 I-10.000 Z#1 F200 This block cuts the helical path from the current Z level down to Z#1 (Z-3.0 for the first iteration)

IF[#1 GT #3] GOTO 10 This block again tests the value of #1 compared to full depth #3. In this case, the test is to determine if #1 is GREATER THAN (GT) #3. On the 6th iteration, #1 would have a value of -18.0, a value that is > #3 (-20.0). In this case the Macro statement tests True, and therefore will execute the GOTO command and control returns to the block containing "N10". When #1 has a value of -20.0, its no longer Greater Than #3, and therefore tests False. In this case, control DOES NOT return to "N10", but continues to execute the remainder of the program.

I hope this helps you understand the Loop functionality of this short program.

Regards,

Bill

Last edited by angelw; 01-26-2012 at 11:18 PM.
Reply With Quote

  #8   Ban this user!
Old 01-27-2012, 04:53 AM
fordav11's Avatar  
Join Date: Aug 2011
Location: Fordaville
Posts: 939
fordav11 is on a distinguished road
retro solution

if you're old school and programmed in BASIC on a C64, BBC Micro, Amiga or something similar in the 80's, macro is very simple to apply using the same programming principles.

For example the above macro statements converted to BASIC would look like this and could effectively be run in something like QBASIC (came with DOS 6) to output the entire tool path to check to see if your logic is correct....

10 A=0 : B=3.0 : C=-20.0
20 PRINT "G90 G00 X10.000 Y0.000"
30 PRINT "G43 Z10.000 H01"
40 PRINT "G01 Z1.000 F2000"
50 A = A - B
60 IF A < C THEN A = C
70 PRINT "G03 I-10.000 F200 Z"; A
80 IF A > C GOTO 50

BASIC is a bit more readable too and less daunting than macro. But essentially macro = BASIC
Sometimes if I need to write a complex macro I'll write it in BASIC first and run it on a computer to prove the logic and ensure the calculated values are coming out right. I will then convert the proven program to macro.
The logic in this very simple example is easy to follow even if you don't know BASIC.

See pic attached with C64 generated G-code
Attached Thumbnails
Click image for larger version

Name:	retro_macro.jpg‎
Views:	16
Size:	132.8 KB
ID:	151252  

Last edited by fordav11; 01-27-2012 at 06:52 AM.
Reply With Quote

  #9   Ban this user!
Old 01-29-2012, 01:45 AM
 
Join Date: May 2007
Location: USA
Posts: 913
g-codeguy is on a distinguished road

Peter Smid's book is good. S.K. Sinha's book is better. Also more expensive, but I got mine for less than the Smid book....used for less than $17 (bit over $20 with shipping). However, it looked like the book had never had a page turned.

Sinha writes it like a text book. Therefore you should not be skipping around. He gives more examples and plenty explanations of "why". I found it informative even though I've been using Macro B for awhile.
Reply With Quote

  #10   Ban this user!
Old 01-30-2012, 06:57 PM
 
Join Date: Jun 2008
Location: United States
Posts: 1,507
stevo1 is on a distinguished road

Originally Posted by g-codeguy View Post
Peter Smid's book is good. S.K. Sinha's book is better.
x2

That's not a blow at Smid's book I am just stating that Sinha's book explains it much better for newcomers to macros.

Stevo
Reply With Quote

Sponsored Links
  #11   Ban this user!
Old 01-31-2012, 10:47 PM
 
Join Date: Feb 2006
Location: india
Posts: 1,187
sinha_nsit is on a distinguished road

Originally Posted by g-codeguy View Post
...Also more expensive...
Not necessarily. I have seen its price dropping down to as low as $5. Just have patience for a couple of weeks and regularly visit amazon's page.
Today's minimum price is $17.46 (new):
Amazon.com: CNC Programming using Fanuc Custom Macro B (9780071713320): S.K Sinha: Books Amazon.com: CNC Programming using Fanuc Custom Macro B (9780071713320): S.K Sinha: Books
Reply With Quote

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
M98 Looping camtd Parametric Programing 20 08-15-2011 08:43 AM
Looping command? rigo430 Haas Lathes 1 04-11-2010 05:35 PM
LOOPING? with Camsoft?? nelZ CamSoft Products 15 10-15-2008 03:56 PM
Program Looping Bohemund CamSoft Products 7 05-26-2007 11:08 AM
Sub Looping murphyspost Daewoo/Doosan 8 12-27-2006 10:28 AM




All times are GMT -5. The time now is 08:04 PM.





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 354 355 356 357 358 359 360 361