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 03-23-2009, 05:55 AM
 
Join Date: Apr 2008
Location: england
Posts: 11
modulus is on a distinguished road
macro question loop

Hi all,

I've been trying to write a macro so that I can easily drill holes in the diameter of shafts. The macro works but there is a problem in the 'while... Do' loop

WHILE[#24LT#101]DO1

N1G01X[#103-#5]F#9
N2#101=#5041 load current x machine pos into #101
N3#103=#5041 load current x machine pos into #103
N4G00X#102 rapid clear of shaft dia
N5X[#103+1.0] rapid to last feed posn + 1mm
END1

Unless I put eob between the lines in the loop the program executes N2 before N1 has fed to posn. How should I properly stop the program from executing commands before previous command have finished.
In the actual program there are no N numbers. I just put them here for clarity.

cheers

Andy
Reply With Quote

  #2   Ban this user!
Old 03-23-2009, 06:03 AM
 
Join Date: Apr 2008
Location: england
Posts: 11
modulus is on a distinguished road

Forgot to mention control is fanuc 16t
Reply With Quote

  #3   Ban this user!
Old 03-23-2009, 01:18 PM
 
Join Date: May 2007
Location: USA
Posts: 913
g-codeguy is on a distinguished road

Tried your program. First peck worked, but after making the rapid move to X#102 it continued to X4.738 before stopping at which point I stopped the machine. Obviously I wasn't picking up the current X-position with #5041. Looked in the Fanuc manual for 16-18 controls. Changed #5041 to #5001. Your program runs fine.

I can only assume you have some way already set in the program so that the drill won't feed smaller than #24.

EDIT: BTW, thanks for the idea. I love to learn new things. Don't know yet where I can use it, but who knows, maybe one day it will come in handy. Thanks.
Reply With Quote

  #4   Ban this user!
Old 03-23-2009, 01:33 PM
beege's Avatar  
Join Date: Feb 2008
Location: USA
Posts: 518
beege is on a distinguished road

I've never done this sort of thing, but might you need a G09 there somewhere? (Exact Stop). I'd be afraid it'd pick up the "current position" somewhere within the range, but not exactly.
Reply With Quote

  #5   Ban this user!
Old 03-23-2009, 02:22 PM
 
Join Date: Apr 2008
Location: england
Posts: 11
modulus is on a distinguished road

I should have posted the whole program. Here it is.
A G65 macro call is made from the main program after tool selection, spindle speed, etc has been set and the drill has been moved to the start position of the hole. I did this because my control appears not to have G83 and I was spending ages writing the code line by line every time I had a different hole to drill.
It's may have some critical bug so I test in fresh air every time before use, but it's already saved me a stack of time and broken drills from hand programing errors. Wish I knew more.

:0001( main prog)
start spindle etc
GOO X22.0 Z-24.0 (RAPID TO START POSITION FOR DRILLED HOLE)
M98 (FEED PER MIN)
G65P9004 X-22.0 I3.0 J4.0 E25 F50
(X= #24, FINAL DRILL POSITION IN X)
(I= #4, FIRST PECK DEPTH, slow feed into workpiece)
(J= #5, SUBSEQUENT PECK DEPTHS)
(E= #8 FIRST PECK FEED)
(F= #9 SUBSEQUENT PECK FEED )


:9004

#102=#5041 (LOAD MACHINE POSN INTO #102

G98
G01X[#102-#4]F#8 (FEED TO FIRST PECK )
#103=#5041 (LOAD MACHINE POSN TO #103)

WHILE[#24LT#101]DO1 (DO LOOP WHILE #24 IS LESS THAN #101)
;
G01X[#103-#5]F#9 FEED TO CURRENT POSN - PECK DEPTH)
;
#101=#5041 (LOAD MACHINE POSN TO #101)
;
#103=#5041 (LOAD MACHINE POSN TO #103)
;
G00X#102 (RAPID BACK TO START OF CYCLE)
;
X[#103+1.0] (RAPID BACK TO LAST DRILL POSN + 1MM)
;
END1

X#102

#101=#5041
M99
M30
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 03-23-2009, 03:37 PM
beege's Avatar  
Join Date: Feb 2008
Location: USA
Posts: 518
beege is on a distinguished road

Originally Posted by modulus View Post
I should have posted the whole program. Here it is.
A G65 macro call is made from the main program after tool selection, spindle speed, etc has been set and the drill has been moved to the start position of the hole. I did this because my control appears not to have G83 and I was spending ages writing the code line by line every time I had a different hole to drill.
It's may have some critical bug so I test in fresh air every time before use, but it's already saved me a stack of time and broken drills from hand programing errors. Wish I knew more.

:0001( main prog)
start spindle etc
GOO X22.0 Z-24.0 (RAPID TO START POSITION FOR DRILLED HOLE)

GOO is supposed to be G00 (Zeroes not Ohs)

M98 (FEED PER MIN)

S'posed to be G98?

G65P9004 X-22.0 I3.0 J4.0 E25 F50
(X= #24, FINAL DRILL POSITION IN X)
(I= #4, FIRST PECK DEPTH, slow feed into workpiece)
(J= #5, SUBSEQUENT PECK DEPTHS)
(E= #8 FIRST PECK FEED)
(F= #9 SUBSEQUENT PECK FEED )


:9004

#102=#5041 (LOAD MACHINE POSN INTO #102

G98
G01X[#102-#4]F#8 (FEED TO FIRST PECK )
#103=#5041 (LOAD MACHINE POSN TO #103)

WHILE[#24LT#101]DO1 (DO LOOP WHILE #24 IS LESS THAN #101)
;
G01X[#103-#5]F#9 FEED TO CURRENT POSN - PECK DEPTH)
;
#101=#5041 (LOAD MACHINE POSN TO #101)
;
#103=#5041 (LOAD MACHINE POSN TO #103)
;
G00X#102 (RAPID BACK TO START OF CYCLE)
;
X[#103+1.0] (RAPID BACK TO LAST DRILL POSN + 1MM)
;
END1

X#102

#101=#5041
M99
M30
Possible corrections in red?
Reply With Quote

  #7   Ban this user!
Old 03-23-2009, 07:14 PM
 
Join Date: May 2007
Location: USA
Posts: 913
g-codeguy is on a distinguished road

Originally Posted by beege View Post
I've never done this sort of thing, but might you need a G09 there somewhere? (Exact Stop). I'd be afraid it'd pick up the "current position" somewhere within the range, but not exactly.
Beege, I thought of that and you may be right. Most of the lathes we have use an M-code for exact stop on/off. I leave it on. His program runs fine on a Daewoo with 18T control. Course I had to make up my own little section to test it with as Andy didn't give all the code needed to run it.
Reply With Quote

  #8   Ban this user!
Old 03-23-2009, 07:37 PM
 
Join Date: May 2007
Location: USA
Posts: 913
g-codeguy is on a distinguished road

Andy. I am going to look at your latest program example in depth tomorrow. I have one question at the moment. What tells the control to stop drilling at X-22.? If I am following it correctly, it should drill to X-25. not the X-22. in the program. Ok for a thru hole (other than time wasted), but not what you want in other situations.

I'm pretty tired, so maybe I am missing something simple.
Reply With Quote

  #9   Ban this user!
Old 03-24-2009, 04:08 AM
 
Join Date: Apr 2008
Location: england
Posts: 11
modulus is on a distinguished road

Hi G-Code.
You are right, it does drill too far. It's my first attempt so not had time to tweak it. I guess I need to check the drill pos in a different place. it just drills into fresh air for my requirement, but i'd prefer it to be right of course and I was more worried about it reading the x position before the feed block had finished.

Cheers

Andy
Reply With Quote

  #10   Ban this user!
Old 03-24-2009, 04:13 AM
 
Join Date: Apr 2008
Location: england
Posts: 11
modulus is on a distinguished road

Hi Beege,
I see you spotted the deliberate mistakes...:-P
I just typed the remarks and other bits on my laptop. sorry about the errors

Andy
Reply With Quote

Sponsored Links
  #11   Ban this user!
Old 03-24-2009, 06:27 AM
 
Join Date: May 2007
Location: USA
Posts: 913
g-codeguy is on a distinguished road

Originally Posted by modulus View Post
Hi G-Code.
You are right, it does drill too far. It's my first attempt so not had time to tweak it. I guess I need to check the drill pos in a different place. it just drills into fresh air for my requirement, but i'd prefer it to be right of course and I was more worried about it reading the x position before the feed block had finished.

Cheers

Andy
I have a hunch that 'Beege' was right. Set the control for Exact Stop either with the G9 or preferably with an M-code if one is available for your machine.

After the last peck it also rapids to X[#103+1.] and then back to X#102.

Following is a program that eliminates both problems. Only difference is that 'J' becomes the maximum peck depth. Control figures the correct peck depth to finish at X-22. as shown in your example. Once there it rapids back to X#102 and you go on from there.


:0133

#102=#5041

(FIGURE PECK DOC)
#21=20 (LEAVE AT 20) 20 would be a number larger than you would ever peck at
#22=1 (LEAVE AT 1)
WHILE[#21GT#5]DO1
#21=[[#102-#4-#24]/#22]
#22=[#22+1]
END1

G1G98X[#102-#4]F#8
#103=#5041
WHILE[#24LT#101]DO2
G1X[#103-#21]F#9
#101=#5041
IF[#101EQ#24]GOTO9
#103=#101
G0X#102
X[#103+1.]
N9END2
G0X#102
#101=#5041
M99


:122

Tool, spindle speed, etc.
X22.Z-15.
G65P133X-22.I3.J4.E25F50
...
...
M30
%

I am relatively new at this myself. I am sure others could come up with a more elegant solution. However this does work. I tested it before the others came in for work.

EDIT: I layed out the program this way so that when I loaded it into the control program O122 would be the one showing on the screen.

EDIT2: Oops, forgot to change #5001 back to #5041 for you. And back to X[#103+1.] I had to run in fractions.

Last edited by g-codeguy; 03-24-2009 at 08:30 AM.
Reply With Quote

  #12   Ban this user!
Old 03-24-2009, 12:16 PM
 
Join Date: Apr 2008
Location: england
Posts: 11
modulus is on a distinguished road

Thanks G-Code

What does the first loop do?
How does your code prevent premature execution.. of commands?

I'll try and figure it out but some remarks would be helpfull

Cheers

Andy
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
macro - motion pauses each loop kendo Haas Mills 2 12-18-2008 05:17 AM
question on closed loop vs open loop (servo systems) boonie Servo Motors and Drives 20 11-09-2007 12:30 PM
Loop in Mach 3 Question?? Help please luther Mach Software (ArtSoft software) 0 10-06-2007 11:21 PM
Loop in Mach 3 Question?? Help please... M47, M99 jimmychand Mach Software (ArtSoft software) 3 09-10-2007 08:06 AM
Macro WHILE DO END Loop (Lathe) Jorge-D-Fuentes G-Code Programing 18 07-25-2007 08:57 AM




All times are GMT -5. The time now is 12:13 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 354 355 356 357 358 359 360 361