Structured Logic 

The post offers limited structured logic capabilities. This functionality allows logical decisions when necessary. The following describes the format and required syntax.

IF, ELSE, and ENDIF Statements 

Here's a sample of a ToolChange sequence that uses if/then logic in 2 different places - first, to control dual-range spindle speed (M41, M42), then again to suppress the “pre-indexing” in the last tool change. (blank lines have been added for clarity to separate the "logic" sections from the rest of the sequence):

ToolChange

M9

G28 G49 Z0 S100

N[Block] M6

            This 'IF' structure sets the 'gear range' (M41 or 42):

if [Speed] > 500

 G0 G40 G[80] G[Work] X[H] Y[V] M[42]

else

 G0 G40 G[80] G[Work] X[H] Y[V] M[41]

endif

G43 Z[D] H[Lcomp] M[Direct] S[Speed]

M[Cool]

This one suppresses pre-indexing of the last Tool:

if [NextTool] <> [Tool1]  

 T[NextTool]

endif

End

 

...as you can see from the example above…

Here are the actual “rules” that apply to the if / then logic:

The IF line must have a variable or a number followed by a 1 or 2-character “logical operator”, then another variable or number. As usual, all items must be separated by a single space. The optional Else line and the required Endif line do not use any "parameters". Here are some sample "If" lines:

IF [Val1] = 2

If [Tool] > 24

if [speed] <= 500

(Note: Just as with all variable, sequence and command names, please notice that the capitalization of the words If, Else and EndIf doesn't matter.)

This is a list of the legal logical operators that can be used on the if line:

Operator
>
<
=
<>
<=
>=

 

Meaning
“Greater than”
“Less Than”
“Equals”
“does not equal”
“is less than or equal to”
“is greater than or equal to”
 

 

 

 

Restrictions

   1.   IF can only be used within a sequence or canned cycle.

   2.   An ENDIF line is required (even if there are no more lines after ENDIF within that sequence).

   3.   The ELSE line is optional.

   4.   The IF, ELSE and ENDIF lines must have at least 1 line of “code” between them.

   5.   IF statements cannot yet be nested.

   6.   You are limited to fifty IF structures within each machine format area.

Testing 2 conditions: Using AND and OR with IF

You can use the words AND and OR to make an IF function test for 2 conditions at a time as in the following examples:

if [Tool] > 5 OR [Val1] = 1

 ...do these lines...

ENDIF

if [LastHole] <> 1 AND [SpeedType] < 97

 ...do these lines...

ENDIF

Operators 

Legal operators are >, <, =, <> (not equal), <= and >=

Following is an example of a tool change sequence using logic to control dual-range spindle speed (M41,M42) and suppression of the pre-indexing of the last tool. (Blank lines were added for clarity to separate the “logic” sections from the rest of the sequence):

Toolchange

M<9>

G<28> G<49> Z<0> S<100>

N<Block> M<6>

This "IF" structure sets the "gear range" (M41 or 42):

IF [Speed]>500

G<0> G<40> G<80> G<Work> X<H> Y<V> M<42>

ELSE

G<0> G<40> G<80> G<Work> X<H> Y<V> M<41>

ENDIF

G<43> Z<D> H<Lcomp> M<Direct> S<Speed>

M<Cool>

Here the pre-indexing of the last Tool is suppressed:

IF [NextTool] <> [Tool1]

T<NextTool>

ENDIF

END

As you can see, either one or both of the 2 values must be a [variable]. It may be a variable that is set from an ASK statement—letting you give the operator a set of processing “options.”

The Set Command 

The SET command allows a variable to be set to any other variable or constant. Place this within an IF structure, and you can set a variable to a number.

Following is an example of how to support spindle ranges:

1stToolchange

 

G0 G90 G80 G40 G17

 

T[Tool] M6

 

 

 

Set [Val2] to 65

This line sets the “default” spindle range.

 

 

If [Speed] > 1000

This is the “IF” line.

Set [Val2] to 66

Replace the line of code with a "SET"...

endif

 

 

 

If [Speed] > 2000

...and we do it again—one If/Set structure for

Set [Val2] to 67

each range you want.

endif

 

 

 

If [Speed] > 3000

 

Set [Val2] to 68

 

endif

 

 

 

If [Speed] > 4000

 

Set [Val2] to 69

 

endif

 

 

 

G[Val2] M[Direct] S[Speed]

This line will output the code you want.

 

 

G0 G[Work] X[H] Y[V]

 

G43 Z[D] H[Lcomp]

 

M[Cool]

 

End 

 

Return to SURFCAM Index


Your Ad Here