40
What Is Parametric Programming? The best kept secret of CNC! There are few CNC people that even know what parametric programming is -- and fewer still that know how to use it! Given the enhancements that this kind of programming brings, it is surprising that more machine tool builders, control manufacturers, and technical schools don't say more about it. In this short discussion, we'll explain what parametric programming is and show its main applications. What it is Parametric programming can be compared to any computer programming language like BASIC, C Language, and PASCAL. However, this programming language resides right in the CNC control and can be accessed at G code level, meaning you can combine manual programming techniques with parametric programming techniques. Computer-related features like variables, arithmetic, logic statements, and looping are available. Like computer programming languages, parametric programming comes in several versions. The most popular is Custom Macro B (used by Fanuc and Fanuc- compatible controls). Others include User Task (from Okuma), Q Routine (from Sodick), and Advanced Programming Language [APL] (from G& L) In addition to having many computer-related features, most versions of parametric programming have extensive CNC-related features. Custom macro, for example, allows the CNC user to access many things about the CNC control (tool offsets, axis position, alarms, generate G codes, and program protection) right from within a CNC program. These things are impossible with only normal G code programming techniques. Applications: Many companies have excellent applications for custom macro and don't even know it. Of course, if you don't even know you have an application for something, it's impossible to even consider using it. While these applications are covered in much greater detail

Parametric Programming

Embed Size (px)

Citation preview

Page 1: Parametric Programming

What Is Parametric Programming?The best kept secret of CNC!

There are few CNC people that even know what parametric programming is -- and fewer still that know how to use it! Given the enhancements that this kind of programming brings, it is surprising that more machine tool builders, control manufacturers, and technical schools don't say more about it. In this short discussion, we'll explain what parametric programming is and show its main applications.

What it is Parametric programming can be compared to any computer programming language like BASIC, C Language, and PASCAL. However, this programming language resides right in the CNC control and can be accessed at G code level, meaning you can combine manual programming techniques with parametric programming techniques. Computer-related features like variables, arithmetic, logic statements, and looping are available. Like computer programming languages, parametric programming comes in several versions. The most popular is Custom Macro B (used by Fanuc and Fanuc-compatible controls). Others include User Task (from Okuma), Q Routine (from Sodick), and Advanced Programming Language [APL] (from G& L)

In addition to having many computer-related features, most versions of parametric programming have extensive CNC-related features. Custom macro, for example, allows the CNC user to access many things about the CNC control (tool offsets, axis position, alarms, generate G codes, and program protection) right from within a CNC program. These things are impossible with only normal G code programming techniques.

Applications: Many companies have excellent applications for custom macro and don't even know it. Of course, if you don't even know you have an application for something, it's impossible to even consider using it. While these applications are covered in much greater detail during our video course and CD-rom course, applications for custom macro fall into five basic categories. Do any of these sound familiar?

Families of partsAlmost all companies have at least some applications for custom macro that fit into this category. Possibly you have prints dimensioned with variables right on the print. The programmer must reference a chart on the drawing to come up with values needed in the program. Or perhaps you consistently find yourself editing one CNC program to make another one. If you do, you have a perfect application for custom macro!

User-created canned cyclesEven if you don't have a perfect family of parts application for custom macro, surely you have at least some work pieces that require similar machining operations. Or maybe you find yourself wishing your CNC control had more (or better) canned cycles. With custom macro, you can develop general purpose routines for operations like thread milling, bolt

Page 2: Parametric Programming

hole patterns, grooving, and pocket milling. In essence, you can develop your own canned cycles!

Complex motionsThere may be times when your CNC control is incapable of easily generating a needed motion. To perform accurate taper thread milling (taper threads), for example, your control must have the ability to form a spiraling motion in XY while forming a linear motion in Z (helical motion will not suffice in this case). Unfortunately, most CNC controls do not have spiral interpolation. But, believe it or not, with custom macro you can generate this desired motion. In essence, custom macro, allow you to create your own forms of interpolation.

Driving accessory devicesProbes, post process gauging systems, and many other sophisticated devices require a higher level of programming than can be found in standard G code level programming. Custom macro is the most popular parametric programming language used to drive these devices. In fact, if you have a probe on one or more of your machines, you probably have custom macro!

UtilitiesThere is a world of things you can do with custom macro that you would never consider doing without it. Custom macro can help reduce setup time, cycle time, program transfer time, and in general, facilitate the use of your equipment. A few example applications that fit into this category include part counters, tool life managers, jaw boring for turning centers, using standard edge finders as probing devices, and facilitating the assignment of program zero.

Benefits of parametric programming

Fast turnaround in production is the most significant benefit of family of parts macros. More time is often needed to develop macro than a standard program.

Page 3: Parametric Programming
Page 4: Parametric Programming

When to program parametrically

Large number of parts that are same shape but different in dimensions

Large number of parts that are similar in shape

Parts that repeat fairly frequently

Parts that contain repetitive tool path

Various machining patterns

Parametric program is never a replacement for other methods- it only enhances them. There could be a significant investment in time spent on parametric macro program development. The resulting benefits are must be tangible and measurable, in order to be economically efficient.

Example: To stress what can be done with parametric programming, we show a simple example written in custom macro B for a machining center application. It will machine a mill a hole of any size at any location. Notice how similar this program is to a program written in BASIC.

ProgramO0001 (Program number)#100=1.0 (Diameter of end mill)#101=3.0 (X position of hole)#102=1.5 (Y position of hole)#103=.5 (Depth of counter bored hole)#104=400 (Speed in RPM)#105=3.5 (Feed rate in IPM)#106=3.0 (Tool length offset number)#107=2.0 (Diameter of counter bored hole)G90 G54 S#104 M03 (Select abs mode, coordinate system, start spindle)G00 X#101 Y#102 (Rapid to hole center)G43 H#106 Z.1 (Instate tool length compensation, rapid to approach Z position)G01 Z-#103 F [#105 / 2]Y [#102 + #107 / 2 - #100 / 2] F#105G02 J-[#107 / 2 - #100 / 2]G01 Y#102G00 Z.1M30

There are 3 types of variables - Local, Common and System variables.

Page 5: Parametric Programming

Local variables are "local" to the program that is currently executing. They can be set and read only in that program. As soon as control is passed to another program, such as when a subprogram is called, that program has its own set of local variables which can be set, read, etc. When control passes back to the original program, its set of local variables is restored. For instance, if you set variable #1 to 100 in the main program, then call a subprogram, var #1 is now empty. You can set and use var #1 in the sub without overwriting the value of #1 in the main. When you return to the main program, var #1 retains its original value of 100. This is useful because you can use local variables at will within subprograms without having to keep track of the local variables you are using in other programs for fear of overwriting them. If you watch the macro variable screen as programs execute, you can see the local variable sets change as control is passed from one program to another. You can pass a value to a local variable when calling a subprogram with the G65 command.

Common variables are "common" to all programs. Set the variable in one program and all of the other programs see the same value. They are retained even after program execution stops. They can be set within a program or by the operator on the macro variable screen. You can even create screen labels for some of them to make it easier for operators to set values. One of the things that we use them for is when we have a choice of profiles on a part. The operator can set variable 500, which may have a screen label of "PROFILE#", to the desired profile number and then the program uses this to select the correct tool, spindle, cutter comp and height offset.

System variables are special variables that represent values in various registers of the control. For instance, when you call H14, you are referring to offset register 14. The value of offset register 14 can be read or set by accessing system variable #2014. Some system variables are read only and cannot be set. There are system variables for reading the absolute X, Y, or Z position of the machine (read only). We sometimes use this set of variables to read the machine position if we need to come back to that exact same point after a series of calculated moves which may have introduced rounding errors when executed.

All of this should be in your operator manual. If you don't have one, get one! The book is not always clear in its descriptions, so write a lot of little test programs until it is clear just how things work. Always start out simple and work up to the complicated stuff.

The present invention relates to the field of robotically-automatedproduction lines. More specifically, the present invention relates toproviding flexibility to a robotically-automated production line throughparametric programming techniques.

BACKGROUND OF THE INVENTION

Over the past thirty years, machine automation has become an importantaspect of every product's assembly or manufacturing line. Computernumerical control (CNC) machines are one type of common automatedmachinery. CNC machines can be directed by a computer program to performany task that an operator could make a conventional machine perform,including welding, drilling, laser cutting, and bending. For example, a

Page 6: Parametric Programming

drill press operator who needs to drill three holes in a metal sheet nolonger has to bring the press toward the sheet. Instead, the operatorsimply places the sheet on the drill press and a computer program commandsthe press to drill holes in the correct locations.

Until recently, CNC machines required individual programs for each specifictask. For example, two distinct programs were needed in order to command adrill press to drill four holes in the middle of one metal sheet and fourholes along the perimeter of another metal sheet. Therefore, an operatorwas required to place the first metal sheet in the press, load the firstprogram, remove the first metal sheet, place the second metal sheet in thepress, and load the second program. Thus, while CNC automated a machine'sindividual functionality, it did not automate multiple independent tasks.As a result, programmers consistently had to edit one CNC program to makeanother, no matter how closely related the tasks.

The advent of robotic manufacturing and assembly lines automated thisprocess to a greater extent by eliminating manual movement of thework piece. Specifically, using the above example, robots are now able toplace the first metal sheet in the press, remove the first metal sheetwhen the CNC-controlled machinery has accomplished its task, place thesecond metal sheet in the press, and so on. However, the CNC-controlledmachinery still requires discrete programs to perform different tasks.Therefore, although a manufacturing line may be automated robotically suchthat human intervention is not required to manipulate a work piece in acertain way, human intervention (in the form of additional programming)still is required to permit the robotically-controlled line to manipulatethe work piece in a different way.

Parametric programming has been developed to overcome the need for discrete programs for each independent task that a machine performs. Parametricprogramming is a technique that allows a CNC programmer to vary theparameters of the task within one program, instead of writing an entirelynew program each time the parameters are varied. In other words,parametric programming allows programs to be written usingvariable-designated parameters instead of fixed numbers. These variablescan be changed each time the program is called. For example, if aparametric program is stored in a machine's memory to drill a bolt hole,the program can be used with any corresponding data file to drill any sizehole in any location. Parametric programming also includes structures forconditional and unconditional program branching, repetitive looping andmathematical equations. There are several parametric programming languagesincluding CUSTOM MACRO B™, USER TASK™, Q ROUTINE™ and ADVANCEDPROGRAMMING LANGUAGE™. As a result, a programmer simply may develop one

Page 7: Parametric Programming

program for a certain machine, for example a drill press. The parametricprogram queues the operator to put in data sets for each individual taskthat the drill press must perform. The operator then tells the machinewhen to begin each task, instead of loading a new program each time.Therefore, programming efforts are reduced significantly.

Although parametric programming of individual robotic devices and machinesis possible, there is no current method for incorporating the flexibilityof parametric programming into an entire robotically-controlledmanufacturing or assembly line. Because there is no current method forincorporating parametric programming into an entire robotic line, thebenefits of parametric programming have not been realized in thisapplication. Thus, complicated and complete programming revisions arenecessary in order to vary the tasks of robotic lines. As a result,today's robotic manufacturing and assembly lines often are dedicated tomanufacturing one type or size of a product. For example, in the contextof electrical transformer tanks, a robotic manufacturing line canmanufacture only one size enclosure with a particular set ofcharacteristics (e.g., high voltage bushing locations). If anotherenclosure size with a different set of characteristics is desired, theline must be shut down and reprogrammed. Because of the consequentlabor-intensive effort to make such a change, today'srobotically-controlled manufacturing and assembly lines are dedicated tospecific products or functions.

Therefore, it would be advantageous to use the flexibility of parametricprogramming techniques in a robotic assembly or manufacturing line suchthat products of varying size and character can be manufactured withoutinterruption in the line. By minimizing human intervention in theproduction process, the present invention facilitates a "lights out"factory for the production of distribution transformers. Specifically, anexternal user, like a customer or a field sales person, may orchestratethe entire production process to meet his or her requirements via theInternet, for example. The user is able to configure the product andproduce an on line price quotation. Also, the user is able to submitorders, review scheduling, and receive confirmation of the manufacture ofthe products in a manner similar to ordering a custom made personalcomputer over the Internet. Additional detail for the "lights out" factoryis found in International Application No.: PCT/US00/35268, InternationalFiling Date: Dec. 27, 2000.

Page 8: Parametric Programming

SUMMARY OF THE INVENTION

The present invention provides a system and method for creating products ofvarying characteristics on an automated production line. The systemincludes one or more production line devices, for example robots andmachines. Each robot and machine is operated by a parametric computerprogram that may be stored locally with the production line devices. Thesystem also comprises one or more data source(s) coupled to the productionline devices. The data source provides characteristics of a desiredproduct to the production line devices. The data source may be a localterminal or a remote terminal connected to the production line via theInternet, for example. In one embodiment, the system further comprises acomputer coupled to the production line devices and to the data sources.The computer may route the inputted characteristics to each of theproduction line devices in a logical order. The computer also may convertthe characteristics into a formatted file readable by the parametriccomputer program, for example a machine data file (MDF).

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a block diagram of a robotically-automated electrical transformertank manufacturing line, according to the present invention;

FIG. 2 is a flowchart detailing the operation of the robotically-automatedelectrical transformer tank manufacturing line, according to the presentinvention;

FIG. 3A is a table of a customer's individual desired features for anelectrical transformer tank enclosure, according to the present invention;

FIG. 3B is a drawing of a portion of an electrical transformer tankenclosure referred to in FIG. 3A, according to the present invention;

FIG. 4A is a table indicating the machines and tools needed to perform adesired task, according to the present invention;

FIG. 4B is an example of a MDF, according to the present invention; and

FIGS. 5A and 5B are an exemplary MDF for use with the present invention forthe manufacture of an electrical transformer tank.

Page 9: Parametric Programming

Reference will now be made in detail to a presently preferred embodiment ofthe invention, an example of which is illustrated in the accompanyingdrawings.

DETAILED DESCRIPTION OF PREFERRED EMBODIMENTS

By using parametric programming for an entire robotic production line, thepresent invention permits the robotic line to produce similar products ofdifferent characteristics without interruption in the line. For example,the present invention may allow a robotic manufacturing line tomanufacture similar electrical transformer enclosures of varying sizes andvarious configurations.

FIG. 1 is a block diagram of a robotically-automated electrical transformertank manufacturing line 100, according to the present invention. As shownin FIG. 1, a data source 102 is coupled to a design database computer 104.Data source 102 may be a data entry terminal, for example, local tomanufacturing line 100. Alternatively, data source 102 may be a remoteterminal coupled to design database computer 104 via the Internet.Although one data source is shown in FIG. 1, it should be appreciated thatthere may be more than one data source. Design database computer 104 iscoupled to cell control computer 101. Design database computer 104 may beconnected to cell control computer 101 and data source 102 using localaccess network (LAN) technology, for example an Ethernet system operatingon TCP/IP protocol. Although FIG. 1 shows design database computer 104separate from cell control computer 101, design database computer 104 maybe a software component of cell control computer 101.

Cell control computer 101 is coupled to terminal server 103, laser cutter106, and master programmable logic controller (PLC) 105. Cell controlcomputer 101 may be connected to master PLC 105 and terminal server 103using LAN technology, for example an Ethernet system operating on TCP/IPprotocol. Terminal server 103 is coupled to robot A 106, robot B 107, androbot C 111. Master PLC 105 is coupled to the devices in cell one 112,cell two 113, and cell three 114. Cell one 112 houses laser cutter 106 androbot A 107. Cell two houses embossing machine 108 and robot B 109. Cellthree houses robot C 111 and stud welder 110. Although not shown, itshould be appreciated that manufacture of the electrical transformer tankmay include additional cells housing additional robots and machines. Inthis application the term "robot" refers a material moving device, and"machine" refers to a device that operates on and manipulates a workpiece.

Page 10: Parametric Programming

The terminology is consistent with that which is used in the art.

FIG. 2 is a flowchart detailing a method of operating therobotically-automated electrical transformer tank manufacturing line 200,according to the present invention. In step 201, data source 102 providesthe desired characteristics of a particular electrical transformer tank.The characteristics from data source 102 may be provided by a customer whois remote from the manufacturing line using an Internet connection, forexample. Alternatively, the tank's characteristics may be entered by anoperator who is queried at a data entry terminal local to themanufacturing line. The customer may specify the characteristics of theelectrical transformer tank either by choosing a standard tank modelnumber. Alternatively, the customer may specify a list of individualfeatures by name or by part number with corresponding locationdesignations.

FIGS. 3A and 3B provide a table and corresponding drawing showing oneexample of a customer's individual desired features. Each of thecharacteristics shown in FIG. 3B have a corresponding part number, nameand location in the table in FIG. 3A. For example, a customer may requirea switch hole, located at X1=19 and Y1=4.57 and a bend along the Y-axis atY1=17.32 and Y2=51.51. The customer also may require two oil fill pads,located at X1=16.9 and Y1=6.82 and X2=6.82 and Y2=24.74. Each of thesefeatures has a corresponding part number.

Referring back to FIG. 2, the characteristic data corresponding to thedesired electrical transformer tank provided in step 201 then entersdesign database computer 104 in step 202. If the customer did not know thepart number associated with each feature in step 201, step 202 will mapthe part number to a corresponding desired feature. Specifically, in step202, design database computer 104 creates a MDF by mapping each desiredcharacteristic (or the desired tank model number) to a database of partnumbers and corresponding machine and tool numbers. The identified numbersrepresent the necessary machines and their tools needed to create thedesired characteristics, as represented by part numbers. In other words,each part number has a corresponding list of machines and tools necessaryto create the part. In addition, in step 202, if the data entry includedindividually desired features, design database computer 104 carriesforward the specified locations of each of the desired characteristics asdesignated by data source 102. If the data entry simply specified a tankmodel number, these locations will be generated automatically.

Page 11: Parametric Programming

FIG. 4A provides a sample table indicating the machines and tools needed toperform a desired task. Each part number has a corresponding list ofmachines and tools necessary to create the desired part (i.e., feature). Atool is a subcomponent of a machine on the manufacturing line. As shown inFIG. 4A, machine M04 and tool T03 may be used to create part number2A16023F01, which corresponds to the two oil fill holes specified by datasource 102. Stated differently, part number 2A16124F01 may require the useof a plasma cutting head tool (e.g., T03) located in laser cutting machine106 in order to create an oil fill hole. This process is repeated for eachindividual characteristic until a list of the necessary machines and toolsis created as shown, for example, in FIG. 4A. Once the machines and theirtools have been selected, a MDF may be created.

FIG. 4B shows an example of a MDF, according to the present invention. Asshown in FIG. 4B, the MDF lists the location (e.g., X-Y location) of thedesired feature, and the machine and its tool necessary to create thefeature. For example, in the first part of the table tool T03 of machineM04 will create two holes. The first hole is located at x=16.90 andy=6.82. The second hole is located at x=16.90 and y=24.74. Then, tool T05of machine M04 creates another hole at x=19 and y=4.57. Tool T243 ofmachine M05 then creates a bend along the y axis at x=0, y=17.32 and x=0,y=51.51. Notably, the order of each operation is logically arranged suchthat one machine may always operate on the electrical transformer tankenclosure before another machine. For example, it may be preferable forhole cutting machine M04 to operate on the electrical transformer tankenclosure before bending machine M05. An exemplary MDF for use with thepresent invention for the manufacture of an electrical transformer tank isincluded in FIGS. 5A and 5B.

Referring back to FIG. 2, in step 203, cell control computer 101 parses theMDF into discrete file packets and transfers the packets to master PLC105, terminal server 103 and laser cutter 106. Each file packetcorresponds to a particular robot and machine. Unlike the other robots andmachines, cell control computer 101 is coupled directly to laser cutter106. This is due to the added complexity of laser cutter 106 andconsequent volume of information that must be processed by laser cutter106. In addition, because of the complexity of laser cutter 106, it mayinclude a computer (not shown) that processes the MDF routed by cellcontrol computer 106. The connection between laser cutter 104 and cellcontrol computer 101 may be an RS-422 serial connection, for example.

Page 12: Parametric Programming

In step 204, cell control computer 101 sends the parsed MDF for robots A107, B 109, and C 111 to terminal server 103. Terminal server 103 thensequences the parsed MDF for the operation of robot A 107, robot B 109,and robot C 111 in accordance with the manufacturing line's process. Instep 205, cell control computer 101 sends the parsed MDF for machines 106,108 and 110 to master PLC 105. Master PLC 105 then sequences the parsedMDF for each of machines 106, 108 and 110 in accordance with themanufacturing line's process. For example, as shown FIG. 4B, hole cuttingmachine M04 and tool T03 will be operated before bending machine M05 andtool T243. In step 206, robots A 107, B 109, and C 111 receive relevantMDF from terminal server 103 in a logical sequence. In step 207, machines106, 108 and 110 receive the relevant MDF from master PLC 105 in a logicalsequence. Each of the machines and the robots receive the MDF into theirresident parametric programs.

In step 208, a computer internal to robots 107, 109, and 111 converts theparametric program with the inputted MDF into a format readable by theindividual robots, for example CNC programming instructions. In step 209,a computer internal to machines 106, 108 and 110 convert the parametricprogram with the inputted MDF into a format readable by the individualmachines, for example CNC programming instructions. The robots and themachines participate in the manufacturing, as commanded by the CNCprogramming instructions and to output the final product in step 210.Because the resident parametric program is a shell that integrates theentire functionality of the robots and machines, the parametric program iswritten for each production line device just once. The inputted MDF is themechanism that instructs the production line devices to performdifferently depending on the particular characteristics of the desiredproduct.

The present invention is directed to a system and method for automating arobotically-controlled production line, that includes, but is not limitedto, the production of electrical transformer tank enclosures, regardlessof any specific description in the drawing or examples set forth herein.It will be understood that the present invention is not limited to use ofany of the particular parts or assemblies discussed herein. Indeed, thisinvention can be used in any assembly or manufacturing line that requiresrobotic automation. Further, the system disclosed in the present inventioncan be used with the method of the present invention or a variety of otherapplications.

Page 13: Parametric Programming

While the present invention has been particularly shown and described withreference to the presently preferred embodiments thereof, it will beunderstood by those skilled in the art that the invention is not limitedto the embodiments specifically disclosed herein. Those skilled in the artwill appreciate that various changes and adaptations of the presentinvention may be made in the form and details of these embodiments withoutdeparting from the true spirit and scope of the invention as defined bythe following claims.

Page 14: Parametric Programming
Page 15: Parametric Programming

A custom macro for tool change format. (CNC Tech Talk).

Source:  Modern Machine Shop

Publication Date: 01-AUG-03

Much of CNC manual programming is redundant. Similar commands must be repeated on a fairly regular basis, especially when tool changes must be made. Because these commands are only similar (not identical), subprograms will not help when it comes to minimizing them. But if your control has custom macro B (or any version of parametric programming), you can simplify the commands required for tool changing.

Even if you program with a computer aided manufacturing (CAM) system, you must consider how difficult it is for operators to run your programs. The techniques we show will simplify programming (especially for manual programmers), ensure consistency for tool changing commands, make your programs more fail-safe and make it easier for setup people and operators to rerun tools.

First, consider a typical series of commands that are needed when you make a tool change on a vertical machining center. Of course, the specific commands for your particular machine(s) will vary. Similar commands will be required for turning centers (or any multi-tool CNC machine tool).

N060 M09 (Turn off coolant)

N065 G91 G28 Z0 M19 (return to tool change position, orient spindle)

N070 T02 M06 (Place desired tool in spindle)

N075 G90 G54 S500 M03 T03 (Select absolute mode, fixture offset, start spindle and select next tool)

N080 G00 X1.5 Y2.0 (Rapid to first X and Y position)

N085 G43 H02 Z0.1 (Instate tool length compensation, rapid to first Z position)

N090 M08 (Start coolant)

Note that the structure of these commands will remain the same for every tool change you make. Only the values of the numbers in bold italics will change from tool change to tool change. Again, these commands are redundant and tedious to write. It's easy for manual programmers to forget key words or commands. Consider this custom macro call statement that can be used to invoke a special tool change custom macro.

N060 G65 P1000 T02 S500 X1.5 Y2.0 Z0.1 (Make tool change)

Page 16: Parametric Programming

When the custom macro (O1000) is executed, it will cause the machine to do everything done in the previous series of tool change commands. In our call statement, T represents the tool to be placed in the spindle. Our macro will assume that the tool to be used after this one follows in sequence (tool three in this case). If it does not, a W word (for waiting station) can be included in this command to specify which tool is coming up next in the program. We've left W out, so we're letting the custom macro assume that the next tool will be station three. S specifies the spindle speed, and X, Y and Z specify the tool's first approach position.

Here is the simple custom macro.

O1000 (Tool change custom macro)

IF [#23 NE #0] GOTO 1 (If W is included in call, skip default)

#23 = #20 +1 (Set next waiting station tool to next number in sequence)

N1 M09 (Turn off coolant)

G91 G28 Z0 M19 (Return to tool change position, orient spindle)

T#20 M06 (Place desired tool in spindle)

G90 G54 S#19 M03 T#23 (Select absolute mode, fixture offset, start spindle and select next tool)

G00 X#24 Y#25 (Rapid to first X and Y position)

G43 H#20 Z#26 (Instate tool length compensation, rapid to first Z position)

M08 (Start coolant)

M99 (End of custom macro)

We've taken the set of tool change commands and replaced those hard-and-fixed values that change from tool change to tool change with local variables (T is represented by #20, W by #23, S by #19, X by #24, Y by #25 and Z by #26). We have also set a default value for W (#23) if it's left out of the call statement. Look at the first two commands of the custom macro. If W is left out of the call statement (as it is in our example), the result of the IF statement will be false (W is vacant), and the next command (the default setting command) will be executed. #23 will be set to a value of whatever T (#20) is plus 1. If W is included in the call statement, #23 will have a value (#23 will not be vacant), the IF statement will be true and the default setting command will be skipped.

Though our example custom macro doesn't show it, you could also include words and commands

Page 17: Parametric Programming

in the tool change format custom macro to make your programs more fail-safe. For example, you could include G80 and G40 in line N1 (when the coolant is turned off) to ensure that canned cycles and cutter radius compensation have been canceled. Most manual programmers will not do this, because they assume they've programmed correctly. Right after the tool change command (M06), you could include some safety commands to confirm that certain modes are still in their initialized states. Consider these commands.

G17 G20 G40 (Set XY plane, inch mode, cancel cutter radius compensation)

G64 G69 G50.1 (Set normal cutting mode, cancel rotation, cancel mirror image)

G80 G94 (Cancel canned cycle, select feed per minute mode)

Again, these commands can be placed in the custom macro right after the tool change and will ensure that the machine is in appropriate states. This is most important for the first tool the first time the program is run.

What about rerunning tools? One important task that CNC setup people and operators must perform on a regular basis is rerun tools. Our tool change format custom macro still allows rerunning tools. Actually, it will simplify the task. The restart block for rerunning tools is simply the call statement (G65 command) for each tool change. Everything required for restarting tools, including a movement to the appropriate tool change position, is included in the custom macro.

Also, if your setup people and operators are currently restarting tools by scanning to the T word, they have to scan twice (assuming you have a machine with a double arm tool changer). The first time they scan, they find the command in which the tool is being placed in the waiting station. The second time, they find where it is actually being placed in the spindle. With the tool change custom macro, only one scan is required.

A more recent advancement in CNC interpreters is support of logical commands, known as parametric programming. Parametric programs incorporate both G-code and these logical constructs to create a programming language and syntax similar to BASIC. Various manufacturers refer to parametric programming in brand-specific ways. For instance, Haas Automation refers to parametric programs as macros. GE Fanuc refers to it as Custom Macro A & B, while Okuma refers to it as User Task 2. The programmer can make if/then/else statements, loops, subprogram calls, perform various arithmetic calculations, and manipulate variables to create a large degree of freedom within one program. An entire product line of different sizes can be programmed using logic and simple math to create and scale an entire range of parts, or create a stock part that can be scaled to any size a customer demands.

Parametric programming also enables custom machining cycles, such as fixture creation and bolt circles. If a user wishes to create additional fixture locations on a work holding device, the machine can be manually guided to the new location and the fixture subroutine called. The

Page 18: Parametric Programming

machine will then drill and form the patterns required to mount additional vises or clamps at that location. Parametric programs are also used to shorten long programs with incremental or stepped passes. A loop can be created with variables for step values and other parameters, and in doing so remove a large amount of repetition in the program body.

Because of these features, a parametric program is more efficient than using CAD/CAM software for large part runs. The brevity of the program allows the CNC programmer to rapidly make performance adjustments to looped commands, and tailor the program to the machine it is running on. Tool wear, breakage, and other system parameters can be accessed and changed directly in the program, allowing extensions and modifications to the functionality of a machine beyond what a manufacturer envisioned.

There are three types of variables used in CNC systems: local variable, common variable, and system variable. Local variable is used to hold data after machine off preset value. Common variable is used to hold data if machine switch off does not erase form data. The System variable this variable used system parameter this cannot use direct to convert the common variable for example tool radius, tool length, and tool height to be measured in millimeters or inches.

Typical logic to a parameter program is as follows;

First define variables to start your program. -bolt circle radius -how many holes -center point of bolt circleNext build a subprogram that crunches the math.When you are ready to drill or tap your holes, run the drill cycle off of your math in subprogram. tool-change-point..... T101 (REVOLVER 1 CORRECTION 1 TOOL CALL) G97 S1000 M3 (SPINDLE SPEED, ROTATION DIRECTION) offset pickup,etc ..... G43 ..... in some cases (tool length pickup) #100=15 (RADIUS) #101=10 (HOW MANY HOLES) #102=50 (REJUMP-PARAMETER) #103=0 (CIRCLE-CENTER X) #104=-10 (CIRCLE-CENTER Y) G81 ..... (DRILL CYCLE) GOTO 100 (JUMP TO SUBPROGRAM) N50 (REUSE THE SUBprogramm) #100=7.5 (RADIUS ROUND 2) #101=7 #102=51 GOTO 100 (JUMP TO SUBPROGRAM) N51 G80 (DEACTIVATE MODAL G81) M30 (SUBprogram) N100 (THIS LINE HERE IS USES AS A MARKER) #105=0 (INIT)

Page 19: Parametric Programming

N101 X[COS[#105]*#100+#103] Y[SIN[#105]*#100+#104] (REMEMBER YOUR G81 CODE IS MODAL) #105=#105+[360/#101] IF [#105 LT 360] GOTO 101 (IF #105 < 360 -> NEXT ROUND) GOTO #102

This is just a model to show the logic of programming. As all languages have some differences, the logic is all similar

1. Cutting Gears with Loops (Following is my generic-gear.ngc:) #1=25(number of teeth) #2=[360/#1](angle to turn chuck) #3=-.1(y clearance) #4=-.05(X start of cut) #5=2.2(X end of cut) #6=0(starting A position) #7=.7(feed rate infeed Y axis) #8=.394(depth of cut) #9=15(feed rate across X axis) G0 X#4 Y#3 G0 Z0 G0 A0 M3 S70 M8 o200 do

G1 Y[#8-.04] F#7G1 X#5 F#9G1 Y#8G1 X#4 F1.5G0 Y#3G0 X#4#6=[#6+#2]G0 A#6

o200 while[#6 lt 359.9] M5 M9 M2Notice that it does a rough cut across then climb mills back for a finish cut. Ed

2. Cutting Splines with Loops (Following is my generic-spline.ngc:) M6 T0 G43 H0 #1=27(number of splines) #2=[360/#1](angle to turn chuck) #3=-.1(y clearance) #4=-.05(X start of spline) #5=5(X end of spline) #6=0(starting A position) #7=3(feed rate) #8=.088(depth of cut) G0 X#4 Y#3 G0 Z0

Page 20: Parametric Programming

G0 A#6 M3 S200 M8 o200 do

G1 Y#8 F#7G1 X#5G0 Y#3G0 X#4#6=[#6+#2]G0 A#6

o200 while[#6 lt 359.9] M5 M9 M2 similar to the gear but does all cutting in a single pass. Both are using a cutter on an arbor in a vertical spindle. Ed

3. Thread Milling (3/4-16 thread milling) G0 X0 Y0 (rapid to location) Z.1 G01 Z-1.020 F50.0 (your finish location will vary depending on conditions always start with a smaller cut until you establish exact finish location) G91 G01 X.1275 F3.0 (incremental move to finish location speeds and feeds will vary with materials being cut) G03 Z.0625 I-.1275 F4.0 (incremental 3 axis move creates right hand thread to establish Z movement divide 1 by thread pitch) ( 1 divided by 16 = .0625) G90 G01 X0 F20.0 (absolute move back to start location) G01 Z-1.020 (absolute move down to starting Z location) G91 G01 X.1275 F6.0 (incremental move to finish location) G03 Z.0625 I-.1275 F6.0 (incremental 3 axis move) G03 Z.0625 I-.1275 F10.0 (optional free pass to remove any burrs) G90 G01 X0 F20.0 (absolute move back to start location) G0 Z3.0 M2

4. Using a while loop to make circular indents in the side of a hand wheel cat 110_mill_grips.ngc % (mill grips on other side, 3/8mill=9.5mm, 12 deep) (params) #1=-15 (drill depth) #2=10 (retraction interval) #100=-12 (depth) (fixed) (speed) F80 (reset) G0 Z5 G0 X0 Y0 G4 P5 (start round) #8=0 (angle in degrees) #9=30 (angle increment in degrees) O101 while [#8 lt 360] #5=32.30 (first step and start)

Page 21: Parametric Programming

#6=31.00 (second step) #7=35 (safe circle) (first step) G0 Z1 G0 X[#5 * cos] Y[#5 * sin] G1 Z[#100 + 0.06] G1 X[#7 * cos] Y[#7 * sin] (second step) G0 Z1 G0 X[#6 * cos] Y[#6 * sin] G1 Z#100 G1 X[#7 * cos] Y[#7 * sin] (increment angle) #8=[#8 + #9] (wait) (M0) O101 endwhile (end) G0 Z5 G0 X1 Y-1 G1 X0 Y0 G0 Z20 %

5. Simple Turning example using IF (simple turning) (#100 = max Z = start Z > #101) (#101 = min Z) (#200 = max X = start X > #201) (#201 = min X) (#300 = feed) (#400 = step size) (Z) #100 = 200 #101 = 0 (X) #200 = 17 #201 = 14 (FEED) #300 = 120 (STEP) #400 = 1 (END OF PARAMETERS) (set feed) F#300 (set current X) #250 = #200 O501 while [#250 gt #201] #250 = [#250 - #400] O502 if [#250 lt #201] #250 = O502 endif (goto start point, safety x 1mm) G0 X[#250 + #400 + 1] G0 Z#100 G0 X#250

Page 22: Parametric Programming

G1 F#300 Z#101 O501 endwhile (retract to orig X) (END) G0 X[#200 + 1] M2

1. IntroductionThe O word was devised by Ken Lerman as a way to implement several branching routines into the EMC interpreter. By using the O word a g code programmer can build subroutines, loops, and conditionals while taking advantage of the interpreter's use of variables and computation.

The canonical documentation for O-words is in the emc2 documentation: [1]. As clarifications and documentation improvements made on this page are incorporated in the official documentation, they should be removed from this page.

2. Notes

Each of these control blocks begins with an Onnnnn word. That makes easier for the parser to know what it is doing and isn't a problem for the user. I have to admit, though, that writing "call sub Onnnnn" seems more natural than writing "Onnnnn call sub".

Note that each block must start and end with the same Onnnnn word. So if you start with o100 the block ends at the next o100

Subroutine declarations may NOT be nested.

Subroutines may be called anywhere (but must be declared before they are called. They may be called from other subroutines, and may be called recursively if it makes sense.

while and if may be nested. They may not overlap without nesting.

When the interpreter scans a sub block, it remembers the location of the next line in the file and associates it with the "O" number. It continues scanning, skipping lines until it sees the matching Onnnnn endsub.

When the interpreter scans a callsub, it pushes (saves) the current location in the input file (on a stack). It then goes to the location in the file associated with the Onnnnn and starts interpretation there.

When the interpreter scans a return, it pops the stack and continues interpretation where it left off. When it interprets an endsub, it treats it like a return.

When the interpreter scans a while, it remembers the location of the Onnnnn. If the expression is true (values close to zero are treated as zero), it continues execution. If the expression was not true, it skips execution of all of the blocks until it finds the matching Onnnnn.

Page 23: Parametric Programming

When the interpreter scans an endwhile, it restarts interpretation at the location of the remembered Onnnnn. (Assumng it wasn't skipping. If it was skipping, it ignores the endwhile).

if is treated exactly as while.

The matching endif is ignored if the interpreter was skipping. Interpretation is turned back on (skipping is ended).

3. Sample ProgramsThese sample programs are offered without any warranty as to their suitability for any task whatsoever! Use these or model your program after these at your own risk.

3.1. Sample 1 -- One side of a ball in cage

Here is a short program that uses a ball end mill to create part of a sphere. The comments in the code explain what each variable does. There is no error checking so you could create sphere that doesn't exist. Here is emc2+axis running this program. [emc2axis] I am sure the program could be simplified also not 100% sure the math is right. Here is 4 sides done - [cube]

#1=1.25 (size of box)#2=.0625 (cutter radius)#3=.125 (size of box bars)#4=5 (degrees of resolusion)#5=#4 (COUNTER)#6=[[#1/2]+#2] (ACTUAL RADIUS OF CIRCLE - CUTTER RADIUS + RADIUS) G01X0Y0F10o140 do #8 = [[SIN[#5]*#6]*SIN[45]] ( X AND Y POSISION) #9 = [0-[[1-COS[#5]]*#6]] (Z HIGHT) G1X[#8]Y[#8]F3 Z[#9] G18 G02 X[0-#8]Z[#9]I[0-#8]K[0-[#9+[#6]]]F5 G19 G03 Y[0-#8]Z[#9]J[0-#8]K[0-[#9+[#6]]] G18 G03 X[#8]Z[#9]I[#8]K[0-[#9+[#6]]] G19 G02 Y[#8]Z[#9]J[#8]K[0-[#9+[#6]]] #5=[#5+#4]o140 while [#8 LT [#1/2-#2-#3]]G1Z1X0Y0M30

3.2. Sample 2 -- Subroutine Sample (ellipse)

Code originally by jepler, converted to gcode by KennethLerman (lerman), fixed by jepler. This code will machine an approximation to a ellipse.

(#1=xc #2=yc #3=xr #4=yr #5=subdiv #5=depth #7=rapid ht)o1000 sub (#10 = theta) (#11 = i) (#12 = x)

Page 24: Parametric Programming

(#13 = y) #14 = 360 #11 = 1 g0 x[#1+#3] y#2 g0 z#6 o1001 while [#11 LE #5] #10 = [#14 * #11 / #5] #12 = [#1 + [#3 * cos[#10]]] #13 = [#2 + [#4 * sin[#10]]] g1 x#12 y#13 #11 = [#11 + 1] o1001 endwhile g0 z#7 o1000 endsub (call it like this) f10 o1000 call [0] [0] [1] [2] [200] [-1] [2] m2

3.3. Sample 3 -- loops/math example (spirograph)I did this on a whim just to see if it could be done with the current math and loop abilities of emc2. Here is example output of the below program. [spiro]. I creates pretty big files - again not sure if everything is correct. Use at your own risk :).

#1=3.1 ( R in this formula {R+r}*cos{t} - {r+O}*cos{{{R+r}/r}*t} ) #2=2 ( r in above)#3=.6 ( O in above)#4=0 (starting t Deg)#5=.2 (deg of resolution)

(check which of the R/r is bigger)o100 if [abs[#1] GT abs[#2]]

#6=#1 (6 and 7 are temp locations for the R and r )#7=#2#8=1

o100 else#6=#2#7=#1#8=2

o100 endif

(now we make them whole numbers if they are not.)(this is the start of figuring the number of degrees)(it has to go to do a complete cycle.)#9=#6#10=#7#11=2o150 while [[fix[#6] NE #6] or [fix[#7] NE #7]]

#6=[#9*#11]#7=[#10*#11]#11=[#11+1]

o150 endwhile(now lets figure out if we can simplify the R/r fraction) (this is using Euclidean algorithm to get the gcd)

Page 25: Parametric Programming

#12=#6#13=#7

o200 do#14=[#12 mod #13]#12=#13#13=#14

o200 while [#13 NE 0](#12 is now the gcd)

(the Number of times around in degrees)(using the correct denominator.)o225 if[#8 eq 1]

#14=[[#7/#12]*360]o225 else

#14=[[#6/#12]*360]o225 endif

(here is the actual cutting - I don't have any z in it yet)o250 do

#15=[[#1+#2]*COS[#4] - [#2+#3]*COS[[[#1+#2]/#2]*#4]]#16=[[#1+#2]*sin[#4] - [#2+#3]*sin[[[#1+#2]/#2]*#4]]g1 x[#15]y[#16]f200#4=[#4+#5]

o250 while [#4 LE #14]m30

3.4. Sample 4, a subroutine for helical hole milling using radius compo100 sub (helical hole milling, load tool and set feed first, then use like so:) (o100 call [x pos] [y pos] [safety height] [hole depth] [hole dia] [tool dia]) (tool dia doesn't have to be specified exactly.)#7=[#6/2] (#7 is depth per circle = half of tool diameter)#8=#7 (#8 is current depth step)g0 z#3(start above and right so we make a convex corner for entry to the ccw arcs)g0 x[#1 + [#7 * 2]] y[#2 + [#5 / 2]]g41 g0 x#1 y[#2 + [#5 / 2]]o101 while [#8 LT #4](down toward the specified depth a bit at a time)g3 x#1 y[#2 + [#5 / 2]] i0 j[0 - [#5 / 2]] z[0 - #8]#8=[#8 + #7]o101 endwhile(down to the actual depth)g3 x#1 y[#2 + [#5 / 2]] i0 j[0 - [#5 / 2]] z[0 - #4](full circle at the actual depth)g3 x#1 y[#2 + [#5 / 2]] i0 j[0 - [#5 / 2]](nice quarter-circle helical exit move)g3 x[#1 - [#5 / 2]] y#2 i0 j[0 - [#5 / 2]] z#3g40o100 endsub

Page 26: Parametric Programming

(here is the actual usage: T1 is a 1/16th end mill)g20 g64 g17 g90t1 m6s1000 m3f5o100 call [0] [0] [.01] [.125] [.125] [.0625]o100 call [.25] [0] [.01] [.125] [.5] [.0625]t0 m6m2

Page 27: Parametric Programming