50 PROGRAM_PJX = 
'''<?xml version="1.0" encoding="utf-8" ?>    51 <Project xmlns="http://www.staubli.com/robotics/VAL3/Project/3">    52   <Parameters version="s7.3.1" stackSize="5000" millimeterUnit="true" />    54     <Program file="start.pgx" />    55     <Program file="stop.pgx" />    58     <Data file="%s.dtx" />    65 DATA_DTX = 
'''<?xml version="1.0" encoding="utf-8" ?>    66 <Database xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.staubli.com/robotics/VAL3/Data/2">    68     <Data name="%s" access="public" xsi:type="array" type="frame" size="%i">    70     <Data name="jPark" access="public" xsi:type="array" type="jointRx" size="1">    71       <Value key="0" j1="0.000" j2="0.000" j3="90.000" j4="0.000" j5="90.000" j6="0.000" />    73     <Data name="%s" access="public" xsi:type="array" type="jointRx" size="%i">    75     <Data name="mNomSpeed" access="public" xsi:type="array" type="mdesc" size="1">    76       <Value key="0" accel="100" vel="100" decel="100" tmax="99999" rmax="99999" blend="off" leave="50" reach="50" />    78     <Data name="%s" access="public" xsi:type="array" type="mdesc" size="%i">    80     <Data name="nTraj" access="public" xsi:type="array" type="num" size="1"/>    81     <Data name="nTimeStop" access="private" xsi:type="array" type="num" size="1"/>    82     <Data name="nTimeStart" access="private" xsi:type="array" type="num" size="1"/>    83     <Data name="nMode" access="private" xsi:type="array" type="num" size="1"/>    84     <Data name="nEtat" access="private" xsi:type="array" type="num" size="1"/>    85     <Data name="%s" access="public" xsi:type="array" type="pointRx" size="%i">    87     <Data name="%s" access="public" xsi:type="array" type="tool" size="%i">    94 START_PGX = 
'''<?xml version="1.0" encoding="utf-8" ?>    95 <Programs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.staubli.com/robotics/VAL3/Program/2">    96   <Program name="start" access="public">   106 STOP_PGX = 
'''<?xml version="1.0" encoding="utf-8" ?>   107 <Programs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.staubli.com/robotics/VAL3/Program/2">   108   <Program name="stop" access="private">   121     """Converts a pose to a Staubli target target"""   127     """Prints a pose target"""   129     return (
'x="%.3f" y="%.3f" z="%.3f" rx="%.3f" ry="%.3f" rz="%.3f"' % (x,y,z,r,p,w))
   132     """Prints a joint target for Staubli VAL3 XML"""   134     for i 
in range(len(angles)):
   135         str = str + (
'j%i="%.5f" ' % (i, angles[i]))
   141     from tkinter 
import filedialog
   143     options[
'initialdir'] = strdir
   144     options[
'title'] = strtitle
   147     file_path = tkinter.filedialog.askdirectory(**options)
   153     """Robot post object"""       165     SPEED = DEFAULT_SPEED
   166     SMOOTH = DEFAULT_SMOOTH
   167     REF_NAME = 
'fReference'   168     REF_CURRENT = 
'world[0]'   172     TOOL_CURRENT = 
'flange[0]'   175     SPEED_NAME = 
'mSpeed'   176     SPEED_CURRENT = 
'mNomSpeed'   179     JOINT_NAME = 
'jJoint'   182     POINT_NAME = 
'pPoint'   186     def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
   194         self.
addline(
'// Program %s start' % progname)
   199         self.
addline(
'// Program %s end' % progname)
   201     def ProgSave(self, folder, progname, ask_user = False, show_result = False):
   204             if foldersave 
is not None and len(foldersave) > 0:
   205                 foldersave = foldersave
   211         folderprog = foldersave + 
'/' + progname
   214             os.makedirs(folderprog)
   217         start_file = folderprog + 
'/start.pgx'   218         fid = open(start_file, 
"w")
   219         fid.write(START_PGX % self.
PROG_PGX)
   223         stop_file = folderprog + 
'/stop.pgx'   224         fid = open(stop_file, 
"w")
   229         project_file = folderprog + 
'/%s.pjx' % progname
   230         fid = open(project_file, 
"w")
   231         fid.write(PROGRAM_PJX % progname)
   233         print(
'SAVED: %s\n' % project_file)
   236         program_data = folderprog + 
'/%s.dtx' % progname
   237         fid = open(program_data, 
"w")
   238         fid.write(DATA_DTX % (self.
REF_NAME, self.
REF_COUNT, self.
REF_DATA,  self.
JOINT_NAME, self.
JOINT_COUNT, self.
JOINT_DATA,  self.
SPEED_NAME, self.
SPEED_COUNT, self.
SPEED_DATA,  self.
POINT_NAME, self.
POINT_COUNT, self.
POINT_DATA,  self.
TOOL_NAME, self.
TOOL_COUNT, self.
TOOL_DATA))
   246             if type(show_result) 
is str:
   249                 p = subprocess.Popen([show_result, start_file])
   250                 p = subprocess.Popen([show_result, program_data])                
   251             elif type(show_result) 
is list:
   253                 p = subprocess.Popen(show_result + [filesave])   
   257                 os.startfile(start_file)
   258                 os.startfile(program_data)
   259             if len(self.
LOG) > 0:
   260                 mbox(
'Program generation LOG:\n\n' + self.
LOG)
   263         """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".   264         The connection parameters must be provided in the robot connection menu of RoboDK"""   267     def MoveJ(self, pose, joints, conf_RLF=None):
   268         """Add a joint movement"""   278     def MoveL(self, pose, joints, conf_RLF=None):
   279         """Add a linear movement"""   284             str_config = 
'shoulder="lefty" elbow="epositive" wrist="wpositive"'   286             [rear, lowerarm, flip] = conf_RLF
   287             str_config = 
'shoulder="%s" elbow="%s" wrist="%s"' % (
"righty" if rear>0 
else "lefty", 
"enegative" if lowerarm>0 
else "epositive", 
"wnegative" if flip>0 
else "wpositive")
   293     def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
   294         """Add a circular movement"""   296         if conf_RLF_1 == 
None:
   297             str_config = 
'shoulder="lefty" elbow="epositive" wrist="wpositive"'   299             [rear, lowerarm, flip] = conf_RLF_1
   300             str_config = 
'shoulder="%s" elbow="%s" wrist="%s"' % (
"righty" if rear>0 
else "lefty", 
"enegative" if lowerarm>0 
else "epositive", 
"wnegative" if flip>0 
else "wpositive")
   308     def setFrame(self, pose, frame_id=None, frame_name=None):
   309         """Change the robot reference frame"""   315     def setTool(self, pose, tool_id=None, tool_name=None):
   316         """Change the robot TCP"""   323         """Pause the robot program"""   325             self.
addline(
'popUpMsg("Paused. Press OK to continue")')
   327             self.
addline(
'delay(%.3f)' % (time_ms*0.001))
   330         """Changes the robot speed (in mm/s)"""   340         """Changes the robot acceleration (in mm/s2)"""   344         """Changes the robot joint speed (in deg/s)"""   348         """Changes the robot joint acceleration (in deg/s2)"""   352         """Changes the zone data approach (makes the movement more smooth)"""   356         """Sets a variable (output) to a given value"""   357         if type(io_var) != str:  
   358             io_var = 
'OUT[%s]' % str(io_var)        
   359         if type(io_value) != str: 
   366         self.
addline(
'%s=%s' % (io_var, io_value))
   368     def waitDI(self, io_var, io_value, timeout_ms=-1):
   369         """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided."""   370         if type(io_var) != str:  
   371             io_var = 
'IN[%s]' % str(io_var)        
   372         if type(io_value) != str: 
   380             self.
addline(
'WAIT FOR %s==%s' % (io_var, io_value))
   382             self.
addline(
'WAIT FOR %s==%s TIMEOUT=%.1f' % (io_var, io_value, timeout_ms))   
   384     def RunCode(self, code, is_function_call = False):
   385         """Adds code or a function call"""   387             code.replace(
' ',
'_')
   388             if not code.endswith(
')'):
   392             self.
addline(
'//call prog:%s' % code)
   397         """Display a message in the robot controller screen (teach pendant)"""   401             self.
addline(
'popUpMsg("%s")' % message)
   405         """Add a program line"""   409         """Add a log message"""   410         self.
LOG = self.
LOG + newline + 
'\n'   415     [x,y,z,r,p,w] = xyzrpw
   425     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]])
   428     """Test the post with a basic program"""   432     robot.ProgStart(
"Program")
   433     robot.RunMessage(
"Program generated by RoboDK using a custom post processor", 
True)
   434     robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
   435     robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
   436     robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
   437     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   438     robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
   439     robot.RunMessage(
"Setting air valve 1 on")
   440     robot.RunCode(
"TCP_On", 
True)
   442     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   443     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   444     robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
   445     robot.RunMessage(
"Setting air valve off")
   446     robot.RunCode(
"TCP_Off", 
True)
   448     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   449     robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
   450     robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
   451     robot.ProgFinish(
"Program")
   453     print(robot.PROG_PGX)
   454     if len(robot.LOG) > 0:
   455         mbox(
'Program generation LOG:\n\n' + robot.LOG)
   457     input(
"Press Enter to close...")
   459 if __name__ == 
"__main__":
   460     """Function to call when the module is executed by itself: test""" 
def getSaveFolder(strdir='C:\\', strtitle='Save program folder ...')
def RunCode(self, code, is_function_call=False)
def setZoneData(self, zone_mm)
def RunMessage(self, message, iscomment=False)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def ProgStart(self, progname)
def setFrame(self, pose, frame_id=None, frame_name=None)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def addline(self, newline)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def ProgFinish(self, progname)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def MoveJ(self, pose, joints, conf_RLF=None)
def addlog(self, newline)
def setDO(self, io_var, io_value)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def setSpeed(self, speed_mms)
def setAcceleration(self, accel_mmss)
def setSpeedJoints(self, speed_degs)
def setTool(self, pose, tool_id=None, tool_name=None)
def setAccelerationJoints(self, accel_degss)
def MoveL(self, pose, joints, conf_RLF=None)
def waitDI(self, io_var, io_value, timeout_ms=-1)