o sub M19 R0 ; align the spindle ; only unload the tool if there is a tool in the spindle ; This assumes that the carousel is already aligned correctly. ; It is important to unload the tool before shutting down the machine. o100 IF [# GT 0] G53 G0 Z-4.000 M64 P0 ; tool arm brake = off M64 P1 ; tool arm out = on M66 P0 L3 Q5 ; wait 5 for tool arm out sensor = true o105 if [#5399 LT 0] (abort, failed tool arm out) o105 endif M66 P1 L4 Q5 ; wait 5 for tool arm in sensor = false o106 if [#5399 LT 0] (abort, failed tool arm out) o106 endif M65 P1 ; move tool arm out = off M65 P0 ; tool arm brake = on M66 P2 L3 Q5 ; wait 5 for low air sensor = true o115 if [#5399 LT 0] (abort, failed low air) o115 endif M64 P2 ; tool unclamp solenoid = on M66 P3 L3 Q2 ; wait 2 for tool unclamp sensor = true o120 if [#5399 LT 0] (abort, failed to release tool) o120 endif M66 P4 L4 Q2 ; wait 2 for tool clamp sensor = false o121 if [#5399 LT 0] (abort, failed to release tool) o121 endif M62 P3 ; Air blast with motion = on G53 G0 Z0 M65 P3 ; Air blast with motion = off o100 ENDIF G53 G0 Z0 o200 IF [# GT 0] M68 E0 Q# ;set the carousel to move to the right pocket M64 P4 ; start carousel G4 P2 M66 P5 L3 Q60 ; wait for carousel finished o205 if [#5399 LT 0] (abort, failed to align carousel) o205 endif M65 P4; stop carousel o210 if [# EQ 0] ; if no tool in spindle tool arm goes out M64 P0 ; tool arm brake = off M64 P1 ; tool arm out = on M66 P0 L3 Q5 ; wait 5 for tool arm out sensor = true o215 if [#5399 LT 0] (abort, failed tool arm out) o215 endif M66 P1 L4 Q5 ; wait 5 for tool arm in sensor = false o220 if [#5399 LT 0] (abort, failed tool arm out) o220 endif M65 P1 ; move tool arm out = off M65 P0 ; tool arm brake = on 0210 endif M62 P3 ; Air blast with motion = on G53 G0 Z-4.000 ; pick up the tool M65 P3 ; Air blast with motion = off o200 ENDIF M65 P2 ; tool unclamp solenoid = off M66 P4 L3 Q2 ; wait 2 for tool clamp sensor = true o122 if [#5399 LT 0] (abort, failed to clamp tool) o122 endif M66 P3 L4 Q2 ; wait 2 for tool unclamp sensor = false o123 if [#5399 LT 0] (abort, failed to clamp tool) o123 endif M64 P0 ; tool arm brake = off M64 P5 ; tool arm in = on M66 P1 L3 Q5 ; wait 5 for tool arm in sensor = true o107 if [#5399 LT 0] (abort, failed tool arm in) o107 endif M66 P0 L4 Q5 ; wait 5 for tool arm out sensor = false o108 if [#5399 LT 0] (abort, failed tool arm in) o108 endif M65 P5 ; move tool arm in = off M65 P0 ; tool arm brake = on o endsub [1] M2