# RoboDK Python Intermediate file to generate robot programs.
# Program name: P13
# This file requires the post processor: 
#   ABB_RAPID_AGS
# to generate your robot program.
# This is a temporary file and you can delete it once you have generated your program.
# 
# Post processor documentation: https://robodk.com/doc/en/PythonAPI/postprocessor.html

import sys
import os
import robodk
sys.path.append(os.path.abspath(r"""C:/RoboDK/Posts/""")) # temporarily add path to POSTS folder

from ABB_RAPID_AGS import *

try:
  from robodk.robomath import PosePP as p
except:
  # This will be removed in future versions of RoboDK
  from robodk import PosePP as p


print('Total instructions: 24')
r = RobotPost(r"""ABB_RAPID_AGS""",r"""ABB IRB 1200-7/0.7""",6, axes_type=['R','R','R','R','R','R'], native_name=r"""ABB IRB 1200-7/0.7""", ip_com=r"""10.1.3.237""", api_port=20500, prog_ptr=2996522100720, robot_ptr=2996550304608)

r.ProgStart(r"""P13""")
r.RunMessage(r"""Program generated by RoboDK v5.8.0 for ABB IRB 1200-7/0.7 on 30/03/2025 18:19:15""",True)
r.RunMessage(r"""Using nominal kinematics.""",True)
r.RunCode(r"""onStart""", True)
r.setZoneData(1.000)
r.setSpeed(1000.000)
r.setFrame(p(551,-164.616,242.5,0,-90,0),-1,r"""WP""")
r.setTool(p(86.06,0,22,0,90,0),-1,r"""T9""")
r.RunMessage(r"""Show T9""",True)
r.MoveJ(None,[-5.45733,23.3028,4.22672,-11.6785,-28.0237,10.3407],None)
r.MoveL(p(167,120,-20,0,-90,0),[-5.45733,30.9788,11.0137,-8.12685,-42.2802,6.03103],[0,0,1])
r.RunCode(r"""onPathStart;""")
r.RunCode(r"""SocketSend ags_socket1 \Str:="A020510";""")
r.RunCode(r"""FOR k FROM 1 TO 10 STEP 1 DO""")
r.RunCode(r"""WOFFS := WP;""")
r.RunCode(r"""WOFFS.oframe.trans := [OFFS_X - k, OFFS_Y, OFFS_Z];""")
r.RunCode(r"""TPWrite " OFF_X " + NumtoStr(OFFS_X - k,3);""")
r.RunCode(r"""WaitTime \InPos, 0.5;""")
r.RunCode(r"""probe_detect(1);""")
r.RunCode(r"""SocketSend ags_socket1 \Str:="A09051";""")
r.RunCode(r"""SocketReceive ags_socket1 \Str:=str_buf \ReadNoOfBytes:=1;""")
r.RunCode(r"""str_buf := HexToDec(str_buf);""")
r.RunCode(r"""IF (str_buf = "1") THEN""")
r.RunCode(r"""    WP.oframe.trans := [OFFS_X - k, 0, 0];""")
r.RunCode(r"""    GOTO nextPart;""")
r.RunCode(r"""ENDIF""")
r.setSpeed(1000.000)
r.RunCode(r"""ENDFOR""")
r.RunCode(r"""nextPart:""")
r.RunCode(r"""onPathFinish;""")
r.RunCode(r"""WOFFS := WP;""")
r.MoveL(p(207,120,-20,0,-90,0),[-5.45733,27.4708,8.85314,-9.16208,-36.6757,7.37061],[0,0,1])
r.RunCode(r"""onFinish""", True)
r.ProgFinish(r"""P13""")
r.ProgSave(r"""C:/ags/rdk/""",r"""P13""",False,r"""C:/RoboDK/Other/VSCodium/VSCodium.exe""")
