55 PDAT_ACT = {VEL 50,ACC 100,APO_DIST 10}    57 FDAT_ACT = {TOOL_NO 0,BASE_NO 0,IPO_FRAME #BASE}    63 ;FOLD SET DEFAULT SPEED    70 ;FOLD PTP FIRST POSITION    72 PDAT_ACT = {VEL 50,ACC 100,APO_DIST 10}    73 FDAT_ACT = {TOOL_NO 0,BASE_NO 0,IPO_FRAME #BASE}    78 PTP $AXIS_ACT ; skip BCO quickly    83     """Converts a pose target to a string"""    87     return (
'X %.3f,Y %.3f,Z %.3f,A %.3f,B %.3f,C %.3f' % (x,y,z,w,p,r))
    95         for i 
in range(njoints-6):
    96             extaxes = extaxes + (
',E%i %.5f' % (i+1, joints[i+6]))
   100     """Prints a joint target"""   102     data = [
'A1',
'A2',
'A3',
'A4',
'A5',
'A6',
'E1',
'E2',
'E3',
'E4',
'E5',
'E6']
   103     for i 
in range(len(angles)):
   104         str = str + (
'%s %.5f,' % (data[i], angles[i]))
   113         strconf = strconf + 
'1'   115         strconf = strconf + 
'0'   118         strconf = strconf + 
'1'   120         strconf = strconf + 
'0'   123         strconf = strconf + 
'1'   125         strconf = strconf + 
'0'   127     return "'B%s'" % strconf    
   134     for i 
in range(len(joints)):
   136             strturn = 
'1' + strturn
   138             strturn = 
'0' + strturn
   139     return "'B%s'" % strturn  
   145     """Robot post object"""   161     def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
   169         self.
addline(
'DEF %s ( )' % progname)
   177     def ProgSave(self, folder, progname, ask_user = False, show_result = False):
   178         progname = progname + 
'.' + self.
PROG_EXT   180             filesave = 
getSaveFile(folder, progname, 
'Save program as...')
   181             if filesave 
is not None:
   182                 filesave = filesave.name
   186             filesave = folder + 
'/' + progname
   187         fid = open(filesave, 
"w")
   190         print(
'SAVED: %s\n' % filesave) 
   195             if type(show_result) 
is str:
   198                 p = subprocess.Popen([show_result, filesave])
   199             elif type(show_result) 
is list:
   201                 p = subprocess.Popen(show_result + [filesave])   
   206                 os.startfile(filesave)
   207             if len(self.
LOG) > 0:
   208                 mbox(
'Program generation LOG:\n\n' + self.
LOG)
   211         """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".   212         The connection parameters must be provided in the robot connection menu of RoboDK"""   215     def MoveJ(self, pose, joints, conf_RLF=None):
   216         """Add a joint movement"""   219     def MoveL(self, pose, joints, conf_RLF=None):
   220         """Add a linear movement"""   225     def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
   226         """Add a circular movement"""   230     def setFrame(self, pose, frame_id=None, frame_name=None):
   231         """Change the robot reference frame"""   234     def setTool(self, pose, tool_id=None, tool_name=None):
   235         """Change the robot TCP"""   239         """Pause the robot program"""   243             self.
addline(
'WAIT SEC %.3f' % (time_ms*0.001))
   246         """Changes the robot speed (in mm/s)"""   247         self.
addline(
'$VEL.CP = %.5f' % (speed_mms/1000.0))
   250         """Changes the current robot acceleration"""   251         self.
addlog(
'setAcceleration not defined')
   254         """Changes the robot joint speed (in deg/s)"""   255         self.
addlog(
'setSpeedJoints not defined')
   258         """Changes the robot joint acceleration (in deg/s2)"""   259         self.
addlog(
'setAccelerationJoints not defined')
   262         """Changes the zone data approach (makes the movement more smooth)"""   265             self.
addline(
'$APO.CPTP = %.3f' % zone_mm)
   266             self.
addline(
'$APO.CDIS = %.3f' % zone_mm)
   274         """Sets a variable (output) to a given value"""   275         if type(io_var) != str:  
   276             io_var = 
'$OUT[%s]' % str(io_var)        
   277         if type(io_value) != str: 
   284         self.
addline(
'%s=%s' % (io_var, io_value))
   286     def waitDI(self, io_var, io_value, timeout_ms=-1):
   287         """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided."""   288         if type(io_var) != str:  
   289             io_var = 
'$IN[%s]' % str(io_var)        
   290         if type(io_value) != str: 
   298             self.
addline(
'WAIT FOR (%s==%s)' % (io_var, io_value))
   301             self.
addline(
'$TIMER_STOP[1]=TRUE')
   302             self.
addline(
'$TIMER_FLAG[1]=FALSE')
   303             self.
addline(
'$TIMER[1]=%.3f' % (float(timeout_ms)*0.001))
   304             self.
addline(
'$TIMER_STOP[1]=FALSE')
   305             self.
addline(
'WAIT FOR (%s==%s OR $TIMER_FLAG[1])' % (io_var, io_value))
   306             self.
addline(
'$TIMER_STOP[1]=TRUE')
   307             self.
addline(
'IF $TIMER_FLAG[1]== TRUE THEN')
   308             self.
addline(
'    HALT ; Timed out!')
   309             self.
addline(
'    GOTO START_TIMER')
   312     def RunCode(self, code, is_function_call = False):
   313         """Adds code or a function call"""   315             code.replace(
' ',
'_')
   316             if not code.endswith(
')'):
   323         """Add a joint movement"""   327             self.
addline(
'Wait for StrClear($LOOP_MSG[])')
   328             self.
addline(
'$LOOP_CONT = TRUE')
   329             self.
addline(
'$LOOP_MSG[] = "%s"' % message)
   333         """Add a program line"""   334         self.
PROG = self.
PROG + newline + 
'\n'   337         """Add a log message"""   338         self.
LOG = self.
LOG + newline + 
'\n'   343     [x,y,z,r,p,w] = xyzrpw
   353     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]])
   356     """Test the post with a basic program"""   358     robot = 
RobotPost(
'Kuka_custom', 
'Generic Kuka')
   360     robot.ProgStart(
"Program")
   361     robot.RunMessage(
"Program generated by RoboDK", 
True)
   362     robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
   363     robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
   364     robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
   365     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   366     robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
   367     robot.RunMessage(
"Setting air valve 1 on")
   368     robot.RunCode(
"TCP_On", 
True)
   370     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   371     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   372     robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
   373     robot.RunMessage(
"Setting air valve off")
   374     robot.RunCode(
"TCP_Off", 
True)
   376     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   377     robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
   378     robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
   379     robot.ProgFinish(
"Program")
   382     if len(robot.LOG) > 0:
   383         mbox(
'Program generation LOG:\n\n' + robot.LOG)
   385     input(
"Press Enter to close...")
   387 if __name__ == 
"__main__":
   388     """Function to call when the module is executed by itself: test""" def setSpeed(self, speed_mms)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def ProgFinish(self, progname)
def setAccelerationJoints(self, accel_degss)
def setDO(self, io_var, io_value)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def MoveJ(self, pose, joints, conf_RLF=None)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def MoveL(self, pose, joints, conf_RLF=None)
def joints_2_turn_str(joints)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def setZoneData(self, zone_mm)
def setTool(self, pose, tool_id=None, tool_name=None)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def addlog(self, newline)
def setAcceleration(self, accel_mmss)
def setFrame(self, pose, frame_id=None, frame_name=None)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def RunMessage(self, message, iscomment=False)
def RunCode(self, code, is_function_call=False)
def setSpeedJoints(self, speed_degs)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def ProgStart(self, progname)
def addline(self, newline)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def pose_2_str_ext(pose, joints)