• No results found

Operating Safety Precautions

Chapter 6 CONDITION HANDLERS

6.1 CONDITION HANDLER OPERATIONS

6.1.1 Global Condition Handlers

Global condition handlers are defined by executing a CONDITION statement in the executable section of a program. The definition specifies conditions/actions pairs. The following rules apply to global condition handlers.

Each global condition handler is referenced throughout the program by a specified number, from 1 to 1000. If a condition handler with the specified number was previously defined, it must be purged before it is replaced by the new one.

The conditions/action s pairs of a global condition handler are specified in the WHEN clauses of a CONDITION statement. All WHEN clauses for a condition handler are enabled, disabled, and purged together.

The condition list represents a list of conditions to be monitored when the condition handler is scanned.

By default, each global condition handler is scanned at a rate based on the value of

$SCR.$cond_time. If the “WITH $SCAN_TIME = n” clause is used in a CONDITION statement, the condition will be scanned roughly every “n” milliseconds. The actual interval between the scans is determined as shown inTable 6–4.

6. CONDITION HANDLERS MARRC75KR07091E Rev H

Table 6–4. Interval Between Global Condition Handler Scans

"n" Interval Between Scans

n <= $COND_TIME $COND_TIME

$COND_TIME < n <= (2 * $COND_TIME) (2 * $COND_TIME) (2 * $COND_TIME) < n <= (4 * $COND_TIME) (4 * $COND_TIME) (4 * $COND_TIME) < n <= (8 * $COND_TIME) (8 * $COND_TIME) (8 * $COND_TIME) < n <= (16 * $COND_TIME) (16 * $COND_TIME) (16 * $COND_TIME) < n <= (32 * $COND_TIME) (32 * $COND_TIME) (32 * $COND_TIME) < n <= (64 * $COND_TIME) (64 * $COND_TIME) (64 * $COND_TIME) < n <= (128 * $COND_TIME) (128 * $COND_TIME) (128 * $COND_TIME) < n <= (256 * $COND_TIME) (256 * $COND_TIME)

(256 * $COND_TIME) < n (512 * $COND_TIME)

Multiple conditions must all be separated by the AND operator or the OR operator. Mixing of AND and OR is not allowed.

If AND is used, all of the conditions of a single WHEN clause must be satisfied simultaneously for the condition handler to be triggered.

If OR is used, the actions are triggered when any of the conditions are TRUE.

The action list represents a list of actions to be taken when the corresponding conditions of the WHEN clause are simultaneously satisfied.

Multiple actions must be separated by a comma or a new line.

Global Condition Handler Definitionsshows three examples of defining global condition handlers.

See Also: $SCR.$cond_time System Variable, FANUC America Corporation Software Reference Manual $SCAN_TIME Condition Handler Qualifier, FANUC America Corporation Software Reference Manual

Global Condition Handler Definitions

CONDITION[1]: --defines condition handler number 1

WHEN DIN[1] DO DOUT[1] = TRUE --triggered if any one WHEN DIN[2] DO DOUT[2] = TRUE --of the WHEN clauses WHEN DIN[3] DO DOUT[3] = TRUE --is satisfied

ENDCONDITION

CONDITION[2]: --defines condition handler number 2

WHEN PAUSE DO --one condition triggers

AOUT[speed_out] = 0 --multiple actions

MARRC75KR07091E Rev H 6. CONDITION HANDLERS

ENDCONDITION --handler again

CONDITION[3]:

WHEN DIN[1] AND DIN[2] AND DIN[3] DO --multiple DOUT[1] = TRUE --conditions separated by AND;

DOUT[2] = TRUE --all three conditions must be DOUT[3] = TRUE --satisfied at the same time ENDCONDITION

You can enable, disable, and purge global condition handlers as needed throughout the program.

Whenever a condition handler is triggered, it is automatically disabled, unless an ENABLE action is included in the action list. (See condition handler 2 inGlobal Condition Handler Definitions.)

— The ENABLE statement or action enables the specified condition handler. The condition handler will be scanned during the next scan operation and will continue to be scanned until it is disabled.

— The DISABLE statement or action removes the specified condition handler from the group of scanned condition handlers. The condition handler remains defined and can be enabled again with the ENABLE statement or action.

— The PURGE statement deletes the definition of the specified condition handler.

ENABLE, DISABLE, and PURGE have no effect if the specified condition handler is not defined.

If the specified condition handler is already enabled, ENABLE has no effect; if it is already disabled, DISABLE has no effect.

Using Global Condition Handlersshows examples of enabling, disabling, and purging global condition handlers.

Using Global Condition Handlers

CONDITION[1]: --defines condition handler number 1 WHEN line_stop = TRUE DO DOUT[1] = FALSE

ENDCONDITION

CONDITION[2]: --defines condition handler number 2 WHEN line_go = TRUE DO

DOUT[1] = TRUE, ENABLE CONDITION [1]

ENDCONDITION

ENABLE CONDITION[2] --condition handler 2 is enabled . . .

IF ready THEN line_go = TRUE; ENDIF

--If ready is TRUE condition handler 2 is triggered (and --disabled) and condition handler 1 is enabled.

--Otherwise, condition handler 2 is not triggered (and is --still enabled), condition handler 1 is not yet enabled, --and the next two statements will have no effect.

DISABLE CONDITION[1]

ENABLE CONDITION[2]

6. CONDITION HANDLERS MARRC75KR07091E Rev H

. . .

ENABLE CONDITION[1] --condition handler 1 is enabled . . .

line_stop = TRUE --triggers (and disables) condition handler 1 . . .

PURGE CONDITION[2] --definition of condition handler 2 deleted ENABLE CONDITION[2] --no longer has any effect

line_go = TRUE --no longer a monitored condition

6.2 CONDITIONS

One or more conditions are specified in the condition list of a WHEN or UNTIL clause, defining the conditions portion of a conditions/actions pair. Conditions can be

States - which remain satisfied as long as the state exists. Examples of states are DIN[1] and (VAR1 > VAR2).

Events - which are satisfied only at the instant the event occurs. Examples of events are ERROR[n], DIN[n]+, and PAUSE.

The following rules apply to system and program event conditions:

After a condition handler is enabled, the specified conditions are monitored.

— If all of the conditions of an AND, WHEN, or UNTIL clause are simultaneously satisfied, the condition handler is triggered and corresponding actions are performed.

— If all of the conditions of an OR, WHEN, or UNTIL clause are satisfied, the condition handler is triggered and corresponding actions are performed.

Event conditions very rarely occur simultaneously. Therefore, you should never use AND between two event conditions in a single WHEN or UNTIL clause because, both conditions will not be satisfied simultaneously.

While many conditions are similar in form to BOOLEAN expressions in KAREL, and are similar in meaning, only the forms listed in this section, not general BOOLEAN expressions, are permitted.

Expressions are permitted within an EVAL clause. More general expressions may be used on the right side of comparison conditions, by enclosing the expression in an EVAL clause: EVAL (expression). However, expressions in an EVAL clause are evaluated when the condition handler is defined. They are not evaluated dynamically.

The value of an EVAL clause expression must be INTEGER, REAL, or BOOLEAN.

See Also: EVAL Clause,Appendix A.

MARRC75KR07091E Rev H 6. CONDITION HANDLERS