Thread: Macro Programming Fundamentals

10022019, 01:37 AM #721
I do not know about your control, but on Fanuc, it is better to use ATAN for finding angles.
ASIN does not give answer in second or third quadrant, and ACOS not in third or fourth quadrant, irrespective of parameter setting.
Of course, if the expected answer is in the first quadrant only, anything can be used.


10022019, 02:31 AM #722
IF [#1EQ#2] #3=#10
ALARM 854: ILLEGAL MACRO PROGRAMMING
IF[#1 < #3] #5=#10
ALARM 859: ODD NUMBER OF PARANTHESES/BRACKETS
so then I tried
IF[[#1 < #3] #5=#10]
Still got alarm 859.

10022019, 03:15 AM #723
I just glanced through the Mazatrol manual.
Though I may have missed something, it seems that only GOTO is available with IF.
And ASIN is not available.
LT must be used in place of <

10022019, 06:04 AM #724
If ASIN really has to be used, the Mazatrol Matrix User Macro has the ATAN math operator. Accordingly, the following should work as an Inverse SIN Function:
#i=ATAN[Number / SQRT[Number * Number + 1]]
Where:
#1 = the ASIN result
Number = the SIN value
If you want to create an Inverse COS Function, the following should also work.
#1 = ATAN[Number / SQRT[Number * Number + 1]] + #2 / 2
#1 = the ACOS result
#2 = Pi
Number = the COS value
Regards,
BillLast edited by angelw; 10022019 at 10:19 AM.

10032019, 01:40 AM #725
That's what I was looking for, thank you very much.


10032019, 05:54 AM #726
Hello MazatrolMatrix,
To be entirely correct, 1 and 1 being passed as an argument have to be dealt with as shown in the Code Examples below.
Rather than having to trot this code out every time you needed it and include it in your program, I would create a Function by registering the code under a unique program number for Inverse SIN and COS as follows. When you have to use either of these functions in your program, simply execute the Macro Call Block for the appropriate function. In each of the following Inverse SIN and COS Function, Common Variable #100 is used to return the result to your program.
Both are Bare Bones examples with no Error Trapping.
Regards,
Bill
Inverse SIN Function Example
G65 P8000 A0.5 (CALL BLOCK PASSING THE SIN OF 30DEG IN THIS EXAMPLE)
O8000
(ASIN FUNCTION)
(THE SIN OF THE ANGLE IS PASSED AS ARGUMENT A)
#2 = 3.1415926535897932 (Pi)
IF [#1 NE 1] GOTO10
#100 = #2 / 2 (Pi/2)
GOTO30
N10 IF[#1 NE 1] GOTO20
#100 = #2 / 2 (Pi/2)
GOTO30
N20 #100 = ATAN[#1 / SQRT[#1 * #1 + 1]]
N30 M99
%
Inverse COS Function Example
G65 P8001 A0.86603 (CALL BLOCK PASSING THE COS OF 30DEG IN THIS EXAMPLE)
O8001
(ACOS FUNCTION)
(THE COS OF THE ANGLE IS PASSED AS ARGUMENT A)
#2 = 3.1415926535897932 (Pi)
IF [#1 NE 1] GOTO10
#100 = 0
GOTO30
N10 IF[#1 NE 1] GOTO20
#100 = #2
GOTO30
N20 #100 = ATAN[#1 / SQRT[#1 * #1 + 1]] + #2 / 2
N30 M99
%

mbraddock liked this post

10152019, 03:32 PM #727
I'm not sure if this is a Haas issue specifically, or a macro issue...
Is it possible to use a variable's value for the text to be engraved while using Haas's G47 macro function**?
In other words, when using the P0 (value), or even the P1 (value), can one reference a variable?
In essence  P0(#505)
All manner of mayhem broke loose when I tried so I'm sure that I'm doing something wrong, but want to make sure that it is even possible.
Thank you.
**  G47 Text Engraving (Group 00)
* E  Plunge feed rate (units/min)
F  Engraving feedrate (units/min)
* I  Angle of rotation (360. to +360.); default is 0
* J  Height of text in in/mm (minimum = 0.001 inch);
default is 1.0 inch
P  0 for literal text engraving
 1 for sequential serial number engraving
 32126 for ASCII characters
* R  Return plane
* X  X start of engraving
* Y  Y start of engraving
* Z  Depth of cut
*indicates optional

10212019, 06:18 AM #728

10242019, 05:31 AM #729
i will help you with this
Cnc Code questions and answers cnc lathe platform


10242019, 06:24 AM #730

10302019, 03:58 AM #731
Our working comprehensive goal is to provide benefits to our client’s business through developing. And growing the standard of their loyalty. Thus, to achieve a high level of loyalty, we do study work along with research on user personas that can reduce the risks of connection with a misunderstanding of their needs.Digitalopment

10302019, 04:22 AM #732
I have a fascination in how the rearrangement of letters in a word, or phrase results in a word of different tense, or meaning. For example Eat and Ate, Eat being the present simple and Ate the past simple.
With regards to the paragraph in the previous Post, by rearranging and deleting some letters, the resulting word is Spam. Amazing don't you think?

10302019, 01:17 PM #733

11072019, 02:47 PM #734
I'm gifting this to the community. Maybe you can improve on it and we can get a discussion going. It's not original or very complex but it's good and working. Error handling isn't really tested. I made this today as a rewrite of an existing working one. Taking it into production tomorrow.
This macro spirals a mill to widen a predrilled hole. It also compensates feed by radius. (Feed given is interpreted as peripheral feed.) Plus I added an option for high feed mills (easy one.)
It's a fun one but maybe you'll ruin your machine with it who knows.
C: Predrilled hole diameter
D: Cutter diameter
E: Target diameter
Q: Ae or Ap
V: Variant (0: Ae 1:Ap)
Code::5000 (TEMPO 1 MATERIAL 2172 250X125X25) (ISCAR GROUP P1 KENNAMETAL GROUP P3) (ORIGO UPPER CENTER) ( T13=KENNAMETAL B051A13500CPG 13.5MM ) ( T12=ISCAR ECE5L 1230C12CF83 12MM ) (KENNAMETAL 13.5MM VC80 F.3) G90G0G54G43X105.Y30.Z50.M7S1886H13T12 G4X10 M3 G81G99R3.Z30.F565 X42.5Y20. Y105. X42. Y20. G98X105.Y30. G55 G99X105.Y30. X42.5Y20. Y105. X42. Y20. G98X105.Y30. G0M9 G91G28Z0M6 M1 (ISCAR ECE5L 12MM) (RECOMMENDED VC360 F.096) (MACHINE LIMIT VC188.4) G90G0G54G43X105.Y30.Z50.S5000H12M3T9 Z5.M14F2000 G66P12C13.5D12.E27.5Q1.R0.Z30.V1.F2000. X105.Y30. X105.Y30. G67 G66P12C13.5D12.E40.Q1.Z13.R0.V0.F2000. X42.5Y20. Y105. X42. Y20. G67 M15 G91G28Z0M6 M30 :0012(FIL=PSPIRALOUT) (FUNCTION 0 SPIRALS FROM R=(CD/2) TO R=(ED/2) Q MM PER ROTATION) (FUNCTION 1 SPIRALS FROM Z=R TO Z=Z Q MM PER ROTATION) (ARGUMENTS:) (C: PREDRILLED HOLE DIAMETER) (D: TOOL DIAMETER) (E: TARGET DIAMETER) (Q: WIDTH OR DEPTH OF CUT) (V: VARIANT. 0 IS SLICING AND 1 IS HIGH FEED LOW AP.) (SAVE CURRENT XYZ) G9 #111=#5001 #112=#5002 #113=#5003 (SAVE MODAL INFO) #119=#4109 (ERROR HANDLING) IF[#07EQ#0]THEN#3000=1(MISSING [D] DIAMETER) IF[#08EQ#0]THEN#3000=2(MISSING [E] DIAMETER) IF[[#17EQ#0]AND[#22NE1]]THEN#3000=3(MISSING [Q] AE) IF[[#17EQ#0]AND[#22EQ1]]THEN#3000=4(MISSING [Q] AP) IF[[#26EQ#0]AND[#22EQ1]]THEN#3000=5(MISSING [Z]) (DEFAULTS) IF[#09EQ#0]THEN#09=#4109(USE SYSTEM FEED IF NO FEED VARIABLE) IF[#03EQ#0]THEN#03=#07(MACRO DEFAULTS TO PREDRILLED HOLE OF CUTTER DIAMETER) IF[#26EQ#0]THEN#26=#113(IF NO TARGET DEPTH IS GIVEN MACRO DEFAULTS TO CURRENT Z TARGET) () #101=[[#3#7]/2] (START RADIUS) #102=[[#8#7]/2] (FINISH RADIUS) #103=10 (MACRO RESOLUTION) IF[#22EQ1]GOTO1 (MODE 0: AREA SLICING. Q IS AE.) #105=0 (ANGLE COUNTER) #106=#101 (RADIUS COUNTER) #104=[#17/360*#103] (RADIUS INCREASE PER STEP) F#09(FEED COUNTER) G90G0Z#18 G90G1Z#26(ENTER CUT) G3X[#111+#101]Z#26R[#101/2] WHILE[#106LT#102]DO1 #105=0(ANGLE COUNTER) WHILE[#105LT360]DO2 #106=#106+#104 IF[#106GT#102]THEN#106=#102 #109=#09*[#106/[#106+[#07/2]]] G3X[#111+[COS[#105]*#106]]Y[#112+[SIN[#105]*#106]]R#106F#109 #105=#105+#103 END2 END1 (FINISHING CUT) G3X[#111+#102]Y#112R#102 G3I#102 G3X#111Y#112R[#102/2]F#09 G0Z#113 F#119 M99 N1 (MODE 1: DEPTH SLICING. Q IS AP.) #106=#18 (Z COUNTER) G90G0Z#18 G3X[#111+#102]Y#112R[#102/2] (ENTER CUT) WHILE[#106GT#26]DO1 #106=#106#17 IF[#106LT#26]THEN#106=#26 G3I#102Z#106 END1 (FINISHING CUT) G3I#102Z#26 G3X#111Y#112R[#102/2] G0Z#113 M99

11112019, 06:13 AM #735
I've been drilling with this little drill program for a pretty long time and unless I'm starting to wig out I don't remember ever running into this till now. So the 27/64 drill did as expected, it kept counting till it reached the Z depth of 1.6 then came out of the hole went home then completely skipped the next drill, read the M30 and set there done.
The fix was to in the 11/32 drill change to GOTO300 & N300 then it run as it was supposed to. I don't understand why this happened though. Isn't the control as its counting reading up looking for N200? I don't know how it got lost when it should be reading backwards at the GOTO looking for N's.
It kinda reminds me of issues I've had with duplicate Q and P numbers in the same program when using canned cycles. Sometimes the control would get lost and be somewhere it's not supposed to be when searching for Q and P numbers if there were duplicates. In my mind if this problem was going to occur it seems it'd be on the second drill instead of first one? I know I've stacked these cycles on top of one another before and I don't ever remember running into this problem. Am I wigging out?
Below is copy and paste of the entire program as it was originally.
Brent
%
O5216(20401 5215 2ND OP)
(20401 5215 REV 3 5/25/2018)
(CORE PIN)
(VISCOUNT V44)
(PART IN .920 DIA COLLET)
(COLLET IS MARKED .8895)
(G54 SET Z 5.015)
N10(MSG, 27/64" .4219 DRILL)
(COLBALT DRILL 89403A430)
(DRILL TURNED DOWN TO .375)
G0G99G40G54X14.Z10.T0
T0404
#1=.025(FEED SHORT OF)
#2=.070(PECK EVERY)
#3=.0(START DRILLING)
#4=1.6(STOP DRILLING)
#5=.2(RAPID BACK SHORT OF)
#6=.005(FEED RATE)
M41
G97S175M3
G0Z.3
G0X0M8
G0Z[#3]
#3=[#3+#2]
N200
G1Z[#3]F[#6]
G0Z.5
G0Z[#3#5]
G1Z[#3#1]F.2
#3=[#3+#2]
IF[#3LT#4]GOTO200
G1Z[#4]F[#6]
G0Z.3
M9
G0X4.
G0G99G40G54X14.Z10.T0
M0
N20(MSG, 11/32" .3438 DRILL)
(MY HOMEMADE LONG DRILL)
G0G99G40G54X14.Z10.T0
T0606
#1=.025(FEED SHORT OF)
#2=.070(PECK EVERY)
#3=1.3(START DRILLING)
#4=4.64(STOP DRILLING)
#5=.2(RAPID BACK SHORT OF)
#6=.0040(FEED RATE)
M41
G97S195M3
G0Z.3
G0X0M8
G0Z[#3]
#3=[#3+#2]
N200
G1Z[#3]F[#6]
G0Z.5
G0Z[#3#5]
G1Z[#3#1]F.2
#3=[#3+#2]
IF[#3LT#4]GOTO200
G1Z[#4]F[#6]
G0Z.3
M9
G0X4.
G0G99G40G54X14.Z10.T0
M30
%

11112019, 06:33 AM #736
Just at a glance you have two N200? Goto searches forward. On my phone.

yardbird liked this post

11112019, 06:37 AM #737
Hello Brent,
The control doesn't search backwards, only forwards. If the sequence number being searched for isn't encountered before the end of the program, the search will start again at the head of the program. Accordingly, if the sequence number is unique in the program and appear before the GOTO command, it seems as though the program has searched backwards, but it has not. In your example program, where there are two N200 sequence numbers, the search initiated by GOTO200 will find the N200 Block that is downstream of the GOTO200 Block first.
Regards,
Bill

11112019, 06:58 AM #738
Last edited by yardbird; 11122019 at 12:37 AM. Reason: Changed stuff

11112019, 03:14 PM #739

11112019, 04:02 PM #740
Bookmarks