50     """Prints a pose target"""    52     return (
'(%.3f,%.3f,%.3f,%.3f,%.3f,%.3f)' % (x,y,z,r,p,w))
    55     """Prints a joint target"""    57     for i 
in range(len(angles)):
    58         str = str + (
'%.6f,' % (angles[i]))
    65     """Robot post object"""    84     def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
    98     def ProgSave(self, folder, progname, ask_user=False, show_result=False):
    99         progname = progname + 
'.' + self.
PROG_EXT   101             filesave = 
getSaveFile(folder, progname, 
'Save program as...')
   102             if filesave 
is not None:
   103                 filesave = filesave.name
   107             filesave = folder + 
'/' + progname
   108         fid = open(filesave, 
"w")
   112         print(
'SAVED: %s\n' % filesave)
   117             if type(show_result) 
is str:
   120                 p = subprocess.Popen([show_result, filesave])   
   121             elif type(show_result) 
is list:
   123                 p = subprocess.Popen(show_result + [filesave])   
   127                 os.startfile(filesave)  
   129             if len(self.
LOG) > 0:
   130                 mbox(
'Program generation LOG:\n\n' + self.
LOG)
   133         """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".   134         The connection parameters must be provided in the robot connection menu of RoboDK"""   137     def MoveJ(self, pose, joints, conf_RLF=None):
   138         """Add a joint movement"""   146     def MoveL(self, pose, joints, conf_RLF=None):
   147         """Add a linear movement"""   156     def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
   157         """Add a circular movement"""   167         self.
addline(
'Mvc P%i, P%i, P%i' % (pi, pi+1, pi+2))
   170     def setFrame(self, pose, frame_id=None, frame_name=None):
   171         """Change the robot reference frame"""   174     def setTool(self, pose, tool_id=None, tool_name=None):
   175         """Change the robot TCP"""   179         """Pause the robot program"""   183             self.
addline(
'Dly %.3f' % (time_ms*0.001))
   186         """Changes the robot speed (in mm/s)"""   188         speed_percent = min(speed_mms*100/5000, 100)
   189         self.
addline(
'Ovrd %.1f' % speed_percent)
   192         """Changes the robot acceleration (in mm/s2)"""   193         self.
addlog(
'setAcceleration not defined')
   196         """Changes the robot joint speed (in deg/s)"""   197         self.
addlog(
'setSpeedJoints not defined')
   200         """Changes the robot joint acceleration (in deg/s2)"""   201         self.
addlog(
'setAccelerationJoints not defined')
   204         """Changes the smoothing radius (aka CNT, APO or zone data) to make the movement smoother"""   206             self.
addline(
'Cnt 1, %.1f' % zone_mm)
   211         """Sets a variable (digital output) to a given value"""   212         if type(io_var) != str:  
   213             io_var = 
'OUT(%s)' % str(io_var)
   214         if type(io_value) != str: 
   221         self.
addline(
'%s=%s' % (io_var, io_value))
   223     def waitDI(self, io_var, io_value, timeout_ms=-1):
   224         """Waits for a variable (digital input) io_var to attain a given value io_value. Optionally, a timeout can be provided."""   225         if type(io_var) != str:  
   226             io_var = 
'IN(%s)' % str(io_var)
   227         if type(io_value) != str: 
   235             self.
addline(
'Wait %s=%s' % (io_var, io_value))
   237             self.
addline(
'Wait %s=%s Timeout=%.1f' % (io_var, io_value, timeout_ms))
   239     def RunCode(self, code, is_function_call = False):
   240         """Adds code or a function call"""   242             code.replace(
' ',
'_')
   243             self.
addline(
'CallP "%s"' % code)
   248         """Display a message in the robot controller screen (teach pendant)"""   258         """Add a program line"""   260         self.
PROG += 
'%d %s' % (self.
lineno, newline) + 
'\n'   263         """Add a log message"""   264         self.
LOG = self.
LOG + newline + 
'\n'   267         """Add a program line"""   272     [x,y,z,r,p,w] = xyzrpw
   282     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]])
   285     """Test the post with a basic program"""   289     robot.ProgStart(
"Program")
   290     robot.RunMessage(
"Program generated by RoboDK using a custom post processor", 
True)
   291     robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
   292     robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
   293     robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
   294     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   295     robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
   296     robot.RunMessage(
"Setting air valve 1 on")
   297     robot.RunCode(
"TCP_On", 
True)
   299     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   300     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   301     robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
   302     robot.RunMessage(
"Setting air valve off")
   303     robot.RunCode(
"TCP_Off", 
True)
   305     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   306     robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
   307     robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
   308     robot.MoveJ(
None, [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
   309     robot.ProgFinish(
"Program")
   313     if len(robot.LOG) > 0:
   314         mbox(
'Program generation LOG:\n\n' + robot.LOG)
   316     input(
"Press Enter to close...")
   318 if __name__ == 
"__main__":
   319     """Function to call when the module is executed by itself: test""" 
def addfooter(self, newline)
def addline(self, newline)
def setZoneData(self, zone_mm)
def MoveJ(self, pose, joints, conf_RLF=None)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def RunCode(self, code, is_function_call=False)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def addlog(self, newline)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def MoveL(self, pose, joints, conf_RLF=None)
def RunMessage(self, message, iscomment=False)
def setAcceleration(self, accel_mmss)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def setTool(self, pose, tool_id=None, tool_name=None)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def setDO(self, io_var, io_value)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def ProgStart(self, progname)
def ProgFinish(self, progname)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def setSpeedJoints(self, speed_degs)
def setFrame(self, pose, frame_id=None, frame_name=None)
def setSpeed(self, speed_mms)
def setAccelerationJoints(self, accel_degss)