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
   115     def pose_2_str(self, pose, remember_last=False, joints=None):
   116         """Prints a pose target"""   123         if joints 
is not None and len(joints) > 5:
   124             strjnts = 
" Y2=%.3f" % joints[5]
   129                 G_LINE += 
'X%.3f ' % x
   131                 G_LINE += 
'Y%.3f ' % y
   132             if self.
LAST_Z != z 
or len(G_LINE) == 0:
   133                 G_LINE += 
'Z%.3f ' % z
   134             G_LINE += 
'A3=%.3f ' % i
   135             G_LINE += 
'B3=%.3f ' % j
   136             G_LINE += 
'C3=%.3f ' % k
   141             return G_LINE + strjnts
   143             return (
'X%.3f Y%.3f Z%.3f A3%.3f B3%.3f C3%.3f%s' % (x,y,z,i,j,k,strjnts))
   146         """Prints a joint target"""   148         data = [
'ST1',
'ST2',
'ST3',
'A',
'C',
'G',
'H',
'I',
'J',
'K',
'L']
   149         for i 
in range(len(joints)):
   150             str = str + (
'%s=%.6f ' % (data[i], joints[i]))
   155     def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
   167             self.
addcomment(
'Created on %s' % datetime.datetime.now().strftime(
"%Y-%m-%d %H:%M:%S"))
   168             self.
addcomment(
'Program created using RoboDK')
   169             if MM_2_UNITS == 1.0:
   170                 self.
addline(
'G710 G40 ; metric, no tool radius compensation')
   171             elif MM_2_UNITS == 1.0/25.4:
   172                 self.
addline(
'G700 G40 ; inch, no tool radius compensation')
   174                 raise Exception(
"Unknown units!! Define MM_2_UNITS properly.")
   176             self.
addline(
'G17 G94 G90 G60 G601 FNORM')            
   177             self.
addline(
'SOFT ; Smooth acceleration')            
   178             self.
addline(
'FFWON ; Look ahead')
   181             self.
addline(
'DYNNORM ; Specific settings for acceleration')
   182             self.
addline(
'COMPCAD ; Not working with radius compensation')
   187             self.
addcomment(
'---------- Subprogram: %s ----------' % progname)
   200             self.
addcomment(
'End of main program ' + progname)
   202             self.
addcomment(
'---------------------------')
   207             self.
addline(
'GOTOB ' + progname + 
"_done")
   208             self.
addcomment(
'------------------------------------')
   211     def ProgSave(self, folder, progname, ask_user=False, show_result=False):
   212         progname = progname + 
'.' + self.
PROG_EXT   214             filesave = 
getSaveFile(folder, progname, 
'Save program as...')
   215             if filesave 
is not None:
   216                 filesave = filesave.name
   220             filesave = folder + 
'/' + progname
   221         fid = open(filesave, 
"w")
   224         print(
'SAVED: %s\n' % filesave)
   227             if type(show_result) 
is str:
   230                 p = subprocess.Popen([show_result, filesave])   
   231             elif type(show_result) 
is list:
   233                 p = subprocess.Popen(show_result + [filesave])   
   237                 os.startfile(filesave)  
   239             if len(self.
LOG) > 0:
   240                 mbox(
'Program generation LOG:\n\n' + self.
LOG)
   243         """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".   244         The connection parameters must be provided in the robot connection menu of RoboDK"""   258     def MoveJ(self, pose, joints, conf_RLF=None):
   259         """Add a joint movement"""   270     def MoveL(self, pose, joints, conf_RLF=None):
   271         """Add a linear movement"""   293                 steps = int(angle/(1))
   294                 steps = float(max(1,steps))
   295                 self.
addline(
'; next move %.1f deg divided in %i steps' % (angle, steps))
   302                 for i 
in range(int(steps)):
   304                     hi = 
UR_2_Pose([xd*factor,yd*factor,zd*factor,wd*factor,pd*factor,rd*factor])
   309     def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
   310         """Add a circular movement"""   316         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))
   318     def setFrame(self, pose, frame_id=None, frame_name=None):
   319         """Change the robot reference frame"""   320         self.
addcomment(
'------ Update reference: %s ------' % (frame_name 
if frame_name 
is not None else ''))
   327         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))
   329         self.
addcomment(
'---------------------------')
   333     def setTool(self, pose, tool_id=None, tool_name=None):
   334         """Change the robot TCP"""   341         self.
addcomment(
'------ Update TCP: %s ------' % (tool_name 
if tool_name 
is not None else ''))
   359         self.
addline(
'T="%s" D1' % tool_name) 
   361         self.
addcomment(
'---------------------------- ')
   365         """Pause the robot program"""   370             self.
addline(
'G4 F%.0f ; pause in seconds' % (time_ms*0.001))
   373         """Changes the robot speed (in mm/s)"""   377         """Changes the robot acceleration (in mm/s2)"""   378         self.
addcomment(
'Acceleration set to %.3f mm/s2' % accel_mmss)
   381         """Changes the robot joint speed (in deg/s)"""   386         """Changes the robot joint acceleration (in deg/s2)"""   387         self.
addcomment(
'Joint acceleration set to %.3f deg/s2' % accel_degss)
   390         """Changes the rounding radius (aka CNT, APO or zone data) to make the movement smoother"""   393             self.
addline(
'CYCLE832(0,_OFF,1)')
   395             self.
addline(
'CYCLE832(0.1,_FINISH,1)')
   398         """Sets a variable (digital output) to a given value"""   399         comment = 
'Set digital output %s = %s' % (io_var, io_value)
   400         if type(io_var) != str:  
   401             io_var = 
'P%s' % str(io_var)
   402         if type(io_value) != str: 
   404                 io_value = M_SET_DO_HIGH
   406                 io_value = M_SET_DO_LOW
   409         self.
addline(
'%s %s ; %s' % (io_value, io_var, comment))
   411     def waitDI(self, io_var, io_value, timeout_ms=-1):
   412         """Waits for a variable (digital input) io_var to attain a given value io_value. Optionally, a timeout can be provided."""   413         comment = 
'Wait Digital Input %s = %s' % (io_var, io_value)
   415             comment = comment + 
' (timeout = %.3f)' % (timeout_ms*0.001)
   417         if type(io_var) != str:  
   418             io_var = 
'P%s' % str(io_var)
   419         if type(io_value) != str: 
   427             self.
addline(
'%s %s %s Q9999; %s' % (M_WAIT_DI, io_var, io_value, comment))
   429             self.
addline(
'%s %s %s Q%.3f; %s' % (M_WAIT_DI, io_var, io_value, timeout_ms*0.001, comment))
   431     def RunCode(self, code, is_function_call = False):
   432         """Adds code or a function call"""   434             code.replace(
' ',
'_')
   437             if code.lower().startswith(
"setrpm("):
   439                 new_rpm = float(code[7:-1]) 
   450         """Display a message in the robot controller screen (teach pendant)"""   454             self.
addcomment(
'Display message: %s' % message)
   458         """Add a program line"""   460         self.
PROG = self.
PROG + (
'N%02i ' % self.
Nline) + newline + 
'\n'           463         """Add a comment line"""   464         self.
PROG = self.
PROG + 
'; ' + newline + 
'\n'   467         """Add a log message"""   468         self.
LOG = self.
LOG + newline + 
'\n'   473     [x,y,z,r,p,w] = xyzrpw
   483     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]])
   486     """Test the post with a basic program"""   490     robot.ProgStart(
"Program")
   491     robot.RunMessage(
"Program generated by RoboDK using a custom post processor", 
True)
   492     robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
   493     robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
   494     robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
   495     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   496     robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
   497     robot.RunMessage(
"Setting air valve 1 on")
   498     robot.RunCode(
"TCP_On", 
True)
   500     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   501     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   502     robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
   503     robot.RunMessage(
"Setting air valve off")
   504     robot.RunCode(
"TCP_Off", 
True)
   506     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   507     robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
   508     robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
   509     robot.MoveJ(
None, [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
   510     robot.ProgFinish(
"Program")
   513     if len(robot.LOG) > 0:
   514         mbox(
'Program generation LOG:\n\n' + robot.LOG)
   516     input(
"Press Enter to close...")
   518 if __name__ == 
"__main__":
   519     """Function to call when the module is executed by itself: test""" 
def set_cartesian_space(self)
def setDO(self, io_var, io_value)
def MoveL(self, pose, joints, conf_RLF=None)
def pose_2_str(self, pose, remember_last=False, joints=None)
def addlog(self, newline)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def MoveJ(self, pose, joints, conf_RLF=None)
def setAccelerationJoints(self, accel_degss)
def setSpeedJoints(self, speed_degs)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def addcomment(self, newline)
def setFrame(self, pose, frame_id=None, frame_name=None)
def setSpeed(self, speed_mms)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def ProgStart(self, progname)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def ProgFinish(self, progname)
def joints_2_str(self, joints)
def setAcceleration(self, accel_mmss)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def setTool(self, pose, tool_id=None, tool_name=None)
def addline(self, newline)
def set_joint_space(self)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def setZoneData(self, zone_mm)
def RunMessage(self, message, iscomment=False)
def RunCode(self, code, is_function_call=False)