Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

If - or statement?


Recommended Posts

So I am looking to have an option set with a MI to have a slow tool change. I would like to have a flag to have it then do a slow tool change to remove the tool also, so for my tool changes, I am looking to have a flag and on my tool change have a logic that goes something like this:

 

If MIxx = 1 and/or Flag = 1 M306

else M6

If MIxx = 1, Flag =1

else flag = 0

 

How can I format that?

 

Thanks

Link to comment
Share on other sites

Ok, here is what I came up with....using mpfan...

 

First define your "flag" variable. (I used dsv)

 

# --------------------------------------------------------------------------
# Toolchange / NC output Variable Formats
# --------------------------------------------------------------------------
fmt "T" 4 t$ #Tool number
fmt "T" 4 first_tool$ #First tool used
fmt "T" 4 next_tool$ #Next tool used
fmt "D" 4 tloffno$ #Diameter offset number
fmt "H" 4 tlngno$ #Length offset number
fmt "G" 4 g_wcs #WCS G address
fmt "P" 4 p_wcs #WCS P address
fmt "S" 4 speed #Spindle Speed
fmt "M" 4 gear #Gear range
fmt 4 dsv #hold last value of mi4

Then start with the psof postblock.... you can see what I added between the ####################

 

 

psof$ #Start of file for non-zero tool number
pcuttype
toolchng = one
if ntools$ = one,
[
#skip single tool outputs, stagetool must be on
stagetool = m_one
!next_tool$
]
pbld, n$, *smetric, e$
pbld, n$, *sgcode, *sgplane, scc0, sg49, sg80, *sgabsinc, e$
sav_absinc = absinc$
if mi1$ <= one, #Work coordinate system
[
absinc$ = one
pfbld, n$, sgabsinc, *sg28ref, "Z0.", e$
pfbld, n$, *sg28ref, "X0.", "Y0.", e$
pfbld, n$, sg92, *xh$, *yh$, *zh$, e$
absinc$ = sav_absinc
]
pcom_moveb
pcheckaxis
c_mmlt$ #Multiple tool subprogram call
ptoolcomment
comment$
pcan
#################
if mi4$ = 1,
[
pbld, n$, *t$, "M306", e$
]
else,
[
pbld, n$, *t$, sm06, e$
]
if mi4$ = 1,
[
dsv = 1
]
else,
[
dsv = 0
]
##################
pindex
if mi1$ > one, absinc$ = zero
pcan1, pbld, n$, *sgcode, *sgabsinc, pwcs, pfxout, pfyout, pfcout,
[if nextdc$ <> 7, *speed, *spindle], pgear, strcantext, e$
pbld, n$, sg43, *tlngno$, pfzout, scoolant, pstagetool, e$
absinc$ = sav_absinc
pbld, n$, sgabsinc, e$
pcom_movea
toolchng = zero
c_msng$ #Single tool subprogram call

Then do the ptlchg postblock, I added what you see between the ################

 

ptlchg$ #Tool change
pcuttype
toolchng = one
if mi1$ = one, #Work coordinate system
[
pfbld, n$, *sg28ref, "X0.", "Y0.", e$
pfbld, n$, sg92, *xh$, *yh$, *zh$, e$
]
if prog_stop = 1, pbld, n$, *sm01, e$
if prog_stop = 2, pbld, n$, *sm00, e$
pcom_moveb
pcheckaxis
c_mmlt$ #Multiple tool subprogram call
ptoolcomment
comment$
pcan
result = newfs(15, feed) #Reset the output format for 'feed'
#########################
if mi4$ = 1 | dsv = 1,
[
pbld, n$, *t$, "M306", e$
]
else,
[
pbld, n$, *t$, sm06, e$
]
if mi4$ = 1,
[
dsv = 1
]
else,
[
dsv = 0
]
############################
pindex
sav_absinc = absinc$
if mi1$ > one, absinc$ = zero
pcan1, pbld, n$, *sgcode, *sgabsinc, pwcs, pfxout, pfyout, pfcout,
[if nextdc$ <> 7, *speed, *spindle], pgear, strcantext, e$
pbld, n$, sg43, *tlngno$, pfzout, scoolant, pstagetool, e$
absinc$ = sav_absinc
pbld, n$, sgabsinc, e$
pcom_movea
toolchng = zero
c_msng$ #Single tool subprogram call
!xnci$, !ynci$, !znci$

 

Here is what I get....

 

%
O0000(TEST)
(DATE=DD-MM-YY - 10-08-12 TIME=HH:MM - 11:26)
(MCX FILE - C:\DOCUMENTS AND SETTINGS\KEITHG\MY DOCUMENTS\DOWNLOADS\TEST.MCX-6)
(NC FILE - C:\DOCUMENTS AND SETTINGS\KEITHG\MY DOCUMENTS\MY MCAMX6\MILL\NC\TEST.NC)
(MATERIAL - ALUMINUM INCH - 2024)
( T157 | 3/4 DRILL | H157 )
( T122 | LTR. R DRILL | H122 )
( T227 | 1-3/4-5 TAPRH | H227 )
N100 G20
N102 G0 G17 G40 G49 G80 G90
N104 T157 M6
N106 G0 G90 G54 X-.9149 Y.4969 A0. S356 M3
N108 G43 H157 Z.1
N110 G99 G81 Z0. R.1 F4.28
N112 X-1.066 Y.7908
N114 G80
N116 M5
N118 G91 G28 Z0.
N120 A0.
N122 M01
N124 T122 M306
N126 G0 G90 G54 X.5405 Y.7435 A0. S788 M3
N128 G43 H122 Z.1
N130 G99 G81 Z0. R.1 F4.16
N132 X.9587 Y.3703
N134 G80
N136 M5
N138 G91 G28 Z0.
N140 A0.
N142 M01
N144 T157 M306
N146 G0 G90 G54 X-.9036 Y-.6018 A0. S356 M3
N148 G43 H157 Z.1
N150 G99 G81 Z0. R.1 F4.28
N152 X-.5794 Y-1.2038
N154 G80
N156 M5
N158 G91 G28 Z0.
N160 A0.
N162 M01
N164 T227 M6
N166 G0 G90 G54 X1.1746 Y-1.1551 A0. S152 M3
N168 G43 H227 Z.1
N170 G99 G81 Z0. R.1 F30.56
N172 X1.3114 Y-1.4064
N174 X1.2166 Y-1.5877
N176 G80
N178 M5
N180 G91 G28 Z0.
N182 G28 X0. Y0. A0.
N184 M30
%

 

mi4 was set to 1 in the second operation.....

 

I didn't do anything with the null toolchange postblock, let me know if you have trouble with that.

HTH!

Link to comment
Share on other sites
Guest CNC Apps Guy 1

Here's all the

Formula descriptions.

 

HTH

 

Formula descriptions

 

= (assignment)

Formula Type Basic math functions

Description Assignment

Form result assignment argument

result assignment function argument

result assignment argument operator argument

Return Type Depends on formula

Formula Code Ex. x = y

x = y + z

c = atan2(x, y)

Boolean Code Ex. Not interpreted in conditional branching statement

Notes These are the basic assignment forms. They may be combined as

required.

 

+

Formula Type Basic math functions

Description Addition

Form argument operator argument

First Argument numeric variable, value (scalar)

string variable

Second Argument numeric variable, value (scalar)

string variable

Return Type numeric variable (scalar)

string variable

Formula Code Ex. x = y – z

string1 = string2 + string3

Boolean Code Ex. if (x + y) = 2, p_action

if (string1 + string2) = string3, p_action

Notes Argument types must match. A maximum of 10 string variables may

be added (concatenated) in a single formula.

 

-

Formula Type Basic math functions

Description Subtraction

Form argument operator argument

First Argument numeric variable, value (scalar)

Second Argument numeric variable, value (scalar)

Return Type numeric variable (scalar)

Formula Code Ex. x = y – z

Boolean Code Ex. if (x – y) = 2, p_action

Notes

 

– (unary)

Formula Type Basic math functions

Description Unary minus

Form operator argument

First Argument numeric variable (scalar)

Second Argument numeric variable (scalar)

Return Type numeric variable (scalar)

Formula Code Ex. x = –y

x = y * (–z)

Boolean Code Ex. if -x = 2, p_action

Notes Do not use multiple unary operators, for example, – – –x.

 

*

Formula Type Basic math functions

Description Multiplication

Form argument operator argument

First Argument numeric variable, value (scalar)

Second Argument numeric variable, value (scalar)

Return Type numeric variable (scalar)

Formula Code Ex. x = y * z

Boolean Code Ex. if (x * y) = 2, p_action

Notes

 

/

Formula Type Basic math functions

Description Division

Form argument operator argument

First Argument numeric variable, value (scalar)

Second Argument numeric variable, value (scalar)

Return Type numeric variable (scalar)

Formula Code Ex. x = y / z

Boolean Code Ex. if (x / y) = 2, p_action

Notes Avoid having a denominator of 0. This condition generates a fatal

“divide by zero” error.

 

^

Formula Type Basic math functions

Description Power. Raises the first argument to the power of the second argument.

Form argument operator argument

First Argument numeric variable, value (scalar)

Second Argument numeric variable, value (scalar)

Return Type numeric variable (scalar)

Formula Code Ex. x = y ^ z

Boolean Code Ex. if (x^ y) = 25, p_action

Notes

 

= (Boolean)

Formula Type Logic operators

Description Logical comparison. True if values are equal.

Form argument operator argument

First Argument numeric variable, value (scalar)

string variable

Second Argument numeric variable, value (scalar)

string variable

Return Type numeric variable (Boolean result)

string variable

Formula Code Ex. real_result = x = y

real_result = string1 = string2

Boolean Code Ex. if x = y, p_action

if string1 = string2, p_action

Notes Argument types must match. The return is 0 if false and 1 if true.

Nested return values are stored internally to the post executable.

 

<

Formula Type Logic operators

Description Logical comparison. True if first argument is less than second

argument.

Form argument operator argument

First Argument numeric variable, value (scalar)

Second Argument numeric variable, value (scalar)

Return Type numeric variable (Boolean result)

Formula Code Ex. real_result = x < y

Boolean Code Ex. if x < y, p_action

Notes The return is 0 if false and 1 if true. Nested return values are stored

internally to the post executable.

 

>

Formula Type Logic operators

Description Logical comparison. True if first argument is greater than second

argument.

Form argument operator argument

First Argument numeric variable, value (scalar)

Second Argument numeric variable, value (scalar)

Return Type numeric variable (Boolean result)

Formula Code Ex. real_result = x > y

Boolean Code Ex. if x > y, p_action

Notes The return is 0 if false and 1 if true. Nested return values are stored

internally to the post executable.

 

<=

Formula Type Logic operators

Description Logical comparison. True if first argument is less than or equal to the

second argument.

Form argument operator argument

First Argument numeric variable, value (scalar)

Second Argument numeric variable, value (scalar)

Return Type numeric variable (Boolean result)

Formula Code Ex. real_result = x <= y

Boolean Code Ex. if x <= y, p_action

Notes The return is 0 if false and 1 if true. Nested return values are stored

internally to the post executable.

 

>=

Formula Type Logic operators

Description Logical comparison. True if first argument is greater than or equal to

the second argument.

Form argument operator argument

First Argument numeric variable, value (scalar)

Second Argument numeric variable, value (scalar)

Return Type numeric variable (Boolean result)

Formula Code Ex. real_result = x >= y

Boolean Code Ex. if x >= y, p_action

Notes The return is 0 if false and 1 if true. Nested return values are stored

internally to the post executable.

 

<>

Formula Type Logic operators

Description Logical comparison. True if values are not equal.

Form argument operator argument

First Argument numeric variable, value (scalar)

string variable

Second Argument numeric variable, value (scalar)

string variable

Return Type numeric variable (Boolean result)

Formula Code Ex. real_result = x <> y

real_result = string1 <>string2

Boolean Code Ex. if x <> y, p_action

if string1 <> string2, p_action

Notes Argument types must match. The return is 0 if false and 1 if true.

Nested return values are stored internally to the post executable.

 

&

Formula Type Logic operators

Description Logical “and”.

Arg1 Arg2 Result

1 1 1

1 0 0

0 1 0

0 0 0

Form argument operator argument

First Argument numeric variable, value (scalar)

Second Argument numeric variable, value (scalar)

Return Type numeric variable (Boolean result)

Formula Code Ex. real_result = x & y

Boolean Code Ex. if x & y, p_action

Notes The return is 0 if false and 1 if true. Nested return values are stored

internally to the post executable.

 

|

Formula Type Logic operators

Description Logical “or”.

Arg1 Arg2 Result

1 1 1

1 0 1

0 1 1

0 0 0

Form argument operator argument

First Argument numeric variable, value (scalar)

Second Argument numeric variable, value (scalar)

Return Type numeric variable (Boolean result)

Formula Code Ex. real_result = x | y

Boolean Code Ex. if x | y, p_action

Notes The return is 0 if false and 1 if true. This character is the “pipe”

character (ASCII decimal equivalent 124). Nested return values are

stored internally to the post executable.

 

(, )

Formula Type Precedence function

Description Open and close parentheses are used to control the precedence of

operation. Depending on the nesting levels, the formulas nested

deepest are evaluated first.

Form operator argument operator

Formula Code Ex. real_result = (x * (2 + y)) ^ z / (x – y)

Boolean Code Ex. if (x > 2 & x <> 3) | (fmtrnd(y) & fmtrnd(z)), p_action

Notes Nesting parentheses must always match the open parenthesis to the

closing parenthesis. Do not confuse the parentheses used in the

formula functions (for example, abs(x)) with those used for precedence

nesting.

 

abs

Formula Type Advanced Math Functions

Description Returns the absolute value of the argument.

Form function argument

Argument numeric variable, value (scalar)

Return Type numeric variable (scalar) as a positive value

Formula Code Ex. real_result = abs(x)

Boolean Code Ex. if abs(x) < mtol, “THIS IS A SMALL NUMBER”

Notes Nested return values are stored internally to the post executable.

 

acos

Formula Type Trigonometric function

Description Arc cosine. Returns the ratio of the adjacent angle to the hypotenuse of

a right triangle.

Form function argument

Argument numeric variable, value (scalar)

Return Type numeric variable (angle)

Formula Code Ex. real_result = acos(x/y)

Boolean Code Ex. if acos(x/y) > 45, p_action

Notes Nested return values are stored internally to the post executable.

 

and

Formula Type Binary function

Description Bitwise and operation. Converts the two arguments to binary and then

performs the “and” comparison on the individual bits.

Bit Bit Result

1 1 1

1 0 0

0 1 0

0 0 0

The return value is the resulting value.

Form function argument, argument

First Argument numeric variable, value (scalar)

Second Argument numeric variable, value (scalar)

Return Type numeric variable (scalar)

Formula Code Ex. real_result = and(real_var1, real_var2)

Boolean Code Ex. if and(real_var1, real_var2) = 2, p_action

Notes Integer values are expected. Nested return values are stored internally

to the post executable. This form of “and” is rarely used.

 

asin

Formula Type Trigonometric function

Description Arc sine. Returns the ratio of the opposite angle to the hypotenuse of a

right triangle.

Form function argument

Argument numeric variable, value (scalar)

Return Type numeric variable (angle)

Formula Code Ex. real_result = asin(x/y)

Boolean Code Ex. if asin(x/y) > 45, p_action

Notes Nested return values are stored internally to the post executable.

 

atan

Formula Type Trigonometric function

Description Arc tangent. Returns the ratio of the opposite angle to the adjacent

angle of a right triangle.

Form function argument

Argument numeric variable, value (scalar)

Return Type numeric variable (angle)

Formula Code Ex. real_result = atan(x/y)

Boolean Code Ex. if atan(x/y) > 45, p_action

Notes Nested return values are stored internally to the post executable.

 

atan2

Formula Type Trigonometric function

Description Arc tangent (two arguments). Returns the angle (0 to 360 degrees) of

the arguments passed to the formula. The second argument axis

indicates the axis for the zero angle position. The first argument axis

indicates the direction from the second argument axis (which defines

the zero angle) is in the positive angle direction. These arguments are

signed to indicate choice.

Form function argument, argument

First Argument numeric variable, value (scalar), represents positive direction

Second Argument numeric variable, value (scalar), represents zero angle

Return Type numeric variable (angle)

Formula Code Ex. real_result = atan2(x, y)

Boolean Code Ex. if atan2(x, y) >180, p_action

Notes Nested return values are stored internally to the post executable.

 

axb

Formula Type 2D vector math function

Description Planar cross product. The formula takes the product of the arguments

(unitized vectors) and returns the sine of the angle between them.

Form function argument, argument

First Argument numeric variable (3D vector, unitized)

Second Argument numeric variable (3D vector, unitized)

Return Type numeric variable (scalar)

Formula Code Ex. real_result = axb(v3_x1, v3_x2)

Boolean Code Ex. Not allowed as a Boolean statement

Notes This is a 2D function. It is recommended that 3D vectors be used and

the last element in the implied array remains 0.

 

brksps

Formula Type String function

Description Breaks a string variable before the index position (one-based) specified

by the value in the first argument. The original string variable (second

argument) holds the start of the broken string and the return string

variable holds the remainder of the string.

Form function argument, argument

First Argument numeric variable, value (scalar)

Second Argument string variable

Return Type string variable

Formula Code Ex. real_var1 : 8

string1 "one two three four"

string2

pblock # A postblock

string2 = brksps (real_var1, string1)

In this example, string1 = "one two" and string2 = " three four".

Boolean Code Ex. Not allowed as a Boolean statement

Notes

 

cos

Formula Type Trigonometric function

Description Cosine. Returns the ratio of the adjacent angle to the hypotenuse of a

right triangle.

Form function argument

Argument numeric variable, value (angle)

Return Type numeric variable (scalar)

Formula Code Ex. real_result = cos(angle)

Boolean Code Ex. if cos(angle) > .7071, p_action

Notes Nested return values are stored internally to the post executable.

Link to comment
Share on other sites

So I didn't have time to get to editing my post until this morning. Thanks guys! Heres what I did and the logics I used, in case anyone needs to do something like it in the future and finds this thread.

 

in the post variables i created a variable,

slowtc : 0

 

In the Tool change I replaced the M6 line with the logic

If mi6 = 99 | slowtc = 1

M306

else

M6

if mi6 = 99,

slowtc = 1

else

slowtc = 0

 

Then, in my end of file, I added a line before my M30

if slowtc = 1, M306

 

That makes sure my heavy or sensitive tool comes back out slow and doesn't get slammed around by the high speed tool change at the start of the next program.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...