58 FDAT_ACT = {TOOL_NO 0,BASE_NO 0,IPO_FRAME #BASE} 62 ;FOLD SET DEFAULT SPEED 71 PTP $AXIS_ACT ; skip BCO quickly 76 """Converts a pose target to a string""" 80 return (
'X %.3f,Y %.3f,Z %.3f,A %.3f,B %.3f,C %.3f' % (x,y,z,w,p,r))
88 for i
in range(njoints-6):
89 extaxes = extaxes + (
',E%i %.5f' % (i+1, joints[i+6]))
93 """Prints a joint target""" 95 data = [
'A1',
'A2',
'A3',
'A4',
'A5',
'A6',
'E1',
'E2',
'E3',
'E4',
'E5',
'E6']
96 for i
in range(len(angles)):
97 str = str + (
'%s %.5f,' % (data[i], angles[i]))
106 strconf = strconf +
'1' 108 strconf = strconf +
'0' 111 strconf = strconf +
'1' 113 strconf = strconf +
'0' 116 strconf = strconf +
'1' 118 strconf = strconf +
'0' 120 return "'B%s'" % strconf
127 for i
in range(len(joints)):
129 strturn =
'1' + strturn
131 strturn =
'0' + strturn
132 return "'B%s'" % strturn
138 """Robot post object""" 145 PROG_NAME =
'unknown' 171 def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
180 self.
addline(
'DEF %s ( )' % progname)
190 def ProgSave(self, folder, progname, ask_user = False, show_result = False):
191 progname = progname +
'.' + self.
PROG_EXT 193 filesave =
getSaveFile(folder, progname,
'Save program as...')
194 if filesave
is not None:
195 filesave = filesave.name
199 filesave = folder +
'/' + progname
200 fid = open(filesave,
"w")
204 fid.write(
"&ACCESS RVP\n")
205 fid.write(
"&REL 1\n")
206 fid.write(
"&PARAM TEMPLATE = C:\\KRC\\Roboter\\Template\\vorgabe\n")
207 fid.write(
"&PARAM EDITMASK = *\n")
210 print(
'SAVED: %s\n' % filesave)
211 filesave_dat = filesave[:-3] +
'dat' 212 fid2 = open(filesave_dat,
"w")
213 fid2.write(
'&ACCESS RVP\n')
214 fid2.write(
'&REL 1\n')
215 fid2.write(
"&COMMENT Generated by RoboDK\n")
216 fid2.write(
'&PARAM TEMPLATE = C:\\KRC\\Roboter\\Template\\vorgabe\n')
217 fid2.write(
'&PARAM EDITMASK = *\n')
218 fid2.write(
'DEFDAT %s\n\n' % self.
PROG_NAME)
219 fid2.write(
'EXT BAS (BAS_COMMAND :IN,REAL :IN )\n')
222 fid2.write(
"EXT %s()\n" % prog_nm)
225 fid2.write(
'\nENDDAT\n\n')
227 print(
'SAVED: %s\n' % filesave_dat)
231 if type(show_result)
is str:
234 p = subprocess.Popen([show_result, filesave_dat, filesave])
235 elif type(show_result)
is list:
237 p = subprocess.Popen(show_result + [filesave])
241 os.startfile(filesave)
242 os.startfile(filesave_dat)
243 if len(self.
LOG) > 0:
244 mbox(
'Program generation LOG:\n\n' + self.
LOG)
247 """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". 248 The connection parameters must be provided in the robot connection menu of RoboDK""" 251 def MoveJ(self, pose, joints, conf_RLF=None):
252 """Add a joint movement""" 269 self.
addline(
';FOLD PTP P%s %sVel=%.0f %% PDAT%s Tool[%i] Base[%i];%%{PE}%%R 5.5.31,%%MKUKATPBASIS,%%CMOVE,%%VPTP,%%P 1:PTP, 2:P%s, 3:%s, 5:%.0f, 7:PDAT%s' % (vname, str_cont, self.
VEL_PTP, vname, self.
TOOL_ID, self.
BASE_ID, vname, str_cdis, self.
VEL_PTP, vname))
270 self.
addline(
'$BWDSTART=FALSE')
271 self.
addline(
'PDAT_ACT=PPDAT%s' % vname)
272 self.
addline(
'FDAT_ACT=FP%s' % vname)
282 self.
addDAT(
'DECL FDAT FP%s={TOOL_NO %i,BASE_NO %i,IPO_FRAME #BASE,POINT2[] " ",TQ_STATE FALSE}' % (vname, self.
TOOL_ID, self.
BASE_ID))
283 self.
addDAT(
'DECL PDAT PPDAT%s={VEL %.3f,ACC 100.000,APO_DIST %.3f,APO_MODE #CPTP}' % (vname, self.
VEL_PTP, max(self.
APO_VALUE,1)))
285 def MoveL(self, pose, joints, conf_RLF=None):
286 """Add a linear movement""" 315 self.
addline(
';FOLD LIN P%s %sVel=%.3f m/s CPDAT%s Tool[%i] Base[%i];%%{PE}%%R 5.5.0,%%MKUKATPA20,%%CARC_SWI,%%VLIN,%%P 1:LIN, 2:P%s, 3:%s, 5:%.0f, 7:CPDAT%s' % (vname, str_cont, self.
speed_ms, vname, self.
TOOL_ID, self.
BASE_ID, vname, str_cdis, self.
speed_ms, vname))
319 self.
addline(
';FOLD LIN P%s CPDAT%s ARC Pgno= %i %s Tool[%i] Base[%i];%%{PE}%%R 5.5.0,%%MKUKATPBASIS,%%CMOVE,%%VLIN,%%P 1:LIN, 2:P%s, 3:%s, 5:%.0f, 7:CPDAT%s, 10:%i, 11:%s' % (vname, str_cont, self.
ARC_Pgno, wid, self.
TOOL_ID, self.
BASE_ID, vname, str_cdis, self.
speed_ms, vname, self.
ARC_Pgno, wid))
320 self.
addline(
'$BWDSTART=FALSE')
321 self.
addline(
'LDAT_ACT=LCPDAT%s' % vname)
322 self.
addline(
'FDAT_ACT=FP%s' % vname)
326 self.
addline(
'BAS(#CP_PARAMS,LDEFAULT.VEL)')
343 self.
addDAT(
'DECL FDAT FP%s={TOOL_NO %i,BASE_NO %i,IPO_FRAME #BASE,POINT2[] " ",TQ_STATE FALSE}' % (vname, self.
TOOL_ID, self.
BASE_ID))
344 self.
addDAT(
'DECL LDAT LCPDAT%s={VEL %.5f,ACC 100.000,APO_DIST %.3f,APO_FAC 50.0000,ORI_TYP #VAR,CIRC_TYP #BASE,JERK_FAC 50.0000}' % (vname, self.
speed_ms, max(self.
APO_VALUE,1)))
348 self.
addDAT(
'DECL WELD_FI M%s={PRG_NO 1,VELOCITY %.3f,WEAVFIG_MECH 1,WEAVLEN_MECH 6.0,WEAVAMP_MECH 7.0,WEAVANG_MECH 180.0,END_TIME 0.015}' % (wid, self.
speed_ms))
350 def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
351 """Add a circular movement""" 354 def setFrame(self, pose, frame_id=None, frame_name=None):
355 """Change the robot reference frame""" 356 if frame_name
is not None and frame_name.endswith(
"Base"):
360 elif frame_id
is not None and frame_id >= 0:
367 def setTool(self, pose, tool_id=None, tool_name=None):
368 """Change the robot TCP""" 369 if tool_id
is not None and tool_id >= 0:
378 """Pause the robot program""" 382 self.
addline(
'WAIT SEC %.3f' % (time_ms*0.001))
385 """Changes the robot speed (in mm/s)""" 390 """Changes the current robot acceleration""" 395 """Changes the robot joint speed (in deg/s)""" 397 self.
addline(
'$VEL.ORI1 = %.5f' % speed_degs)
398 self.
addline(
'$VEL.ORI2 = %.5f' % speed_degs)
401 """Changes the robot joint acceleration (in deg/s2)""" 403 self.
addline(
'$ACC.ORI1 = %.5f' % accel_degss)
404 self.
addline(
'$ACC.ORI2 = %.5f' % accel_degss)
407 """Changes the zone data approach (makes the movement more smooth)""" 410 self.
addline(
'$APO.CPTP = %.3f' % zone_mm)
411 self.
addline(
'$APO.CDIS = %.3f' % zone_mm)
419 """Sets a variable (output) to a given value""" 420 if type(io_var) != str:
421 io_var =
'$OUT[%s]' % str(io_var)
422 if type(io_value) != str:
429 self.
addline(
'%s=%s' % (io_var, io_value))
431 def waitDI(self, io_var, io_value, timeout_ms=-1):
432 """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided.""" 433 if type(io_var) != str:
434 io_var =
'$IN[%s]' % str(io_var)
435 if type(io_value) != str:
443 self.
addline(
'WAIT FOR (%s==%s)' % (io_var, io_value))
446 self.
addline(
'$TIMER_STOP[1]=TRUE')
447 self.
addline(
'$TIMER_FLAG[1]=FALSE')
448 self.
addline(
'$TIMER[1]=%.3f' % (float(timeout_ms)*0.001))
449 self.
addline(
'$TIMER_STOP[1]=FALSE')
450 self.
addline(
'WAIT FOR (%s==%s OR $TIMER_FLAG[1])' % (io_var, io_value))
451 self.
addline(
'$TIMER_STOP[1]=TRUE')
452 self.
addline(
'IF $TIMER_FLAG[1]== TRUE THEN')
453 self.
addline(
' HALT ; Timed out!')
454 self.
addline(
' GOTO START_TIMER')
457 def RunCode(self, code, is_function_call = False):
458 """Adds code or a function call""" 460 code.replace(
' ',
'_')
461 if not code.endswith(
')'):
463 if code.startswith(
'ARC_ON'):
466 elif code.startswith(
'ARC_OFF'):
472 fcn_def = fcn_def.split(
'(')[0]
481 """Add a joint movement""" 485 self.
addline(
'Wait for StrClear($LOOP_MSG[])')
486 self.
addline(
'$LOOP_CONT = TRUE')
487 self.
addline(
'$LOOP_MSG[] = "%s"' % message)
491 """Add a program line""" 492 self.
PROG = self.
PROG + newline +
'\n' 498 """Add a log message""" 499 self.
LOG = self.
LOG + newline +
'\n' 504 [x,y,z,r,p,w] = xyzrpw
514 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]])
517 """Test the post with a basic program""" 519 robot =
RobotPost(
'Kuka_custom',
'Generic Kuka')
521 robot.ProgStart(
"Program")
522 robot.RunMessage(
"Program generated by RoboDK",
True)
523 robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
524 robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
525 robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
526 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
527 robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
528 robot.RunMessage(
"Setting air valve 1 on")
529 robot.RunCode(
"TCP_On",
True)
531 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
532 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
533 robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
534 robot.RunMessage(
"Setting air valve off")
535 robot.RunCode(
"TCP_Off",
True)
537 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
538 robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
539 robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
540 robot.ProgFinish(
"Program")
543 if len(robot.LOG) > 0:
544 mbox(
'Program generation LOG:\n\n' + robot.LOG)
546 input(
"Press Enter to close...")
548 if __name__ ==
"__main__":
549 """Function to call when the module is executed by itself: test""" def setSpeedJoints(self, speed_degs)
def addlog(self, newline)
def setAccelerationJoints(self, accel_degss)
def setZoneData(self, zone_mm)
def joints_2_turn_str(joints)
def setTool(self, pose, tool_id=None, tool_name=None)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def MoveJ(self, pose, joints, conf_RLF=None)
def setFrame(self, pose, frame_id=None, frame_name=None)
def setSpeed(self, speed_mms)
def RunCode(self, code, is_function_call=False)
def ProgFinish(self, progname)
def pose_2_str_ext(pose, joints)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def MoveL(self, pose, joints, conf_RLF=None)
def addline(self, newline)
def setAcceleration(self, accel_mmss)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def ProgStart(self, progname)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def setDO(self, io_var, io_value)
def addDAT(self, newline)
def RunMessage(self, message, iscomment=False)