Haas CNC Macro Programming.doc

(377 KB) Pobierz
(see Macro Chapter, manual pages 157-179; January '97)

Programming with Macro's on the Haas CNC

10/14/00

 

 

 

 

 

 

 

 

 

 

 


 

·         Some familiarity with the Haas control and with G-code programming is assumed.

 


 

·         Definition - A macro is a form of sub-program that includes non-G-code commands.  It is typically a common operation that will be called many times.

·              Macro statements - Any non-G-code command.  Includes statements such as:  IF, WHILE, GOTO, math functions, and variables.  Haas requires that the macro parameter bit be set in order to interpret macro statements.  If it is not set, attempts to enter a macro statement during editing will result in an alarm.  If it is not set, macro statements within programs that are being loaded will be changed to comments.

·              Why? - A G-code program is rigid in structure.  It cannot be altered in mid-operation.  Offsets are the only things that can be used to alter machine path from one run to the next.  Macro's allow additional 'macro statements' that make it more flexible.

·              Macro Enable parameter bit – Parameter 57 bit 22.  This parameter allows for the entry of macro statements.  This parameter is used at the time of program entry not program execution.  If this parameter is turned off and a macro statement is entered, the control will ignore it.  If the program is loaded from a file, these statement will be converted to comments.  If the statement is loaded manually in MDI or edit modes, the control will give an alarm.


 

Problem #1:

·         Getting started- Start-up and zero control.  Select program 9000 and switch to edit mode.  Press reset before running any programs.  Edit programs in edit mode.  Run programs from mem mode.  Each program will build on the previous ones.

·         Go to the parameter page.  Find parameter 57 bit 22, “ENABLE MACRO”.  Set this parameter to ‘0’.

·         Go to the program page.  Attempt to enter the following block to the end of the program: #1124=1.  What happens?  What messages/alarms show up?

·         Go to the parameter page.  Find parameter 57 bit 22, “ENABLE MACRO”.  Set this parameter to ‘1’.

·         Go to the program page.  Attempt to enter the same block: #1124=1.  What happens?  What messages/alarms show up?

·         The program will look like this when finished:

O9000;

#1124=1;


 

G-codes:--

The following are G-codes that are of particular interest to the macro programmer.  They are available regardless of whether macro's are enabled.

M98 - Sub Program Call.  Pnnnn indicates the Onnnn of the program being called.  Lnn can be added to indicated the number of times the subprogram is to be called.  The subprogram must already be loaded into memory and must include an M99 to return to the main.  No arguments may be passed.

G65 - Macro subprogram call.  Allows arguments to be passed to subprogram.  Pnnnn indicates the Onnnn of the program being called.  Lnn can be added to indicated the number of times the subprogram is to be called.  Arguments are preceded with a command letter (A, B, etc.).  Arguments are copied to local variables #1-#26.

M97 - Local Sub Routine Call.  Pnnnn indicates beginning block number for subroutine.  Cannot branch to another program. 

M96 - Conditional Local Branch when Discrete Input Signal is 0.  Qnn designates which input to test.  Pnnnn designates the block to branch to if condition is true.  Cannot branch to another program.  Not available in DNC.  Not available with cutter comp.  Stops Look ahead until after test is complete.

M00 - Stop Program.  Halts program.  Cycle start will continue at next block.  Shuts off TSC.

M01 - Optional Program Stop.  Same as M00 except that it won't stop if option stop is not turned on at front panel.

M30 - Program End and Rewind.  Stops program.  Returns cursor to beginning of program.  Stops spindle, shuts off all coolant, and cancels all tool length offsets.

M99 - Sub Program/subroutine Return or Loop.  Returns control to the main from a subroutine or subprogram.  If it is in the main, it will continually loop back to the beginning of the program.  If a Pnnnn is included, it performs an unconditional jump to the block indicated.  This last mode is similar to the GOTO statement.

G103 - Block Lookahead Limit.  Blocks are prepared well in advance in order to produce smooth motion.  The number of blocks of Look ahead can be limited.  G103 P0 or G103 disable limits.  G103 Pnnnn indicates the number of blocks allowed to be viewed in advance.  The actual number is Pnn + 2.  This means that the lower limit is 3 blocks. Not available with cutter comp.

G04 - Dwell.  Pnnn indicates the dwell time.  If there is a decimal point, the units are in seconds.  If no decimal, the units are in milliseconds.


 

Problem #2:

·         Add 3 end-of-blocks (;) to the end of program O9000.  Run the program.  What happens to the cursor (highlighted block)?

·         Add M00 immediately after the ‘#1124=1;’.  Run the program.  What happens to the cursor (highlighted block)? Switch to the diagnostics page and locate the M21 output.  Rerun the program.  What happens to the output?

·         Replace M00 with M99.  Run the program.  What happens to the cursor (highlighted block)?  Switch to the diagnostics page and locate the M21 output.  Rerun the program.  What happens to the output?

·         Replace M99 with M30.  Run the program.  What happens to the cursor (highlighted block)?  Switch to the diagnostics page and locate the M21 output.  Rerun the program.  What happens to the output?

·         Delete the end-of-blocks at the end of the program. The program will look like this when finished:

O9000;

#1124=1;

M30;


 

Problem #3:

·         Add ‘G04 P2.; #1124=0;’ immediately before the M30.  Switch to the diagnostics page and locate the M21 output.  Run the program and observe the status of this output.  What happened?  When did the output turn on and off?

·         Add ‘G103 P1;’ immediately after the O9000.  Switch to the diagnostics page and locate the M21 output.  Run the program and observe the status of this output.  What happened?  When did the output turn on and off?

·         Add 3 end-of-blocks (;) between the G103 P1 and the #1124=1.  Add another 3 end-of-blocks (;) between the G04 P2. and the #1124=0.  Switch to the diagnostics page and locate the M21 output.  Run the program and observe the status of this output.  What happened?  When did the output turn on and off?

·         The program will look like this when finished:

O9000;

G103 P1;

;

;

;

#1124=1;

G04 P2.;

;

;

;

#1124=0;

M30;


 

·              Parentheses – Parentheses are used to enclose comments.  They indicate text that will not be executed as a part of the g-code program.  They are also used in conjunction with certain macro variables to provide the text for a programmable stop or alarm. Multiple levels of parentheses are not allowed (i.e. ((text)text) is not allowed ).   An opening parenthesis, (, must always have a close, ).

·              Comments are used to add notes to the program code.  They can describe revisions, document program flow in English, and even give a program a name.

·              With macro’s disabled, any block that contains a macro statement will be converted to comments.  The comment will begin with a question mark.  This will occur at the time the file is loaded into the control.  (i.e. (? #1=#1+#3)  )

·              Brackets – Brackets are used to control the order of execution of expressions within a g-code program.  Expressions within the innermost set of brackets are executed first.  Multiple levels of brackets are allowed (i.e. ABS[[3+1]*2] is acceptable).  An opening bracket, [, must always have a close, ].

·              Line Numbers – Line numbers are a way of assigning a label to a block.  Nnn may be placed anywhere on the line however it is typically in the beginning.  They are optional.  Line numbers can be used with sub-routine calls.  Nnn indicates the target of a M99 Pnn, M97 Pnn, or GOTOnn statement.


 

·              Aliasing – Aliasing is the act of assigning a name (G-code) to a specific program.  Macro's are typically a subprogram, not a stand-alone program.  They are called via G65 or M98.  This subprogram call can be replaced with a single M- or G-code.   The assignment of this new code to a program takes place throught parameters 81-100.  Only programs O9000 to O9019 may be aliased.

·              When aliased to a G-code, variables may be passed.  With an M-code, variables may not be passed.

·              This is particularly useful when assigning a function to an M-code.  (For example, M50 performs a pallet change on a vertical.  M50 is aliased to program O9001.)


 

Problem #4:

·         Modify program O9000. Change the M30 to an M99.

·         Start a new program, O0010.  Using any sub-program call (aliasing,  M98, or G65), write a line that will call program O9000.  End this program with an M30.

·         Enable single block mode. (press single block button).

·         Step through program O0010 using cycle start.  Is program O9000 called properly?  What happens when the M99 in program O9000 is reached?



 

·              Variables - Variables provide great flexibility in macro programming.  They can be changed manually as well as by the program itself.  Variables always numbered and follow a # sign.  E.g. #1, #1100, #33.  Variables can be a maximum of four digits.  Both local and global variable can be viewed and edited in the macro variable page of the current commands display.  Although system variables can be written to and read from, they cannot be viewed.  Parameters and settings cannot be accessed using macro variables.  Variables can replace any constant in a G-code command (e.g. G00 X#100).  Variables may be nested (e.g. #[#100]) to provide indirect addressing

·              Local variables  - Local variables are in the range of #1 to #33.  These are cleared after each G65 call.  Local variables are used to transfer data from the main to the macro (on the G65 line).  They can also be used as disposable storage locations.  Note that when passing variables, either normal or alternate addressing will be selected, not both.

·              In a source file, data can be passed to a subprogram.  See Appendix C.  The data is assigned to a variable depending upon the alphabetic code used.  For example, a G65 P12 X1. T3. is a sub-progarm call to program O0012.  As program O0010 is run, the X and T data will be available in variables #24 and #20 respectively.  If multiple IJK’s are present, then the alternate addressing is assumed.

·              Global variables - Global variables are in the range of #100-199 and #500-699.  These are not cleared with each G65 call. 

·              System variables - System variables are always four digits.  They provide a way to interact with the machine operation.  They can be used to read and write to the discrete I/O.  They provide access to all offsets, positions, timers, programmable alarms,  and modal group codes.  See pages 163-167 for a more detailed description.

·              Macro variables can be viewed on the Current commands page.

·              Global macro variables are typically rounded in the last digit.  For example, a 5 may be stored as 4.999999.  This is particularly true of math operations.  The statement  6/2 may be evaluated as 3.000001.  6/2+6/2 could have a answer anywhere in the range 5.999998 to 6.000002.  If this value were then compared with 6, the answer may be true or false depending on the the rounding.  This must be accounted for when using these variables.  If a program is expecting a whole number, it is frequently useful to use the ROUND function described later.


 

·              Operators - Operators are symbols and commands that modify data.  They are classified as Arithmetic, Logical, and Boolean.  Results from an operator can be integers (or binary), floating point, or true(1)/false(0).

·              Arithmetic operators - Arithmetic operators perform simple math functions.  They are +, -, *, /, and MOD.  Plus and minus may also be used to indicate the sign of the data.  Arithmetic operators may not be used in conditional statements.  MOD performs a division and outputs the remainder.  */ are executed before +-.  x MOD y is the same as x/y® remainder.  (1+2, #1022-1)

·              Logical operators - Logical operators work on binary bit numbers.  When performed on a floating point number, only the integer part will be used.  These operators are OR, AND, and XOR.  (#100 AND #22, #500 XOR 4)

·              Boolean operators - Boolean operators are always evaluated as true(1) or false(0).  They are EQ, NE, GT, LT, GE, and LE.  (#100 EQ 0, #33 LE 4.5)


 

Problem #5:

·         Turn off single block mode.

·         Add a counter to program O9000.  This counter should increment by one, every time the program is run.  Use any variable in the range 100 to 199. 

·         A counter is a variable that increments by 1 every time the program is run.  They typically look like:  #100=#100+1.

·         Run program O0010.  Observe the value of the counter variable.  Does it increment properly?


 

·              Functions - Functions are mathematical operations.  They are complex routines that simplify programming. 

·              The functions are SIN, ASIN, COS, ACOS, TAN, ATAN, SQRT, ABS, ROUND, and FIX. 

·              ABS returns the absolute value of the given decimal. 

·              ROUND rounds off a decimal. 

·              FIX returns the whole number portion of a fraction with no rounding.  If FIX is used in an arithmetic expression, it will round to the nearest whole number.  If it used as an address, the fraction is rounded to the addresses significant precision.  (i.e. X[ROUND[#1]] will round to 0.xxxx decimal places).  (SQRT[4.], COS[#100]).

·              DPRNT is a special function that allows data or text to be sent to the serial port.


 

·              Expressions - Expressions are defined as a sequence of variables and values surrounded by brackets [ ]. 

·              An entire expression can be assigned to a variable.  For example, suppose #100=10 and #510=3.  The expression #101= #[#100 +500] would load variable #101 with the value 3.  This method is very useful when working with look-up tables.

·              Arithmetic Expressions - Arithmetic Expressions produce a floating point number or integer.  They can be used as stand alone in the form of assignments or in conjunction with other G-codes.  (#3=[#3+1]*2, X[#501-#22], #[#2+2]=0)

·              Conditional Expressions - Conditional Expressions produce a value that is either true(1) or false(0).  They are used in conjunction with IF and WHILE.  (IF [#100 EQ 4.5] THEN GOTO20, #2=[#4 GT 9.2])


 

Problem #6:

·         Modify program O0010 so that the sub-progr...

Zgłoś jeśli naruszono regulamin