47 from robolink 
import *
    52     """Prints a pose target"""    54     return (
'x="%.3f" y="%.3f" z="%.3f" a="%.3f" b"%.3f" c="%.3f"' % (x,y,z,r,p,w))
    57     """Prints a joint target"""    59     jnt_tags = [
'a1', 
'a2', 
'a3', 
'a4', 
'a5', 
'a6', 
'a7', 
'a8']
    60     for i 
in range(len(joints)):
    61         str = str + (
'%s="%.5f" ' % (jnt_tags[i], joints[i]))
    68     """Robot post object"""    90     def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
    99         self.
addline(
'<?xml version="1.0" encoding="utf-8"?>')
   100         self.
addline(
'<!-- values in mm and degree -->')
   102         self.
addline(
'<Header ProgramName ="CPRog recording" Author="nn" SetUpDate=""  LastChangeDate="" Kinematic="CPRFour"/>')
   112         self.
addline(
'<!-- End of program: %s -->' % progname)
   117     def ProgSave(self, folder, progname, ask_user=False, show_result=False):
   119         progname = progname + 
'.' + self.
PROG_EXT   121             filesave = 
getSaveFile(folder, progname, 
'Save program as...')
   122             if filesave 
is not None:
   123                 filesave = filesave.name
   127             filesave = folder + 
'/' + progname
   131         robot = RDK.Item(self.
ROBOT_NAME, ITEM_TYPE_ROBOT)
   132         [server_ip, port, remote_path, username, password] = robot.ConnectionParams()            
   134         fid = open(filesave, 
"w")
   136         print(
'SAVED: %s\n' % filesave)
   141         selection_view = 
True   143         if selection_view 
and show_result:
   144             if type(show_result) 
is str:
   147                 p = subprocess.Popen([show_result, filesave])   
   148             elif type(show_result) 
is list:
   150                 p = subprocess.Popen(show_result + [filesave])   
   154                 os.startfile(filesave)  
   156             if len(self.
LOG) > 0:
   157                 mbox(
'Program generation LOG:\n\n' + self.
LOG)
   159         if not selection_view:
   160             RDK.ShowMessage(
'Running program...', 
False)
   161             proc = subprocess.Popen([
'python', filesave])
   171         """Send a program to the robot using the provided parameters. This method is executed right after ProgSave if we selected the option "Send Program to Robot".   172         The connection parameters must be provided in the robot connection menu of RoboDK"""   178         print(
"POPUP: Starting process...")     
   179         print(
"Python path " + PATH_PYTHON)
   185         if PATH_PYTHON != 
'':
   189         process = subprocess.Popen(cmd_run, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=
True)
   192         for stdout_line 
in iter(process.stdout.readline, 
""):
   193             print(
"POPUP: " + stdout_line.strip())
   196         process.stdout.close()
   197         return_code = process.wait()
   199             raise subprocess.CalledProcessError(return_code, cmd_run)
   201         if (return_code == 0):
   204             raise ProcessException(command, return_code, output)
   206     def MoveJ(self, pose, joints, conf_RLF=None):
   207         """Add a joint movement"""   211     def MoveL(self, pose, joints, conf_RLF=None):
   212         """Add a linear movement"""   220     def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
   221         """Add a circular movement"""   222         self.
addlog(
"Cicular moves not supported")
   224     def setFrame(self, pose, frame_id=None, frame_name=None):
   225         """Change the robot reference frame"""   229     def setTool(self, pose, tool_id=None, tool_name=None):
   230         """Change the robot TCP"""   235         """Pause the robot program"""   238             self.
addline(
'<Wait Nr="%i" Seconds="%.3f" Descr="" />' % (self.
NR_ID, float(9999)))
   241             self.
addline(
'<Wait Nr="%i" Seconds="%.3f" Descr="" />' % (self.
NR_ID, float(time_ms)*0.001))
   244         """Changes the robot speed (in mm/s)"""   248         """Changes the robot acceleration (in mm/s2)"""   249         self.
addlog(
'Linear acceleration not supported')
   252         """Changes the robot joint speed (in deg/s)"""   256         """Changes the robot joint acceleration (in deg/s2)"""   257         self.
addlog(
'Joint acceleration not supported')
   260         """Changes the smoothing radius (aka CNT, APO or zone data) to make the movement smoother"""   267         """Sets a variable (digital output) to a given value"""   268         if type(io_var) != str:  
   269             io_var = 
'%s' % str(io_var)
   270         if type(io_value) != str: 
   279         self.
addline(
'<Output Nr="%i" Local="True" DIO="%s" State="%s" Descr="" />' % (self.
NR_ID, io_var, io_value))
   281     def waitDI(self, io_var, io_value, timeout_ms=-1):
   282         """Waits for a variable (digital input) io_var to attain a given value io_value. Optionally, a timeout can be provided."""   283         if type(io_var) != str:  
   284             io_var = 
'%s' % str(io_var)
   285         if type(io_value) != str: 
   293         self.
addline(
'<WaitInput Nr="%i" Local="True" DIO="%s" State="%s" Descr="" />' % (self.
NR_ID, io_var, io_value))
   296     def RunCode(self, code, is_function_call = False):
   297         """Adds code or a function call"""   299             code.replace(
' ',
'_')
   300             if not code.endswith(
')'):
   307         """Display a message in the robot controller screen (teach pendant)"""   309             self.
addline(
'<!-- %s -->' % message)
   311             self.
addline(
'<!-- %s -->' % message)
   315         """Add a program line"""   319         """Add a log message"""   320         self.
LOG = self.
LOG + newline + 
'\n'   325     [x,y,z,r,p,w] = xyzrpw
   335     return Mat([[cb*ca, ca*sc*sb - cc*sa, sc*sa + cc*ca*sb, x],[cb*sa, cc*ca + sc*sb*sa, cc*sb*sa - ca*sc, y],[-sb, cb*sc, cc*cb, z],[0,0,0,1]])
   338     """Test the post with a basic program"""   342     robot.ProgStart(
"Program")
   343     robot.RunMessage(
"Program generated by RoboDK using a custom post processor", 
True)
   344     robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
   345     robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
   346     robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
   347     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   348     robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
   349     robot.RunMessage(
"Setting air valve 1 on")
   350     robot.RunCode(
"TCP_On", 
True)
   352     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   353     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   354     robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
   355     robot.RunMessage(
"Setting air valve off")
   356     robot.RunCode(
"TCP_Off", 
True)
   358     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   359     robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
   360     robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
   361     robot.MoveJ(
None, [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
   362     robot.ProgFinish(
"Program")
   365     if len(robot.LOG) > 0:
   366         mbox(
'Program generation LOG:\n\n' + robot.LOG)
   368     input(
"Press Enter to close...")
   370 if __name__ == 
"__main__":
   371     """Function to call when the module is executed by itself: test""" def RunCode(self, code, is_function_call=False)
def addlog(self, newline)
def setTool(self, pose, tool_id=None, tool_name=None)
def RunMessage(self, message, iscomment=False)
def setZoneData(self, zone_mm)
def addline(self, newline)
def MoveJ(self, pose, joints, conf_RLF=None)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def setDO(self, io_var, io_value)
def ProgFinish(self, progname)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def setFrame(self, pose, frame_id=None, frame_name=None)
def MoveL(self, pose, joints, conf_RLF=None)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def setSpeed(self, speed_mms)
def setAccelerationJoints(self, accel_degss)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def ProgStart(self, progname)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def setAcceleration(self, accel_mmss)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def setSpeedJoints(self, speed_degs)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)