78     for i 
in range(njoints):
    80             turn = turn + 2**(njoints-1-i)
    87     """Robot post object"""   103     SPEED_UNITS_MIN = 5000 * MM_2_UNITS
   116         """Prints a pose target"""   124                 G_LINE += 
'X%.3f ' % x
   126                 G_LINE += 
'Y%.3f ' % y
   127             if self.
LAST_Z != z 
or len(G_LINE) == 0:
   128                 G_LINE += 
'Z%.3f ' % z
   129             G_LINE += 
'A=%.3f ' % a
   130             G_LINE += 
'B=%.3f ' % b
   131             G_LINE += 
'C=%.3f ' % c
   138             return (
'X%.3f Y%.3f Z%.3f A%.3f B%.3f C%.3f' % (x,y,z,a,b,c))
   141         """Prints a joint target"""   143         data = [
'JT1',
'JT2',
'JT3',
'A',
'B',
'C',
'G',
'H',
'I',
'J',
'K',
'L']
   144         for i 
in range(len(joints)):
   145             str = str + (
'%s=%.6f ' % (data[i], joints[i]))
   150     def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
   162             self.
addcomment(
'Created on %s' % datetime.datetime.now().strftime(
"%Y-%m-%d %H:%M:%S"))
   163             self.
addcomment(
'Program created using RoboDK')            
   164             if MM_2_UNITS == 1.0:
   165                 self.
addline(
'G17 G710 G40 ; XY plane selection, metric, no tool radius compensation')
   166             elif MM_2_UNITS == 1.0/25.4:
   167                 self.
addline(
'G17 G700 G40 ; XY plane selection, inch')
   169                 raise Exception(
"Unknown units!! Define MM_2_UNITS properly.")
   183             self.
addline(
'STOPRE ; stop preprocessing')
   192             self.
addline(
'; M3 S7458 ; Generic way to turn on the spindle') 
   193             self.
addline(
'S1700.0 M80 ; Customized Spindle speed and power on')
   198             self.
addcomment(
'---------- Subprogram: %s ----------' % progname)
   207             self.
addcomment(
'End of main program ' + progname)
   209             self.
addcomment(
'---------------------------')
   214             self.
addline(
'GOTOB ' + progname + 
"_done")
   215             self.
addcomment(
'------------------------------------')
   218     def ProgSave(self, folder, progname, ask_user=False, show_result=False):
   219         progname = progname + 
'.' + self.
PROG_EXT   221             filesave = 
getSaveFile(folder, progname, 
'Save program as...')
   222             if filesave 
is not None:
   223                 filesave = filesave.name
   227             filesave = folder + 
'/' + progname
   228         fid = open(filesave, 
"w")
   231         print(
'SAVED: %s\n' % filesave)
   234             if type(show_result) 
is str:
   237                 p = subprocess.Popen([show_result, filesave])   
   238             elif type(show_result) 
is list:
   240                 p = subprocess.Popen(show_result + [filesave])   
   244                 os.startfile(filesave)  
   246             if len(self.
LOG) > 0:
   247                 mbox(
'Program generation LOG:\n\n' + self.
LOG)
   250         """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".   251         The connection parameters must be provided in the robot connection menu of RoboDK"""   265     def MoveJ(self, pose, joints, conf_RLF=None):
   266         """Add a joint movement"""   277     def MoveL(self, pose, joints, conf_RLF=None):
   278         """Add a linear movement"""   300                 steps = int(angle/(1))
   301                 steps = float(max(1,steps))
   302                 self.
addline(
'; next move %.1f deg divided in %i steps' % (angle, steps))
   309                 for i 
in range(int(steps)):
   311                     hi = 
UR_2_Pose([xd*factor,yd*factor,zd*factor,wd*factor,pd*factor,rd*factor])
   316     def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
   317         """Add a circular movement"""   323         self.
addline(
'G2 X%.3f Y%.3f Z%.3f I1=%.3f J1=%.3f K1=%.3f F%.1f' % (xyz2[0], xyz2[1], xyz2[2], xyz1[0], xyz1[1], xyz1[2], self.
SPEED_UNITS_MIN))
   325     def setFrame(self, pose, frame_id=None, frame_name=None):
   326         """Change the robot reference frame"""   327         self.
addcomment(
'------ Update reference: %s ------' % (frame_name 
if frame_name 
is not None else ''))
   339         self.
addline(
'$P_UIFR[1]=CTRANS(X,%.5f,Y,%.5f,Z,%.5f):CROT(X,%.5f,Y,%.5f,Z,%.5f)' % (x,y,z,a,b,c))
   341         self.
addcomment(
'---------------------------')
   343     def setTool(self, pose, tool_id=None, tool_name=None):
   344         """Change the robot TCP"""   351         self.
addcomment(
'------ Update TCP: %s ------' % (tool_name 
if tool_name 
is not None else ''))
   360         self.
addline(
'$TC_DP5[1,1]=%.5f' % x)
   361         self.
addline(
'$TC_DP4[1,1]=%.5f' % y)
   362         self.
addline(
'$TC_DP3[1,1]=%.5f' % z)
   366         self.
addline(
'$TC_DPC3[1,1]=0.0')        
   367         self.
addline(
'$TC_DPC2[1,1]=0.0')
   368         self.
addline(
'$TC_DPC1[1,1]=0.0')
   370         self.
addcomment(
'---------------------------- ')        
   373         """Pause the robot program"""   378             self.
addline(
'G4 F%.0f ; pause in seconds' % (time_ms*0.001))
   381         """Changes the robot speed (in mm/s)"""   385         """Changes the robot acceleration (in mm/s2)"""   386         self.
addcomment(
'Acceleration set to %.3f mm/s2' % accel_mmss)
   389         """Changes the robot joint speed (in deg/s)"""   394         """Changes the robot joint acceleration (in deg/s2)"""   395         self.
addcomment(
'Joint acceleration set to %.3f deg/s2' % accel_degss)
   398         """Changes the rounding radius (aka CNT, APO or zone data) to make the movement smoother"""   401             self.
addline(
'CYCLE832(0,_OFF,1)')
   403             self.
addline(
'CYCLE832(0.1,_FINISH,1)')
   406         """Sets a variable (digital output) to a given value"""   407         comment = 
'Set digital output %s = %s' % (io_var, io_value)
   408         if type(io_var) != str:  
   409             io_var = 
'P%s' % str(io_var)
   410         if type(io_value) != str: 
   412                 io_value = M_SET_DO_HIGH
   414                 io_value = M_SET_DO_LOW
   417         self.
addline(
'%s %s ; %s' % (io_value, io_var, comment))
   419     def waitDI(self, io_var, io_value, timeout_ms=-1):
   420         """Waits for a variable (digital input) io_var to attain a given value io_value. Optionally, a timeout can be provided."""   421         comment = 
'Wait Digital Input %s = %s' % (io_var, io_value)
   423             comment = comment + 
' (timeout = %.3f)' % (timeout_ms*0.001)
   425         if type(io_var) != str:  
   426             io_var = 
'P%s' % str(io_var)
   427         if type(io_value) != str: 
   435             self.
addline(
'%s %s %s Q9999; %s' % (M_WAIT_DI, io_var, io_value, comment))
   437             self.
addline(
'%s %s %s Q%.3f; %s' % (M_WAIT_DI, io_var, io_value, timeout_ms*0.001, comment))
   439     def RunCode(self, code, is_function_call = False):
   440         """Adds code or a function call"""   442             code.replace(
' ',
'_')
   451         """Display a message in the robot controller screen (teach pendant)"""   455             self.
addcomment(
'Display message: %s' % message)
   459         """Add a program line"""   461         self.
PROG = self.
PROG + (
'N%02i ' % self.
Nline) + newline + 
'\n'           464         """Add a comment line"""   465         self.
PROG = self.
PROG + 
'; ' + newline + 
'\n'   468         """Add a log message"""   469         self.
LOG = self.
LOG + newline + 
'\n'   474     [x,y,z,r,p,w] = xyzrpw
   484     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]])
   487     """Test the post with a basic program"""   491     robot.ProgStart(
"Program")
   492     robot.RunMessage(
"Program generated by RoboDK using a custom post processor", 
True)
   493     robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
   494     robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
   495     robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
   496     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   497     robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
   498     robot.RunMessage(
"Setting air valve 1 on")
   499     robot.RunCode(
"TCP_On", 
True)
   501     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   502     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   503     robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
   504     robot.RunMessage(
"Setting air valve off")
   505     robot.RunCode(
"TCP_Off", 
True)
   507     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   508     robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
   509     robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
   510     robot.MoveJ(
None, [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
   511     robot.ProgFinish(
"Program")
   514     if len(robot.LOG) > 0:
   515         mbox(
'Program generation LOG:\n\n' + robot.LOG)
   517     input(
"Press Enter to close...")
   519 if __name__ == 
"__main__":
   520     """Function to call when the module is executed by itself: test""" 
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def RunCode(self, code, is_function_call=False)
def ProgFinish(self, progname)
def setSpeed(self, speed_mms)
def addlog(self, newline)
def setAccelerationJoints(self, accel_degss)
def set_joint_space(self)
def setDO(self, io_var, io_value)
def MoveL(self, pose, joints, conf_RLF=None)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def MoveJ(self, pose, joints, conf_RLF=None)
def setTool(self, pose, tool_id=None, tool_name=None)
def setSpeedJoints(self, speed_degs)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def addline(self, newline)
def addcomment(self, newline)
def RunMessage(self, message, iscomment=False)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def setAcceleration(self, accel_mmss)
def setZoneData(self, zone_mm)
def ProgStart(self, progname)
def setFrame(self, pose, frame_id=None, frame_name=None)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def pose_2_str(self, pose, remember_last=False)
def set_cartesian_space(self)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def joints_2_str(self, joints)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)