What's new
What's new

Macro Programming Fundamentals

My issue would be mostly in what point and how you would call the macro. Calling by M6 won't work as the T code is long before the M6 in the programs and it will throw an error if there's a wrong tool number called. In these machines, T code makes the tool changer search the next tool and M6 executes the ATC arm cycle. I think you can only call one macro with one T code and that's it?
 
My issue would be mostly in what point and how you would call the macro. Calling by M6 won't work as the T code is long before the M6 in the programs and it will throw an error if there's a wrong tool number called. In these machines, T code makes the tool changer search the next tool and M6 executes the ATC arm cycle. I think you can only call one macro with one T code and that's it?
So, are you referring to pre staging the next tool in the program? If so, its common safe practice to call the next tool again when the Tool Change is about to be made, as in the following example:
N1
T01 (Tool to put in spindle)
M06
T02 (Next Tool)
---------------
---------------
More Program Code
---------------
---------------
N2
T02 (Tool to put in spindle)
M06
T03 (Next Tool)
---------------
---------------
More Program Code
---------------
---------------
N3
T03 (Tool to put in spindle)
M06
T04(Next Tool)
and so on.

In the event that you have to rerun a Tool Operation, the above method ensures that the correct Tool is put into the Spindle. The above method also allows for the extraction of the two least significant numbers from a 4 digit Tool Number to be included in the Tool Change Macro.

Regards,

Bill

Regards
 
#2 = #1 / 100
#3 = FIX[#2]
#4 =FIX[[ V2 - V3] * 100] (#4 = 28)

Hey Bill,

Is this an error? Seems like it should be ...
#4 =FIX[[ #2 - #3] * 100] (#4 = 28)

Also, can you explain MOD to me. I don't have a control that has the MOD function so I can experiment and in reading a 15M manual, don't understand how it behaves.
 
When a number is divided by another number, the remainder is called MOD.
This function is available in newer control models.
 
Hey Bill,

Is this an error? Seems like it should be ...
#4 =FIX[[ #2 - #3] * 100] (#4 = 28)

Also, can you explain MOD to me. I don't have a control that has the MOD function so I can experiment and in reading a 15M manual, don't understand how it behaves.
Hello Kevin,
Yes, you're correct. I use Visual Basic to Debug Macro Program and sometimes create the Macro Program in VB then convert it to User Macro Syntax. V B can't use the # symbol as a Variable identifier, its the symbol for Double Precision real numbers, and therefore, I normally use "V" instead of "#" and when finished, do a Global Find and Replace of V with #. I created the simple example in my earlier Post in VB and as there weren't many Variables, changed the Vs to # manually and they were two I missed.

I would hardly call a FS15 control a newer control, but as Sinha explains, MOD is the resulting remainder when a number is divided by another.

In the following example, where 9128 is divided by 1000, 128 will be the remainder. Actually, the extra step I said would be required if the right most three numbers were greater than 099, isn't quite correct. Had #1 = #20 MOD 1000 (#1 = 128) been written as #1 = #20 MOD 100 (#1 =28) then only the right most two numbers would be returned.

(#20 (or #4120) = 9128)
#1 = #20 MOD 1000 (#1 = 128)
#1 = #1 MOD 100 (#1 = 28)

Regards,

Bill
 
Hello Kevin,
Yes, you're correct. I use Visual Basic to Debug Macro Program and sometimes create the Macro Program in VB then convert it to User Macro Syntax. V B can't use the # symbol as a Variable identifier, its the symbol for Double Precision real numbers, and therefore, I normally use "V" instead of "#" and when finished, do a Global Find and Replace of V with #. I created the simple example in my earlier Post in VB and as there weren't many Variables, changed the Vs to # manually and they were two I missed......
Ahh, I wondered if it was something related to that. I think I recall you telling me a bit about your VB application to test macros.
......I would hardly call a FS15 control a newer control, but as Sinha explains, MOD is the resulting remainder when a number is divided by another.
Yes, while certainly not new, it was and still is a powerful control. Quite advanced capabilities in its day. When I looked at my Mitsu M50 and FS0 manuals and found no MOD function, I turned to a FS15 manual I have. Despite the Mitsu and FS0 manual not mentioning MOD, I think it worth trying to see if the ability exists despite not being documented. Seems the MOD function would be useful in parsing a number for say an engraving macro.
 
Hello Kevin,
Yes, you're correct. I use Visual Basic to Debug Macro Program and sometimes create the Macro Program in VB then convert it to User Macro Syntax. V B can't use the # symbol as a Variable identifier, its the symbol for Double Precision real numbers, and therefore, I normally use "V" instead of "#" and when finished, do a Global Find and Replace of V with #. I created the simple example in my earlier Post in VB and as there weren't many Variables, changed the Vs to # manually and they were two I missed.

I would hardly call a FS15 control a newer control, but as Sinha explains, MOD is the resulting remainder when a number is divided by another.

In the following example, where 9128 is divided by 1000, 128 will be the remainder. Actually, the extra step I said would be required if the right most three numbers were greater than 099, isn't quite correct. Had #1 = #20 MOD 1000 (#1 = 128) been written as #1 = #20 MOD 100 (#1 =28) then only the right most two numbers would be returned.

(#20 (or #4120) = 9128)
#1 = #20 MOD 1000 (#1 = 128)
#1 = #1 MOD 100 (#1 = 28)

Regards,

Bill
MOD is a new one to me as well.. If I am to understand it correctly if you was to change the second line in this
(#20 (or #4120) = 9128)
#1 = #20 MOD 1000 (#1 = 128)
#1 = #1 MOD 100 (#1 = 28)

to this
(#20 (or #4120) = 9128)
#1 = #20 MOD 1000 (#1 = 128)
#1 = #1 MOD 10 (#1 = 8)

would that be accurate ? or would you have to step it down more like this.

(#20 (or #4120) = 9128)
#1 = #20 MOD 1000 (#1 = 128)
#1 = #1 MOD 100 (#1 = 28)
#1 = #1 MOD 10 (#1 = 8)
 
MOD is a new one to me as well.. If I am to understand it correctly if you was to change the second line in this
(#20 (or #4120) = 9128)
#1 = #20 MOD 1000 (#1 = 128)
#1 = #1 MOD 100 (#1 = 28)

to this
(#20 (or #4120) = 9128)
#1 = #20 MOD 1000 (#1 = 128)
#1 = #1 MOD 10 (#1 = 8)

would that be accurate ? or would you have to step it down more like this.

(#20 (or #4120) = 9128)
#1 = #20 MOD 1000 (#1 = 128)
#1 = #1 MOD 100 (#1 = 28)
#1 = #1 MOD 10 (#1 = 8)
No, you don't have to step it down to get just the right most number as in your above example and in effect I stated that in my earlier Post with the following extract from that Post.

Actually, the extra step I said would be required if the right most three numbers were greater than 099, isn't quite correct. Had #1 = #20 MOD 1000 (#1 = 128) been written as #1 = #20 MOD 100 (#1 =28) then only the right most two numbers would be returned.

and you don't require the two steps shown in your example. The following will result in returning only the right most single number from the original number 9128:

(#20 (or #4120) = 9128)
#1 = #20 MOD 10 (#1 = 8)

Regards,

Bill
 
No, you don't have to step it down to get just the right most number as in your above example and in effect I stated that in my earlier Post with the following extract from that Post.



and you don't require the two steps shown in your example. The following will result in returning only the right most single number from the original number 9128:

(#20 (or #4120) = 9128)
#1 = #20 MOD 10 (#1 = 8)

Regards,

Bill
Thanks Bill I missed your earlier explanation of that.
 
I think you are correct.
MOD is not included in the function list of 0iTC manual.
However, this is from the same manual ...
View attachment 411638
Today I tested MOD on a Fanuc 0MB. Doesn't work Won't even accept the character O in a macro code line. I also tried MOD on a Mitsubishi M50. It functions same as on a MOD capable Fanuc. In my initial look through the Mitsu programming manual I did not find MOD listed in the macro functions. A subsequent look and I found it mentioned outside of the list of functions. Pretty obscure.
 
Seems the MOD function would be useful in parsing a number for say an engraving macro.
Hello Kevin,
I've given this notion a bit of thought and I believe there are better methods than using MOD. With an engraving program of a number, you want to be dismantling the number one digit at a time, from either left to right, or right to left. This is more difficult to do with MOD than with other methods I've Posted on this Forum for that purpose.

In any case, unless the number to decode for engraving is always of the same fixed length, the number of digits in the number needs to be determined. This can be done with the following:

#1 = 222220 (Number to Dismantle)

#2 = 1 (First Base 10)
#3 = 0 (Counter)

WHILE [#1 GE #2] DO1
#2 = #2 * 10
#3 = #3 + 1
END1
IF [#2 GT #1] #3 = #3-1 (The number of digits in the number)

Regards,

Bill
 
Last edited:
Hello Kevin,
I've given this notion a bit of thought and I believe there are better methods than using MOD. With an engraving program of a number, you want to be dismantling the number one digit at a time, from either left to right, or right to left. This is more difficult to do with MOD than with other methods I've Posted on this Forum for that purpose.

In any case, unless the number to decode for engraving is always of the same fixed length, the number of digits in the number needs to be determined. This can be done with the following:

#1 = 222220 (Number to Dismantle)

#2 = 1 (First Base 10)
#3 = 0 (Counter)

WHILE [#1 GE #2] DO1
#2 = #2 * 10
#3 = #3 + 1
END1
IF [#2 GT #1] #3 = #3-1 (The number of digits in the number)

Regards,

Bill
Correction to the above code is shown following:

#1 = 222220 (Number to Dismantle)

#2 = 1 (First Base 10)
#3 = 0 (Counter)

WHILE [#1 GE #2] DO1
#2 = #2 * 10
#3 = #3 + 1
END1
(3# = The number of digits in the number)


Regards,

Bill
 
Hello Kevin,
I've given this notion a bit of thought and I believe there are better methods than using MOD. With an engraving program of a number, you want to be dismantling the number one digit at a time, from either left to right, or right to left. This is more difficult to do with MOD than with other methods I've Posted on this Forum for that purpose.

In any case, unless the number to decode for engraving is always of the same fixed length, the number of digits in the number needs to be determined. This can be done with the following:

#1 = 222220 (Number to Dismantle)

#2 = 1 (First Base 10)
#3 = 0 (Counter)

WHILE [#1 GE #2] DO1
#2 = #2 * 10
#3 = #3 + 1
END1
IF [#2 GT #1] #3 = #3-1 (The number of digits in the number)

Regards,

Bill
Bill I am a little confused about what the goal is with this one. You said to dismantle a number 1 at a time from from left or right. Maybe I am overthinking it but would't it grow by a factor of 10 each iteration of the do-while?
WHILE [#1 GE #2] DO1
#2 = #2 * 10
#3 = #3 + 1
END1
first iteration result would be #2=10
second iteration result would be #2=100
third iteration result would be #2=1000
and so on.
Or am I just missing something?
 
Bill I am a little confused about what the goal is with this one. You said to dismantle a number 1 at a time from from left or right. Maybe I am overthinking it but would't it grow by a factor of 10 each iteration of the do-while?
WHILE [#1 GE #2] DO1
#2 = #2 * 10
#3 = #3 + 1
END1
first iteration result would be #2=10
second iteration result would be #2=100
third iteration result would be #2=1000
and so on.
Or am I just missing something?
That is correct. The number of digits is the final value of #3.

Another way, without a loop, can be this:
#3 = FIX[LN[#1]/LN[10]]+1

If #1 is 222220 then
LN[#1] = 12.311---
LN[10] = 2.302---
LN[#1]/LN[10] = 5.346---
FIX[LN[#1]/LN[10]] = 5
FIX[LN[#1]/LN[10]]+1 = 6
Hence, #3 = 6 (As expected)
 
That is correct. The number of digits is the final value of #3.

Another way, without a loop, can be this:
#3 = FIX[LN[#1]/LN[10]]+1

If #1 is 222220 then
LN[#1] = 12.311---
LN[10] = 2.302---
LN[#1]/LN[10] = 5.346---
FIX[LN[#1]/LN[10]] = 5
FIX[LN[#1]/LN[10]]+1 = 6
Hence, #3 = 6 (As expected)
Never have used the natural logarithm function before that is interesting. The main thing that I was referring to was the dismantling a number 1 at a time from left or right. I was thinking decreasing by 1 each iteration instead of a factor of 10. I'm thinking I just misunderstood Bill's intent.
 








 
Back
Top