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-04-2012, 09:15 AM
 
Join Date: Jun 2010
Location: U.S.A.
Posts: 4
wileydavis is on a distinguished road
Lathe Code for Mill With Subroutine

I'm trying to hand-code a program to do some turning on my RF-30 mill and I'm trying to wrap my head around subroutines. The program below is for a Mach3 controller and takes a Cut Depth and Cut Length parameter, then loops however many times from the start point.

I've never written a program by hand before, so I was wondering if any of you see any major flaws with this approach. Cheers, and thanks for any insight.

Code:
( Axle )
G20 G90 G91.1 G64 G40 G49
G0 Z0.25
T0 M6
G17
M3 S1900
G0 Z0
G1 F5 X.250
#1=.010 (SUBROUTINE DEPTH)
#2=1.27 (SUBROUTINE LENGTH)
M98 P100 L12
(FINISH PASS)
G1 F5 X.123
G1 F17 Z-1.270 X.125 (TAPER SPRING PASS)
G1 X.350
M5
M30

O100
(TURNING SUBROUTINE)
G91 (BEGIN INCREMENTAL)
G1 F5 X[0-#1] (CUT DEPTH)
G1 F17 Z[0-#2] (CUT LENGTH)
G1 X#1 (PULL OUT TO START X")
G0 Z#2 (RAPID TO START Z)
G1 F7 X[0-#1] (BACK TO START X)
G90 (END INCREMENTAL)
M99
%
Reply With Quote

  #2   Ban this user!
Old 01-05-2012, 12:38 AM
fordav11's Avatar  
Join Date: Aug 2011
Location: Fordaville
Posts: 939
fordav11 is on a distinguished road

What kind of machine is this? Normally you can't do 'real' XZ turning on a mill.

If you have never programmed long hand before why are you over-complicating it by using macro variables? It would be easier to just use long hand code. The sub with incremental values is ok but using macro just makes it harder to understand from the point of view of someone who has never written long hand code before.

As for problems, you are in G17 (XY plane) and you are cutting XZ plane (G18). It's not a problem here because you are only cutting straight but if you cut an arc with G02/G03 you will get an alarm (wrong plane)

Also T0 is not valid except when cancelling an offset. A T0 with M6 after it will generate an alarm.

Your program is very strange regardless of these errors
Reply With Quote

  #3   Ban this user!
Old 01-05-2012, 08:11 AM
 
Join Date: Jun 2010
Location: U.S.A.
Posts: 4
wileydavis is on a distinguished road

Originally Posted by fordav11 View Post
What kind of machine is this? Normally you can't do 'real' XZ turning on a mill.
The machine is a round column mill/drill converted to CNC with servos and a Mach3 controller. I'm chucking up 1/2" dia aluminum stock in a collet and clamping some lathe tools in the vice.

Originally Posted by fordav11 View Post
If you have never programmed long hand before why are you over-complicating it by using macro variables?
I guess I figured I was simplifying things. The subroutine keeps me from making dangerous numerical typos, and the parts I'm making have a shoulder and three grooves of varying depths and widths, so I figured by passing in parameters I could use the same subroutine for each groove and the shoulder. It's not in the example I posted, but my plan was to call M98 multiple times, and correspondingly rewrite the parameters for each call. Is that a piss-poor way to go about it?

Originally Posted by fordav11 View Post
As for problems, you are in G17 (XY plane) and you are cutting XZ plane (G18). It's not a problem here because you are only cutting straight but if you cut an arc with G02/G03 you will get an alarm (wrong plane)
Yeah, my plan there was to switch to G18 only for any arc moves (none in this program) and then switch back to G17. Since it's a mill, I wanted to be sure it stays in G17 as a default in case the next program doesn't explicitly call G17.

Originally Posted by fordav11 View Post
Also T0 is not valid except when cancelling an offset. A T0 with M6 after it will generate an alarm.
Good point. My controller doesn't alarm with a T0, but I'll switch it to an unused tool number and use the tool offset for the stock length.

Originally Posted by fordav11 View Post
Your program is very strange regardless of these errors
How you skin a cat can say a lot about your personality, I suppose
Reply With Quote

  #4   Ban this user!
Old 01-05-2012, 12:55 PM
fordav11's Avatar  
Join Date: Aug 2011
Location: Fordaville
Posts: 939
fordav11 is on a distinguished road

Originally Posted by wileydavis View Post
The machine is a round column mill/drill converted to CNC with servos and a Mach3 controller. I'm chucking up 1/2" dia aluminum stock in a collet and clamping some lathe tools in the vice.
that's a novel approach. I guess if that's all you have to work with then it's fine if it works.

on a mill it's not necessary to use T0 to cancel offsets.
Tool length offset is called with G43 and cancelled with G49
Tool diameter offset is called with G41/G42 and cancelled with G40
T0 isn't required unless your control somehow acts like a lathe control.

How you skin a cat can say a lot about your personality, I suppose
I don't skin cats, I usually roast them on a spit. The skin usually just falls off with the cooked meat. Much easier than skinning it manually.

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

  #5   Ban this user!
Old 01-08-2012, 09:49 PM
 
Join Date: Jun 2010
Location: U.S.A.
Posts: 4
wileydavis is on a distinguished road
Success!

I finally got the subroutine working. Turned out I had the wrong line-ending on my text file encoding and Mach3 didn't like the line return after the M99. Once I saved to a windows line ending, it ran fine (similar to the above code but not the same program). Here's a video of the outcome (turning a shoulder, a 1/4" wide groove, and parting.

http://thungy-videos.s3.amazonaws.co...ng-960_540.mp4

Thanks for the advice on T0. Cheers.
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
Found in archives - A2100 thread mill subroutine Ron P Cincinnati CNC 2 05-17-2011 08:38 AM
subroutine kendo Okuma 3 01-14-2010 06:50 AM
Problem- macro code inside of a subroutine brockmo Fadal 7 03-12-2009 10:32 PM
Program g-code for mill as multiple tool lathe? Monte G-Code Programing 12 04-18-2008 11:18 PM
G-code viewer (subroutine) hao G-Code Programing 1 11-15-2006 06:10 AM




All times are GMT -5. The time now is 08:03 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