49 HEADER = 
''';[Point&S]    50 DECL E6POINT P0={A1 0.0, A2 0.0, A3 0.0, A4 0.0, A5 -90.0, A6 0.0}    55 ;PTP P0 CONT Vel=100% Acc=50% TOOL[0] BASE[0]    60     """Converts a pose target to a string"""    64     return (
'X %.3f,Y %.3f,Z %.3f,A %.3f,B %.3f,C %.3f' % (x,y,z,w,p,r))
    72         for i 
in range(njoints-6):
    73             extaxes = extaxes + (
',E%i %.5f' % (i+1, joints[i+6]))
    77     """Prints a joint target"""    79     data = [
'A1',
'A2',
'A3',
'A4',
'A5',
'A6',
'E1',
'E2',
'E3',
'E4',
'E5',
'E6']
    80     for i 
in range(len(angles)):
    81         str = str + (
'%s %.5f,' % (data[i], angles[i]))
    86     """Get a safe program name"""    87     for c 
in r' -[]/\;,><&*:%=+@!#^|?^':
    88         varname = varname.replace(c,
'_')
    91     if varname[0].isdigit():
    92         varname = 
'P' + varname    
    98     """Robot post object"""   100     MAX_LINES_X_PROG = 5000  
   101     INCLUDE_SUB_PROGRAMS = 
False   108     PROG_NAME = 
'unknown'    128     def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
   134         for k,v 
in kwargs.items():
   135             if k == 
'lines_x_prog':
   139         progname_i = progname
   143                 progname_i = progname
   145                 progname_i = 
"%s%i" % (self.
PROG_NAME, nPages)
   156         self.
addline(
'; Program: %s' % progname_i)
   164             self.
PROG = self.
PROG + 
"\n;[Program&E]\n"   169             self.
PROG = self.
PROG + 
"\n;[Program&E]\n"   171     def progsave(self, folder, progname, ask_user = False, show_result = False): 
   172         progname = progname + 
'.' + self.
PROG_EXT   174             filesave = 
getSaveFile(folder, progname, 
'Save program as...')
   175             if filesave 
is not None:
   176                 filesave = filesave.name
   180             filesave = folder + 
'/' + progname
   181         fid = open(filesave, 
"w")
   184         print(
'SAVED: %s\n' % filesave) 
   189             if type(show_result) 
is str:
   192                 p = subprocess.Popen([show_result, filesave])
   193             elif type(show_result) 
is list:
   195                 p = subprocess.Popen(show_result + [filesave])   
   200                 os.startfile(filesave)
   201             if len(self.
LOG) > 0:
   202                 mbox(
'Program generation LOG:\n\n' + self.
LOG)
   204     def ProgSave(self, folder, progname, ask_user = False, show_result = False):
   212             progname_main = progname + 
"Main"   213             mainprog = 
"Program: %s\n" % progname_main
   219             for i 
in range(npages):
   224             self.
progsave(folder, progname_main, ask_user, show_result)
   234             for i 
in range(npages):
   239             self.
progsave(folder, progname, ask_user, show_result)
   242         """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".   243         The connection parameters must be provided in the robot connection menu of RoboDK"""   246     def MoveJ(self, pose, joints, conf_RLF=None):
   247         """Add a joint movement"""   251     def MoveL(self, pose, joints, conf_RLF=None):
   252         """Add a linear movement"""   255     def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
   256         """Add a circular movement"""   259     def setFrame(self, pose, frame_id=None, frame_name=None):
   260         """Change the robot reference frame"""   261         if frame_id 
is None or frame_id < 1:
   266         self.
addline(
'SET_BASE ' + str(frame_id))
   267         self.
addline(
'SET_BASE ' + frame_name)       
   269     def setTool(self, pose, tool_id=None, tool_name=None):
   270         """Change the robot TCP"""   271         if tool_id 
is None or tool_id < 1:
   276         self.
addline(
'SET_TOOL ' + str(tool_id))
   277         self.
addline(
'SET_TOOL ' + tool_name)   
   280         """Pause the robot program"""   284             self.
addline(
'WAIT SEC %.3f' % (time_ms*0.001))
   287         """Changes the robot speed (in mm/s)"""   289         self.
addline(
'; SPEED = %.5f mm/s' % (speed_mms))
   292         """Changes the current robot acceleration"""   293         self.
addline(
'; ACCELERATION = %.5f' % (accel_mmss/1000.0))
   296         """Changes the robot joint speed (in deg/s)"""   297         self.
addline(
'; JOINT SPEED = %.5f deg/s' % speed_degs)
   301         """Changes the robot joint acceleration (in deg/s2)"""   302         self.
addline(
'; JOINT ACCELERATION = %.5f deg/s2' % accel_degss)
   305         """Changes the zone data approach (makes the movement more smooth)"""   308             self.
addline(
'CPTP = %.3f' % zone_mm)
   309             self.
addline(
'CLIN = %.3f' % zone_mm)
   317         """Sets a variable (output) to a given value"""   318         if type(io_var) != str:  
   319             io_var = 
'$DO[%s]' % str(io_var)        
   320         if type(io_value) != str: 
   327         self.
addline(
'%s=%s' % (io_var, io_value))
   329     def waitDI(self, io_var, io_value, timeout_ms=-1):
   330         """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided."""   331         if type(io_var) != str:  
   332             io_var = 
'$DI[%s]' % str(io_var)        
   333         if type(io_value) != str: 
   341         self.
addline(
'WHILE %s!=%s' % (io_var, io_value))
   347     def RunCode(self, code, is_function_call = False):
   348         """Adds code or a function call"""   350             code.replace(
' ',
'_')
   351             if code.endswith(
'()'):
   358         """Add a joint movement"""   362             self.
addline(
'; Display message: ' + message)
   366         """Add a program line"""   375         self.
PROG = self.
PROG + newline + 
'\n'   379         """Add a log message"""   383         self.
LOG = self.
LOG + newline + 
'\n'   388     [x,y,z,r,p,w] = xyzrpw
   398     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]])
   401     """Test the post with a basic program"""   403     robot = 
RobotPost(
'Kuka_custom', 
'Generic Kuka')
   405     robot.ProgStart(
"Program")
   406     robot.RunMessage(
"Program generated by RoboDK", 
True)
   407     robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
   408     robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
   409     robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
   410     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   411     robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
   412     robot.RunMessage(
"Setting air valve 1 on")
   413     robot.RunCode(
"TCP_On", 
True)
   415     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   416     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   417     robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
   418     robot.RunMessage(
"Setting air valve off")
   419     robot.RunCode(
"TCP_Off", 
True)
   421     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   422     robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
   423     robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
   424     robot.ProgFinish(
"Program")
   427     if len(robot.LOG) > 0:
   428         mbox(
'Program generation LOG:\n\n' + robot.LOG)
   430     input(
"Press Enter to close...")
   432 if __name__ == 
"__main__":
   433     """Function to call when the module is executed by itself: test""" 
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')