49 HEADER = 
'''package application;    51 import com.kuka.roboticsAPI.applicationModel.RoboticsAPIApplication;    52 import static com.kuka.roboticsAPI.motionModel.BasicMotions.*;    54 import com.kuka.roboticsAPI.deviceModel.LBR;    55 import com.kuka.roboticsAPI.deviceModel.LBRE1Redundancy;    56 import com.kuka.roboticsAPI.geometricModel.Frame;    57 import com.kuka.roboticsAPI.geometricModel.Tool;    58 import com.kuka.roboticsAPI.geometricModel.math.Transformation;    60 import com.kuka.roboticsAPI.motionModel.LIN;    61 import com.kuka.roboticsAPI.motionModel.PTP;    62 import com.kuka.roboticsAPI.motionModel.Spline;    63 import com.kuka.roboticsAPI.uiModel.ApplicationDialogType;    65 public class %s extends RoboticsAPIApplication {    68 \t// private Frame FRAME;    70 \tpublic void initialize() {                71 \t\trobot = getContext().getDeviceFromType(LBR.class);    74 \t\tSpline move_curve;    79     """Converts a pose target to a string"""    85     return (
'%.3f,%.3f,%.3f,%.5f,%.5f,%.5f' % (x,y,z,w*torad,p*torad,r*torad))
    93         for i 
in range(njoints-7):
    94             extaxes = extaxes + (
',%.5f' % (i+1, joints[i+7]))
    98     """Prints a joint target"""   100     for i 
in range(len(angles)):
   101         str = str + (
'%.5f,' % (angles[i]*pi/180.0))
   108     """Robot post object"""   119     MOVE_OBJECT = 
'robot'   131     SPLINE_LAST_FRAME = 
''   135     def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
   144             self.
addline(
'public void %s() {' % progname.replace(
' ',
'_'))
   154     def ProgSave(self, folder, progname, ask_user = False, show_result = False):
   158         progname = progname + 
'.' + self.
PROG_EXT   160             filesave = 
getSaveFile(folder, progname, 
'Save program as...')
   161             if filesave 
is not None:
   162                 filesave = filesave.name
   167             filesave = folder + 
'/' + progname
   168         fid = open(filesave, 
"w")
   169         fid.write(HEADER % progname_base)
   172         print(
'SAVED: %s\n' % filesave) 
   177             if type(show_result) 
is str:
   180                 p = subprocess.Popen([show_result, filesave])
   181             elif type(show_result) 
is list:
   183                 p = subprocess.Popen(show_result + [filesave])   
   188                 os.startfile(filesave)
   189             if len(self.
LOG) > 0:
   190                 mbox(
'Program generation LOG:\n\n' + self.
LOG)
   193         """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".   194         The connection parameters must be provided in the robot connection menu of RoboDK"""   197     def MoveJ(self, pose, joints, conf_RLF=None):
   198         """Add a joint movement"""   209     def MoveL(self, pose, joints, conf_RLF=None):
   210         """Add a linear movement"""      231     def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
   232         """Add a circular movement"""   241         self.
addline(
'getLogger().info("Move circular to %s and %s");' % (framename1, framename2))
   246     def setFrame(self, pose, frame_id=None, frame_name=None):
   247         """Change the robot reference frame"""   248         if frame_name 
is None:
   249             frame_name = 
"Reference"   253         self.
addline(
'// Using Reference Frame: %s' % frame_name)
   254         self.
addline(
'// robot.addDefaultMotionFrame("%s", Transformation.ofDeg(%s);' % (frame_name,
pose_2_str(pose, 
True)))
   256     def setTool(self, pose, tool_id=None, tool_name=None):
   257         """Change the robot TCP"""   258         if tool_name 
is None:
   261         self.
addline(
'// Using TCP: %s' % tool_name)
   262         self.
addline(
'TOOL = new Tool("%s");' % tool_name)
   263         self.
addline(
'TOOL.attachTo(robot.getFlange(), Transformation.ofDeg(%s));' % 
pose_2_str(pose, 
True))
   268         """Pause the robot program"""   271             self.
addline(
'if (getApplicationUI().displayModalDialog(ApplicationDialogType.QUESTION, "Program paused. Select Cancel to stop the program.", "OK", "Cancel") == 1)')
   276             self.
addline(
'Thread.sleep(%.3f);' % (time_ms))
   279         """Changes the robot speed (in mm/s)"""   285         """Changes the current robot acceleration"""   286         self.
addline(
'// Warning: set linear acceleration to %.3f mm/ss has no effect' % accel_mmss)
   290         """Changes the robot joint speed (in deg/s)"""           295         """Changes the robot joint acceleration (in deg/s2)"""   296         self.
addline(
'// Warning: set angular acceleration to %.3f deg/s has no effect' % accel_degss)
   299         """Changes the zone data approach (makes the movement more smooth)"""           303         self.
addline(
'// smoothing/blending set to %.1f mm' % zone_mm)
   307         """Sets a variable (output) to a given value"""   308         if type(io_var) != str:  
   309             io_var = 
'OUT[%s]' % str(io_var)        
   310         if type(io_value) != str: 
   317         self.
addline(
'%s=%s' % (io_var, io_value))
   319     def waitDI(self, io_var, io_value, timeout_ms=-1):
   320         """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided."""   321         if type(io_var) != str:  
   322             io_var = 
'IN[%s]' % str(io_var)        
   323         if type(io_value) != str: 
   331             self.
addline(
'WAIT FOR %s==%s' % (io_var, io_value))
   333             self.
addline(
'WAIT FOR %s==%s TIMEOUT=%.1f' % (io_var, io_value, timeout_ms))   
   335     def RunCode(self, code, is_function_call = False):
   336         """Adds code or a function call"""   339             code.replace(
' ',
'_')
   346         """Add a joint movement"""   352             self.
addline(
'getLogger().info("%s");' % message)      
   356         """Add a program line"""   368             self.
PROG = self.
PROG + self.
TAB + 
'move_curve = new Spline(' + self.
SPLINE[:-1] + 
');\n'   376         """Add a log message"""   377         self.
LOG = self.
LOG + newline + 
'\n'   382     [x,y,z,r,p,w] = xyzrpw
   392     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]])
   395     """Test the post with a basic program"""   397     robot = 
RobotPost(
'Kuka_custom', 
'Generic Kuka')
   399     robot.ProgStart(
"Program")
   400     robot.RunMessage(
"Program generated by RoboDK", 
True)
   401     robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
   403     robot.waitDI(125,1,1000)
   405     robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
   406     robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
   407     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   408     robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
   409     robot.RunMessage(
"Setting air valve 1 on")
   410     robot.RunCode(
"TCP_On", 
True)
   412     robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
   413     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   414     robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
   415     robot.RunMessage(
"Setting air valve off")
   416     robot.RunCode(
"TCP_Off", 
True)
   418     robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
   419     robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
   420     robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
   421     robot.ProgFinish(
"Program")
   424     if len(robot.LOG) > 0:
   425         mbox(
'Program generation LOG:\n\n' + robot.LOG)
   427     input(
"Press Enter to close...")
   429 if __name__ == 
"__main__":
   430     """Function to call when the module is executed by itself: test""" 
def pose_2_str(pose, rot_in_deg=False)
def setSpeedJoints(self, speed_degs)
def ProgFinish(self, progname)
def getFileName(filepath)
def setSpeed(self, speed_mms)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def setAccelerationJoints(self, accel_degss)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def setTool(self, pose, tool_id=None, tool_name=None)
def RunMessage(self, message, iscomment=False)
def pose_2_str_ext(pose, joints)
def RunCode(self, code, is_function_call=False)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def MoveJ(self, pose, joints, conf_RLF=None)
def setAcceleration(self, accel_mmss)
def addlog(self, newline)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def spline_addbuffer(self, frame)
def setFrame(self, pose, frame_id=None, frame_name=None)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def setZoneData(self, zone_mm)
def MoveL(self, pose, joints, conf_RLF=None)
def ProgStart(self, progname)
def addline(self, newline)
def setDO(self, io_var, io_value)