Manufacturing Information Solutions Forum Index Manufacturing Information Solutions
Your Place for Support and Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Setting Up Loops With Custom Macro B

 
Post new topic   Reply to topic    Manufacturing Information Solutions Forum Index -> G-Code Programming
View previous topic :: View next topic  
Author Message
juniorf
Frequent Poster


Joined: 15 Jun 2006
Posts: 29
Location: Little Rock, AR

PostPosted: Thu Nov 30, 2006 9:53 am    Post subject: Setting Up Loops With Custom Macro B Reply with quote

[Editors note: I found this on the web, and thought it very usefull, so I wanted to shair it with you all.]

Custom macro B provides many tools to help users with CNC programming, including variable capabilities, arithmetic calculations and program flow control. One of the most powerful functions allowed by this custom macro (and for that matter, any computer programming language) is looping. Looping involves having the machine repeat a series of commands and can be compared to repeating the execution of subprograms. When you repeat a subprogram, it will be executed in exactly the same fashion all four times. That is, nothing in the subprogram can change between executions. When you set up a loop, however, anything can change between executions.

Loops are used to minimize the number of redundant commands needed for your application. Consider this loop, which sets offsets 1 through 100 to zero.

#100 = 1 (Loop counter and offset number)
N1 IF [#100 GT 100] GOTO 50 (Test if finished)
G90 G10 L1 P#100 R0 (Set current offset to zero)
#100 = #100 + 1 (Step counter and offset number)
GOTO 1 (Go back to the test)
N50… (Continue with program)

This loop illustrates the contrast to a time when the commands were written out in longhand, requiring many (100) commands. As you can see, this loop requires only six commands.

Loops are also used when the number of executions for the loop changes from application to application. With a bolt circle loop, for example, the number of holes on the bolt circle can change from one bolt circle to another. You can see this loop example at the seperate post: xxx


Loops become more complicated when it is not easy to determine the number of loop executions. Consider, for example, a peck drilling custom macro. You have a 3-inch deep hole and a peck depth of 1 inch. In this case, the loop is pretty easy to program. The hole depth of 3 inches is evenly divisible by the peck depth of 1 inch. This means that three executions of the peck depth will be required. But what if you have a 3.25-inch deep hole and want a 1-inch peck? This loop requires a little more thought.

I always recommend determining an even number of executions, even if it means modifying certain machining criteria. For example, if you use the “round” function (which rounds to the closest integer), you can come up with an even number of passes. Consider the command:

#100 = ROUND[3.25 / 3.0]
The result will be that #100 will be 3. However, you cannot simply peck 1 inch deep three times. This will not render the correct depth.

Let’s recalculate the peck depth based upon the number of passes:

#101 = 3.25 / #100

The peck depth will be slightly more than 1 inch (in this example). However, you can now set up a loop that has an even number of passes.

1. The seven steps to setting up a loop are:
2. Initialize the counter and, if needed, anything that changes each time within the loop.
3. If necessary, initialize constants in the loop.
4. Test to see if the loop is finished.
5. If necessary, calculate anything needed for the current time through the loop.
6. If necessary, make motions needed for the current time through the loop.
7. Step the counter and, if needed, anything that changes each time through the loop.
8. Go back to the test.

There is a special custom macro function for looping, WHILE. However, anything you can do with a WHILE statement loop can be done with an IF statement loop. Here is the offset clearing loop shown earlier using the WHILE statement:

#100 = 1 (Loop counter and offset number)
WHILE [#100 GT 100] DO 1 (Start of loop)
G90 G10 L1 P#100 R0 (Set current offset to zero)
#100 = #100 + 1 (Step counter and offset number)
END 1 (End of loop)
N50… (Continue with program)

Note that the counter (#100) must still be initialized and stepped. The DO 1 at the end of the WHILE statement tells the machine the location of the loop’s ending (corresponding to END 1). However, if you are nesting loops, only three loops can be running. This means you can use DO1/END1, DO2/END2 and DO3/END3. There is no such limitation to an IF statement loop.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Manufacturing Information Solutions Forum Index -> G-Code Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group