What's new
What's new

Fanuc oi macro

OPA12

Plastic
Joined
Jun 5, 2017
Location
MONROE, NC
Trying to modify the attached macro in a Fanuc oi Control.

EXISTING - DRILL HOLES ON A RADIUS

X ABSOLUTE CENTER Y ABSOLUTE CENTER I RADIUS D ANGULAR DISTANCE BETWEEN HOLES
A ANGLE TO FIRST HOLE IN X H NUMBER OF HOLES

%
O9915( ARC - ORIGINAL )
(G65P9915X-Y-I-D-A-H)
#31=#4001
#33=#4003
#32=#5003
IF[#24EQ#0]GOTO10
GOTO20
N10#24=#5001
N20IF[#24EQ#0]GOTO30
GOTO40
N30#25=#5002
N40IF[#1EQ#0]GOTO50
GOTO60
N50#1=0
N60IF[[#11*#4*#7]EQ0]GOTO990
#12=FIX[#11]
IF[[#12-#11]NE0]GOTO990
IF[ABS[#7*#11]GT360]GOTO990
#100=1
WHILE[#100LE#11]DO1
#15=#1+[#100-1]*#7
#27=#4*COS[#15]+#24
#28=#4*SIN[#15]+#25
X#27Y#28
#100=#100+1
END1
G#31G#33F#9
GOTO999
N990#3000=81(DATA-LACK-0R-ERROR-I.D.H.)
N999M99
%

G81Z-2.0R.5F10K0
G65P9915X0Y0I16.0H4.D30.A15.0
G80G91G28Z0

DOES NOT ALLOW “D0” IF ONLY ONE HOLE REQUIRED, OR USING “G” CODE INSIDE SUB PROGRAM
***********************************

MODIFIED - TO ALLOW “G” CODES IN SUB AND ONE HOLE ON AN ARC.

X ABSOLUTE CENTER Y ABSOLUTE CENTER Z DRILL DEPTH R RAPID HEIGHT I RADIUS
D ANGULAR DISTANCE BETWEEN HOLES A ANGLE TO FIRST HOLE IN X H NUMBER OF HOLES
Q PECK # IF G83 K NO REPEAT F FEED RATE

%
O6008( ARC w/G SUB )
(G65P6008E-X-Y-Z-R-I-D-A-H-Q-K-F)
#31=#8
#33=#4003
#32=#5003
IF[#24EQ#0]GOTO10
GOTO20
N10#24=#5001
N20IF[#24EQ#0]GOTO30
GOTO40
N30#25=#5002
N40IF[#1EQ#0]GOTO45
GOTO50
N45#1=0
N50IF[[#11*#4*#7]EQ0]GOTO55
GOTO60
N55IF[#11GT1]GOTO990
N60#12=FIX[#11]
IF[[#12-#11]NE0]GOTO990
IF[ABS[#7*#11]GT360]GOTO990
#100=1
WHILE[#100LE#11]DO1
#15=#1+[#100-1]*#7
#27=#4*COS[#15]+#24
#28=#4*SIN[#15]+#25
X#27Y#28
#100=#100+1
G#31G#33Z#26R#18Q#17K#6F#9
END1
GOTO999
N990#3000=81(DATA-LACK-0R-ERROR-I.D.H.)
N999M99
%

Program:
G65P6008E81X0Y0Z-1.0R.5I8.4305D30.2A38.7H4.K0F10 ( * MOVES TO BUT DOES NOT DRILL FIRST HOLE * )
G65P6008E81X0Y0Z-1.0R.5I8.4305D30.2A-141.3H6.K0F10 ( * DRILLS ALL HOLES * )
IF[#900 GT 18] GOTO 100 (NO HOLE IF GREATER THAN 18” DIA)
G65P6008E81X0Y0Z-1.0R.5I8.4305D28.2A160.H2.K0F10 ( * DRILLS ALL HOLES * )
N100G80G0Z15
G0G91G28Z0
M0

THIS SUB WORKS EXCEPT IT MOVES TO THE FIRST LOCATION OF THE FIRST SUB CALL WITH A NEW TOOL BUT DOES
NOT DRILL HOLE.
 
G65P6008E81X0Y0Z-1.0R.5I8.4305D30.2A38.7H4.K0F10 ( * MOVES TO BUT DOES NOT DRILL FIRST HOLE * )
G65P6008E81X0Y0Z-1.0R.5I8.4305D30.2A-141.3H6.K0F10 ( * DRILLS ALL HOLES * )
Hello OPA12,
There are errors in your program, but none that would prevent the first hole from being drilled, except for the Number of Repeats argument and the fact that Cycle is called after the first hole location is executed.

The following Macro Call that you say doesn't drill the first hole
G65 P6008 E81 X0 Y0 Z-1.0 R.5 I8.4305 D30.2 A38.7 H4. K0 F10

generates the following pseudo code using your Macro Program.

X6.5794 Y5.2711
G81 G90 Z-1.0000 R0.5000 Q0.0000 K0 F10.0
X3.0350 Y7.8653
G81 G90 Z-1.0000 R0.5000 Q0.0000 K0 F10.0
X-1.3334 Y8.3244
G81 G90 Z-1.0000 R0.5000 Q0.0000 K0 F10.0
X-5.3397 Y6.5239
G81 G90 Z-1.0000 R0.5000 Q0.0000 K0 F10.0

The following Macro Call that you say does drill the first and all holes
G65 P6008 E81 X0 Y0 Z-1.0 R.5 I8.4305 D30.2 A-141.3 H6. K0 F10

generates the following pseudo code using your Macro Program.

X-6.5794 Y-5.2711
G81 G90 Z-1.0000 R0.5000 Q0.0000 K0 F10.0
X-3.0350 Y-7.8653
G81 G90 Z-1.0000 R0.5000 Q0.0000 K0 F10.0
X1.3334 Y-8.3244
G81 G90 Z-1.0000 R0.5000 Q0.0000 K0 F10.0
X5.3397 Y-6.5239
G81 G90 Z-1.0000 R0.5000 Q0.0000 K0 F10.0
X7.8966 Y-2.9524
G81 G90 Z-1.0000 R0.5000 Q0.0000 K0 F10.0
X8.3100 Y1.4205
G81 G90 Z-1.0000 R0.5000 Q0.0000 K0 F10.0

In both cases, I would be surprised if the first hole is drilled. In both examples, you have passed a value of Zero to Local Variable #6 (K in the Drill Cycle). By specifying Zero for the Number of Repeats in the Canned Cycle definition, the Cycle Data is simply stored and the Cycle Operation at the current location is not executed.

The above output is exactly how the Macro Program would generate the commands. Accordingly, in the first example, the Cycle is called after the location of the first hole at X6.5794 Y5.2711 (no Cycle Operation will be executed), but it will be executed at X3.0350 Y7.8653 and all subsequent locations, even though all subsequent calls of the Canned Cycle contain a Zero Repeat argument (K0). The reason for this is as follows:

1st hole, current location X6.5794 Y5.2711
G81 G90 Z-1.0000 R0.5000 Q0.0000 K0.0000 F10.0 Cycle Called - No Execution at Current Location
2nd hole X3.0350 Y7.8653 Cycle Executed
G81 G90 Z-1.0000 R0.5000 Q0.0000 K0.0000 F10.0 Cycle Called - No Execution at Current Location
3rd hole X-1.3334 Y8.3244 Cycle Executed
G81 G90 Z-1.0000 R0.5000 Q0.0000 K0.0000 F10.0 Cycle Called - No Execution at Current Location
4th hole X-5.3397 Y6.5239 Cycle Executed
G90 Z-1.0000 R0.5000 Q0.0000 K0.0000 F10.0 Cycle Called - No Execution at Current Location

The second example also has a Zero Value for the Repeat argument (K0), so I see no reason why that example also wouldn't omit executing the Canned Cycle at the first location, if this Call Block was executed First in your Main Program.

Neither of the two Macro Programs are very elegant in their structure. However, I believe the first is designed to calculate the location of where the Cycle is to be executed, after Calling the Cycle in the Main Program. In this case, the Cycle could be called with a Repeat Value of Zero (K0), then the Macro called to calculate the positions and generate the Motion Commands to have the Cycle Execute at each and every calculated location. This would result in no execution of the cycle at the machine's current location when the Cycle is Called, but execute at all coordinates calculate in the Macro.

The reason the Second Macro Call drills all holes is that the G81 Cycle is still active from when the Macro was called the First time, with no G80 or G Code from G Code Group 1 executed in between. Effectively you have the following:

G81 G90 Z-1.0000 R0.5000 Q0.0000 K0 F10.0 Cycle Called in Previous Macro Call - No Execution at Current Location
1st hole X-6.5794 Y-5.2711 Hole Location Calculated in 2nd Macro Call - Cycle Executed

DOES NOT ALLOW “D0” IF ONLY ONE HOLE REQUIRED
Why not? #100 = 1 and if #11 also equaled 1 (for one hole), then #100 and #11 are equal and the DO Loop would execute.

#100=1
WHILE[#100LE#11]DO1
#15=#1+[#100-1]*#7
#27=#4*COS[#15]+#24
#28=#4*SIN[#15]+#25
X#27Y#28
#100=#100+1
END1


Regards,

Bill
 
Last edited:
%
O6008( ARC w/G SUB )
(G65P6008E-X-Y-Z-R-I-D-A-H-Q-K-F)
#31=#8
#33=#4003
#32=#5003
IF[#24EQ#0]GOTO10
GOTO20
N10#24=#5001
N20IF[#24EQ#0]GOTO30
GOTO40
N30#25=#5002
N40IF[#1EQ#0]GOTO45
GOTO50
N45#1=0
N50IF[[#11*#4*#7]EQ0]GOTO55
GOTO60
N55IF[#11GT1]GOTO990
N60#12=FIX[#11]
IF[[#12-#11]NE0]GOTO990
IF[ABS[#7*#11]GT360]GOTO990
#100=1
G#31G#33Z#26R#18Q#17K#6F#9 To Here
WHILE[#100LE#11]DO1
#15=#1+[#100-1]*#7
#27=#4*COS[#15]+#24
#28=#4*SIN[#15]+#25
X#27Y#28
#100=#100+1
G#31G#33Z#26R#18Q#17K#6F#9 Move This Block from Here
END1
GOTO999
N990#3000=81(DATA-LACK-0R-ERROR-I.D.H.)
N999M99
%
Hello OPA12,
To have your modified program work as you would like and execute the Canned Cycle at the first hole location, move the Block shown in Red inside the DO Loop, to just before it as indicated.

The Number Of Repeats argument is only useful when operating in Incremental Mode (extraordinarily unnecessary), or when you want to inhibit the execution of the Cycle at a particular location (quite useful). The latter (inhibiting an execution) can be used to skirt around an obstacle when its not possible, or practical, to go over it, when moving to the location of the next location for the cycle to execute. To do this, you would specify one, or more, intermediate X/Y coordinates that would have the spindle move around the obstacle, with K0 included in each block where the execution of the cycle is not required.

Following is the pseudo Code output by your Macro with the G#31G#33Z#26R#18Q#17K#6F#9 moved as shown above.

G81 G90 Z-1.0000 R0.5000 Q0.0000 K0 F10.0 No Execution of Cycle at Current Location
X6.5794 Y5.2711 Execution of Cycle at this and Subsequent Locations
X3.0350 Y7.8653
X-1.3334 Y8.3244
X-5.3397 Y6.5239

Regards,

Bill
 
Bill,
Thank you so much for all the insight. Your suggestion worked great. I am just starting to dabble with Macro programming by modifying existing programs. In looking back, my "D0" was meant to represent "D0.0". I wanted the option of drilling one hole or multiple holes on an angle. The existing macro would not work unless D had a value in it (I used .001 which did not change the single hole location). My modifications to this macro were in the D=0.0 and H=1 statements, and of course the variables for multiple G cycles.
*********
Your suggestion:
Why not? #100 = 1 and if #11 also equaled 1 (for one hole), then #100 and #11 are equal and the DO Loop would execute.

#100=1
WHILE[#100LE#11]DO1
#15=#1+[#100-1]*#7
#27=#4*COS[#15]+#24
#28=#4*SIN[#15]+#25
X#27Y#28
#100=#100+1
END1
If I do this how can I define the number of holes I want on an angle with #11 (1-??)?

Is there an easier way to modify this macro if only one hole exists on the arc?

Regards,
Darrell
 
Bill,
Thank you so much for all the insight. Your suggestion worked great. I am just starting to dabble with Macro programming by modifying existing programs. In looking back, my "D0" was meant to represent "D0.0". I wanted the option of drilling one hole or multiple holes on an angle. The existing macro would not work unless D had a value in it (I used .001 which did not change the single hole location). My modifications to this macro were in the D=0.0 and H=1 statements, and of course the variables for multiple G cycles.
*********
If I do this how can I define the number of holes I want on an angle with #11 (1-??)?

Is there an easier way to modify this macro if only one hole exists on the arc?

Regards,
Darrell

Hello Darrell,
OK, now I know what you're attempting.

Irrespective of the value of #7 (D), the first hole will always be in the correct position, because [#100-1]*#7 in the #15=#1+[#100-1]*#7 Block will always equal Zero for the first cycle of the Loop. Accordingly, if only one hole at an angle from the Arc Centre, then you can do that using any value for D. It fails when more than one hole is required and a D value of Zero because the two Conditional Statements in the following Code will have the program fall through to N990 without executing an Canned Cycle.

N50IF[[#11*#4*#7]EQ0]GOTO55
GOTO60
N55IF[#11GT1]GOTO990

When multiple holes on a line at an angle are required, this is one situation where the K argument of the Canned Cycle (number of repeats) with a value greater than 1 is useful. In this case you would calculate the X/Y Incremental move to give the correct Radial value between the holes and have the Canned Cycle repeat for the required number of holes in Incremental Mode (G91).

If you want to make this Macro multi functional (not only holes on a PCD), and use it for Multi Holes on a straight line at an angle, then my approach would be to pass another argument to the Macro to set a Flag. For example, "1" for PCD "0" for Points on a Line at Angle, then use a Conditional Statement based on this Flag to either run a DO Loop for a PCD, or Points on a Line at Angle.

In the routine for Points on a line at Angle, you could either:
1. add the Radial distance between the holes to the Circle Radius (I address (#4)) inside a DO Loop and use Absolute Mode.

or,

2. calculate the X/Y incremental move for the desired Radial Distance between Holes and use the Canned Cycle in Incremental Mode and a Number of Repeats specified with the K argument.

In both cases, you could use the D argument used for the Angle between Holes in the PCD routine, to pass the Radial Distance between Holes in the Points on a Line at Angle routine.

Regards,

Bill
 
Bill,
Thanks again for all the help!!!
Regards,
Darrell

Hello Darrell,
Following is one method to go to Points on a Line at Angle using Absolute Mode; the Code in Red is the modification you need to make to your Macro

#100=1
G#31G#33Z#26R#18Q#17K#6F#9
WHILE[#100LE#11]DO1
#15=#1+[#100-1]*#7
#27=#4*COS[#15]+#24
#28=#4*SIN[#15]+#25
X#27Y#28
#100=#100+1
IF[#22EQ1]GOTO70 (IF PCD METHOD)
DO2
#4 = #4 + #7
#27 = #4 * COS[#15] + #24
#28 = #4 * SIN[#15] + #25
X#27Y#28
#100 = #100 + 1
IF[#100 > #11] GOTO80
END2
N70

END1
N80

Follow is the pseudo NC Code output with a "D" value of 1.0" and a "V" argument of Zero passed by the Calling Block to specify Points on Line at Angle. "V" sets the Flag (#22) in the Macro to specify whether points on a PCD, or Line at Angle are calculated.

G81 G90 Z-1.0000 R0.5000 Q0.0000 K0 F10.0
X6.5794 Y5.2711
X7.3598 Y5.8964
X8.1403 Y6.5216
X8.9207 Y7.1468

Alternatively, following is another method to go to Points on a Line at Angle using Incremental Mode and Number of Repeats (K); the Code in Red is the modification you need to make to your Macro.

#100=1
G#31G#33Z#26R#18Q#17K#6F#9
WHILE[#100LE#11]DO1
#15=#1+[#100-1]*#7
#27=#4*COS[#15]+#24
#28=#4*SIN[#15]+#25
X#27Y#28
#100=#100+1
IF[#22EQ1]GOTO70 (IF PCD METHOD)
(POINTS ON LINE AT ANGLE STARTS HERE)
#27 = #7 * COS[#15]
#28 = #7 * SIN(#15)
#6 = #11 - 1
G91 X#27 Y#28 K#6
GOTO80 (EXIT DO1 LOOP)
N70

END1
N80

Follow is the pseudo NC Code output with a "D" value of 1.0" and a "V" argument of Zero passed by the Calling Block to specify Points on Line at Angle.

G81 G90 Z-1.0000 R0.5000 Q0.0000 K0 F10.0
X6.5794 Y5.2711
G91 X0.7804 Y0.6252 K3 (This Block will drill 3 holes, incrementally spaced as specified)


Regards,

Bill
 
Last edited:








 
Back
Top