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 07-20-2007, 10:31 AM
 
Join Date: Mar 2006
Location: USA
Age: 33
Posts: 39
Jorge-D-Fuentes is on a distinguished road
Macro WHILE DO END Loop (Lathe)

In this thread I finally managed to get a drill to do a radial hole on a lathe.

Now I'm looking for a way to automatically do this a number of times, so I'm looking into subroutine/macro programming.

Again, I look to the Haasmanual for answers and there's a section on the WHILE DO END Iteration/Looping.

(for information purposes, I'm using a Haas OL-1 Lathe with the Live-Tooling and C axis option)

There is less than one quarter of a page's worth of information on it, however. It basically has this:
////////
"Macros allow flexibility with the WHILE-DO-END construct. For example:
WHILE [<conditional expression>]DOn;
<statements>;
ENDn;

This executes the statements between DOn and ENDn as long as the conditional expression evaluates to True. The brackets in the expression are necessary. If the expression evaluates to False, then the block after ENDn is executed next. WHILE can be abbreviated to WH. The DOn-ENDn portion of the statement is a matched pair. The value of n is 1-3. This means that there can be no more than three nested loops per subroutine. A nest is a loop within a loop.

Although nesting of WHILE statements can only be up to three levels, there really is no limit since each subroutine can have up to three levels of nesting. If there is a need to nest to a level greater than 3, then the segment containing the three lowest levels of nesting can be made into a subroutine therefore overcoming the limitation.
////////

As explained in the other thread, the goal here is to drill some holes into the outer diameter of a workpiece, but the book says that there is no canned cycle that does this, so I'm attempting to make one using Macros.

The variables that I'm changing are only the Degrees the C-axis has to rotate to.

This code, for example, would try to put a hole into 0, 90, 180, and 270 degrees in the OD and would look something like this:

;
T101; (pick tool 1)
M14; (clamp spindle brake)
M154; (c axis engage)
G98 (feed/minute)
G00 X1.0 (rapid T101 to x1.0)
#101=0; (variable for c axis degree)
WH [#101LT360] DO1;
G01 C#101 F500; (rotate spindle #101 degrees at 500RPM)
G01 X0.75 F2.; (drill into OD down to 0.75")
G00 X1.0; (retract)
#101=#101+90
END1; (end of loop)
G01 C0. F500.; (return C axis to zero)
M15; (unclamp spindle brake)
M155; (c axis disengage)
;

I cannot seem to enter the WH into the control when in MDI mode, however. As soon as I hit the enter/insert key after the WH (or) WHILE, or after the #101=0, I get a "Bad code" error.

I have not tried putting the program in a file and loading it that way (in case it's just MDI that doesn't allow for parameter passing).

I know I bug you guys with a lot of questions, but I'm willing to try stuff and learn and wouldn't wanna break anything... so I'm careful and check usually here or with software before running....
Reply With Quote

  #2   Ban this user!
Old 07-21-2007, 12:52 PM
 
Join Date: May 2006
Location: Sweden
Posts: 265
M-man is on a distinguished road

This is how I should do this on my machine with fanuc macrob.

I dont think you should have spindlebreak clamp when moving c-axis unless it is a
anti vibration break. Ive got 2 breaks on the machine, both the antivibration and
another one to use when I am machining in other axis then C...

%
:O1000(MAIN)
G28U0
G28W0
G00T0101
M35 - ENGAGE C-AXIS
G28H0 - HOME C-AXIS
G98
G97S5000M34 LIVE TOOL SPINDEL ON
G00X1Z-1 MOVE TO POSITION FOR FIRST HOLE
G66P1001X0.75F2
C90 - MOVES TO C90 AND REPEATS MACRO 1001
C180
C270
G80
G28U0
G28W0
M35 - LIVE TOOL SPINDLE OFF
M5 - TURNING MODE ON
M30
%

%
:O1001(CYCLE/RADIAL DRILLING/NO PECKING)
#1=#5001 - READ X AXIS POSITION AND SAVE FOR CLEARENS.
M89- SPINDLE CLAMP HIGH ON
G1X#24F#9
G0X#1
M90 - SPINDLECLAMP OFF
M99
%
Reply With Quote

  #3   Ban this user!
Old 07-21-2007, 03:36 PM
gar gar is offline
 
Join Date: Mar 2005
Location: USA
Posts: 1,498
gar is on a distinguished road

070721-1530 EST USA

Jorge:

What are the semicolons for? I am not where I can test their effect. Your code looks ok on the surface. Try while instead of WH. Also load the program into an O-number program. If these don't work forget the while, and use line numbers, an if - then test, and a GOTO at the loop end.

I seldom test anything in MDI vs single step in a program. It is easier to edit code on a computer and dowload to the machine for anything other than a couple lines.

Why not post this under HAAS?

.
Reply With Quote

  #4   Ban this user!
Old 07-23-2007, 07:31 AM
 
Join Date: Mar 2006
Location: USA
Age: 33
Posts: 39
Jorge-D-Fuentes is on a distinguished road

IRT All:

I tried loading the program from a file, rather than entering it directly in MDI mode. The control reads the code all the way up until the first PoundSign (#), then does not read anything else and gives out an alarm.

It cannot understand Pound, so I'm guessing there's a chance it just does not have Macros enabled... I'm guessing.

@M-Man:

I actually put the spindle brake code (M14) after the fact. It doesn't seem to make any difference whether I put it on or not, so I left it in. Again, I haven't actually cut a piece, so I don't know whether the spindle is locking when rotating.

I have a bad habit of doing excessive tests before I cut anything (plus we don't have the drillbit for the livetooling spindle, nor do we have the air pressure connected yet. It's there, and a while back it was connected, but they disabled it because they saw 'no need at the time').

I will examine your code and will showcase my results later.

@Gar:

The semicolons are just "End of Line" symbols. In MDI mode, it's equivalent to hitting the "Enter" key on a keyboard. When you write the program in a PC you don't need them, because usually the control adds them as it reads the code.

In MDI mode, you put them in order to move down a line. Aside from that, they don't have any real purpose, so from a PC standpoint, you can ignore them.

I didn't post this under Haas because I figured it was strictly a G-Code thing. I suppose with all the sub-forums that exist here, I probably should have.

There's also the off-chance that the machine doesn't have the "Macros" option enabled, which would mean that anything with a # on it will not read.
Reply With Quote

  #5   Ban this user!
Old 07-23-2007, 08:17 AM
gar gar is offline
 
Join Date: Mar 2005
Location: USA
Posts: 1,498
gar is on a distinguished road

070722-0811 EST USA

Jorge-D-Fuentes:

If the program fails at the
#101 = 0
then that is a good indicator of no MACRO capability.

.
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 07-23-2007, 08:34 AM
 
Join Date: Jul 2005
Location: Canada
Posts: 11,563
Geof will become famous soon enough

Originally Posted by gar View Post
070722-0811 EST USA

Jorge-D-Fuentes:

If the program fails at the
#101 = 0
then that is a good indicator of no MACRO capability.

.
With Haas you can turn Macro on for a trial period of 200 hours. Go to Parameter 57 and in the right hand column you will se ENABLE MACRO. It will show 0T if it is not turned on and 1 if it is. Just type 1 and WRITE and it will turn on. You have to turn off setting 7 and push Estop to do this.
__________________
An open mind is a virtue...so long as all the common sense has not leaked out.
Reply With Quote

  #7  
Old 07-23-2007, 09:28 AM
Switcher's Avatar
Moderator
 
Join Date: Apr 2005
Location: Vectorink.com
Posts: 3,660
Switcher is on a distinguished road

Jorge-D-Fuentes

This code, for example, would try to put a hole into 0, 90, 180, and 270 degrees in the OD and would look something like this:

;
T101; (pick tool 1)
M14; (clamp spindle brake)
M154; (c axis engage)
G98 (feed/minute)
G00 X1.0 (rapid T101 to x1.0)
#101=0; (variable for c axis degree)
WH [#101LT360] DO1;
G01 C#101 F500; (rotate spindle #101 degrees at 500RPM)
G01 X0.75 F2.; (drill into OD down to 0.75")
G00 X1.0; (retract)
#101=#101+90
END1; (end of loop)
G01 C0. F500.; (return C axis to zero)
M15; (unclamp spindle brake)
M155; (c axis disengage)



Do you really need a (WHILE DO END Loop) macro, to rotate only 4 angles?






.
Reply With Quote

  #8   Ban this user!
Old 07-23-2007, 11:32 AM
 
Join Date: Mar 2006
Location: USA
Age: 33
Posts: 39
Jorge-D-Fuentes is on a distinguished road

The example was for only four angles.

In reality, the pieces might have as many as forty to sixty holes in a channel all the way around.

So yes, a do-while loop would be more efficient to write than one hundred and sixty lines.

@Geof & Gar.
I'll check if the setting is enabled. Thanks for telling me the parameter/setting to check. I think some machines have it on, and some don't, and the one that happens to have livetooling doesn't have it. I'll check later.

EDIT
@Geof & Gar:
Yeah it was off. It was set to 0T. I went to Parameter Lock and turned it off, then hit the Emergency Switch, and turned it on by pressing 1, then WRITE/ENTER. Then released the emergency and restarting the machine (I'm familiar with this procedure from when I had to change the Z Max Travel Limits). I turned it back on and now the Macro setting reads "1T". I'm guessing the "T" is for "Trial".

I'll run the code again later.
Reply With Quote

  #9   Ban this user!
Old 07-23-2007, 11:55 AM
 
Join Date: Jul 2005
Location: Canada
Posts: 11,563
Geof will become famous soon enough

Originally Posted by Jorge-D-Fuentes View Post
The example was for only four angles.

In reality, the pieces might have as many as forty to sixty holes in a channel all the way around.

So yes, a do-while loop would be more efficient to write than one hundred and sixty lines.
If your hole spacing is constant, i.e. same angular spacing same linear spacing you could probably do it using incremental moves in nested subroutines with an L count.
__________________
An open mind is a virtue...so long as all the common sense has not leaked out.
Reply With Quote

  #10   Ban this user!
Old 07-23-2007, 01:36 PM
CNCRim's Avatar  
Join Date: Feb 2006
Location: usa
Posts: 947
CNCRim is on a distinguished road

Jorge;

The reason you get an alarm on first # because it's useless number, as computer rule is any number equal to 0 is null..... all the variable in the machine right now is treat as 0.


Originally Posted by Jorge-D-Fuentes View Post
;
T101; (pick tool 1)
M14; (clamp spindle brake)
M154; (c axis engage)
G98 (feed/minute)
G00 X1.0 (rapid T101 to x1.0)
#101=0; (variable for c axis degree)
WH [#101LT360] DO1;
G01 C#101 F500; (rotate spindle #101 degrees at 500RPM)
G01 X0.75 F2.; (drill into OD down to 0.75")
G00 X1.0; (retract)
#101=#101+90
END1; (end of loop)
G01 C0. F500.; (return C axis to zero)
M15; (unclamp spindle brake)
M155; (c axis disengage)
;
I will change to some thing like this?

#100=4(number of hole)
#101=360/#100

T101; (pick tool 1)
M14; (clamp spindle brake)
M154; (c axis engage)
G98 (feed/minute)
G00 X1.0 (rapid T101 to x1.0)
C0(***)this can be vary, some require difference angle .....so revise math need.
WH [#101LT360] DO1;
G01 X0.75 F2.; (drill into OD down to 0.75")
G00 X1.0; (retract)
#101=#101+#101
END1; (end of loop)
G01 C0. F500.; (return C axis to zero)
M15; (unclamp spindle brake)
M155; (c axis disengage)
__________________
The best way to learn is trial error.
Reply With Quote

Sponsored Links
  #11   Ban this user!
Old 07-23-2007, 01:47 PM
 
Join Date: Mar 2006
Location: USA
Age: 33
Posts: 39
Jorge-D-Fuentes is on a distinguished road

An L count, eh?
"I'm interested in this".

Is an L count a procedure that would not require us to purchase the Macro option?

Also, I ran the code but forgot to put the periods next to the numbers representing the degrees, so the spindle did not turn, and my guys are doing a big production run so I can't test my code right now... but I will later.

I gotta look into this L Count. Yes, our holes would be equidistant from one another (I believe), both on the Z and on the C. What might change would be whether it goes all the way around, but often it does.

I might make new programmable code whether this is the case.

EDIT:
@NewTexas:

I don't think this is the case. I managed to get the code working with no issues even if the first variable happened to equal Zero. The reason it is Zero is because I'm drilling the first hole at Zero degrees on the C Axis, so it's far from a useless number.

@Everyone:

I'd like to thank everyone who helped me with this problem.
I'd also like to announce that the following code does what I want it to do to the letter.

%
O09899
T101 (pick tool 1)
M14 (clamp spindle brake)
M154 (c axis engage)
G98 (feed/minute)
G00 X1. (rapid T101 to X1.0)
#101= 0. (variable for c axis degree)
#102= 45. (variable for degree change)
#103= 360. (variable for total degrees)
WH [ #101 LT #103 ] DO1 (WHILE DO END loop)
G01 C#101 F500. (rotate spindle #101 degrees at 500 RPM)
G04 P2.
G01 X0.75 F2. (drill into OD down to 0.75")
G00 X1. (retract)
#101= #101 + #102 (add 90 degrees to variable #101)
END1 (end of loop)
G01 C0. F250. (return c axis to zero)
M15 (unclamp spindle brake)
M155 (c axis disengage)
M30
%

One of the errors I was getting was that the spindle was not rotating. After examining the variables, I realized that all the variables for the C Axis require a period at the end (30 degrees is "30.", not "30").
I also modified the code a bit so that I get the amount of holes I want given a certain portion of the ring.

Say I wanted five holes on one quarter of the ring, I can assign "#103 = 90." instead of "#103=360."
Also, I can say how many holes I want by just getting the degrees. It's a little crude because it requires a bit of math, but I can say I want five holes by assigning "#102=9.". So now I can put five holes on a quarter of a ring or forty holes on the entire circumference, etc.

I have to see if the company will pay for the option to Macro this correctly.

Last edited by Jorge-D-Fuentes; 07-23-2007 at 02:55 PM.
Reply With Quote

  #12   Ban this user!
Old 07-23-2007, 06:45 PM
gar gar is offline
 
Join Date: Mar 2005
Location: USA
Posts: 1,498
gar is on a distinguished road

070723-1826 EST USA

newtexas2006:

Your comment:
The reason you get an alarm on first # because it's useless number, as computer rule is any number equal to 0 is null..... all the variable in the machine right now is treat as 0.
is nonsense.

The code line (block)
#100 = numeric value
on execution results in the variable #100 and only #100 being loaded with the value of "numeric value" whether that value is 25, 25., 0, 0., or null. In HAAS null and 0 are not identical. The HAAS null is #0 . However, the manual is confusing.

From the current HAAS on-line manual.

VARIABLE USAGE
All variables are referenced with a pound sign (#) followed by a positive number. Examples are: #1, #101, and #501.
Variables are decimal values that are represented as floating point numbers. If a variable has never been used, it can
take on a special “undefined” value. This indicates that it has not been used. A variable can be set to undefined with
the special variable #0. #0 has the value of undefined or 0.0 depending on the context it is used in. Indirect references
to variables can be accomplished by enclosing the variable number in brackets.
#[<Expression>]
The expression is evaluated and the result becomes the variable accessed. For example:
When you make a G65 subroutine call all local variables in the called subroutine are assigned the null value unless the variable corresponds to a parameter on the calling line.

.
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
Closed loop vs. open loop pelesl Benchtop Machines 10 04-06-2007 04:56 PM
Lathe conversion - open loop vs closed loop bhowden General Metal Working Machines 7 03-21-2006 03:56 PM
Closed loop....open loop? DAB_Design General Electronics Discussion 10 06-26-2004 04:02 PM
Closed Loop Driver vs. Closed Loop Computer ojibberish Gecko Drives 3 06-08-2004 11:30 AM
closed loop georgebarr DIY-CNC Router Table Machines 9 06-01-2003 09:39 AM




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