O0195 (CIRCULO DE AGUJEROS PARAMETRICO) | ( Program header. ) |
G21 G17 G40 G49 G80 | ( Millimeters, XY plane and a clean state. ) |
#100 = 8 | ( Number of holes. This is the first number you touch for a different part. ) |
#101 = 120. | ( Bolt circle diameter. ) |
#102 = 60. | ( X coordinate of the circle center. ) |
#103 = 50. | ( Y coordinate of the center. ) |
#104 = 0. | ( Angle of the first hole, measured from the positive X axis. ) |
#105 = 360. / #100 | ( Angular step between holes. It is calculated, not typed in: if tomorrow there are twelve holes, only #100 changes. ) |
#106 = 1 | ( Loop counter. ) |
G91 G28 Z0. | ( Z to the reference point before the change. ) |
T7 M06 | ( Ø8 drill. ) |
G90 G54 G00 X#102 Y#103 | ( Positions over the center of the circle, using the variables directly as dimensions. ) |
G43 H07 Z50. M03 S2500 | ( T7 length offset and spindle on. ) |
M08 | ( Coolant. ) |
WHILE [#106 LE #100] DO 1 | ( Starts the loop: it repeats as long as the counter does not go past the number of holes. ) |
#107 = #102 + [[#101 / 2] * COS[#104]] | ( X coordinate of the current hole: center plus radius times the cosine of the angle. Note the nested brackets; parentheses do not work here. ) |
#108 = #103 + [[#101 / 2] * SIN[#104]] | ( Y coordinate of the current hole, with the sine. ) |
G99 G81 X#107 Y#108 Z-20. R3. F200 | ( Drills at the calculated position. The canned cycle accepts variables in X and Y as if they were numbers. ) |
#104 = #104 + #105 | ( Adds the angular step for the next hole. ) |
#106 = #106 + 1 | ( Increments the counter. Forgetting this line is the number one mistake: the loop never ends. ) |
END 1 | ( Closes loop 1. The number has to match the one on the DO. ) |
G80 G00 Z50. M09 | ( Cancels the cycle and moves up. ) |
G91 G28 Z0. M05 | ( Z to the reference point and spindle stop. ) |
G90 M30 | ( Back to absolute and end of program. ) |