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]))
111 """Robot post object""" 113 MAX_LINES_X_PROG = 1400
114 INCLUDE_SUB_PROGRAMS =
True 121 PROG_NAME =
'unknown' 136 def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
142 for k,v
in kwargs.items():
143 if k ==
'lines_x_prog':
147 progname_i = progname
151 progname_i = progname
153 progname_i =
"%s%i" % (self.
PROG_NAME, nPages)
164 self.
addline(
'DEF %s ( )' % progname_i)
179 def progsave(self, folder, progname, ask_user = False, show_result = False):
180 progname = progname +
'.' + self.
PROG_EXT 182 filesave =
getSaveFile(folder, progname,
'Save program as...')
183 if filesave
is not None:
184 filesave = filesave.name
188 filesave = folder +
'/' + progname
189 fid = open(filesave,
"w")
190 fid.write(
"&ACCESS RVP\n")
191 fid.write(
"&REL 1\n")
192 fid.write(
"&COMMENT Generated by RoboDK\n")
193 fid.write(
"&PARAM TEMPLATE = C:\\KRC\\Roboter\\Template\\vorgabe\n")
194 fid.write(
"&PARAM EDITMASK = *\n")
197 print(
'SAVED: %s\n' % filesave)
202 if type(show_result)
is str:
205 p = subprocess.Popen([show_result, filesave])
206 elif type(show_result)
is list:
208 p = subprocess.Popen(show_result + [filesave])
214 os.startfile(filesave)
215 if len(self.
LOG) > 0:
216 mbox(
'Program generation LOG:\n\n' + self.
LOG)
218 def ProgSave(self, folder, progname, ask_user = False, show_result = False):
226 progname_main = progname +
"Main" 227 mainprog =
"DEF %s ( )\n" % progname_main
228 for i
in range(npages):
234 self.
progsave(folder, progname_main, ask_user, show_result)
244 for i
in range(npages):
249 self.
progsave(folder, progname, ask_user, show_result)
252 """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". 253 The connection parameters must be provided in the robot connection menu of RoboDK""" 256 def MoveJ(self, pose, joints, conf_RLF=None):
257 """Add a joint movement""" 260 def MoveL(self, pose, joints, conf_RLF=None):
261 """Add a linear movement""" 264 def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
265 """Add a circular movement""" 268 def setFrame(self, pose, frame_id=None, frame_name=None):
269 """Change the robot reference frame""" 273 self.
addline(
'$BASE = EK (MACHINE_DEF[2].ROOT, MACHINE_DEF[2].MECH_TYPE, { %s })' %
pose_2_str(pose))
277 def setTool(self, pose, tool_id=None, tool_name=None):
278 """Change the robot TCP""" 282 """Pause the robot program""" 286 self.
addline(
'WAIT SEC %.3f' % (time_ms*0.001))
289 """Changes the robot speed (in mm/s)""" 290 self.
addline(
'$VEL.CP = %.5f' % (speed_mms/1000.0))
293 """Changes the current robot acceleration""" 294 self.
addline(
'$ACC.CP = %.5f' % (accel_mmss/1000.0))
297 """Changes the robot joint speed (in deg/s)""" 298 self.
addline(
'$VEL.ORI1 = %.5f' % speed_degs)
299 self.
addline(
'$VEL.ORI2 = %.5f' % speed_degs)
302 """Changes the robot joint acceleration (in deg/s2)""" 303 self.
addline(
'$ACC.ORI1 = %.5f' % accel_degss)
304 self.
addline(
'$ACC.ORI2 = %.5f' % accel_degss)
307 """Changes the zone data approach (makes the movement more smooth)""" 310 self.
addline(
'$APO.CPTP = %.3f' % zone_mm)
311 self.
addline(
'$APO.CDIS = %.3f' % zone_mm)
319 """Sets a variable (output) to a given value""" 320 if type(io_var) != str:
321 io_var =
'$OUT[%s]' % str(io_var)
322 if type(io_value) != str:
329 self.
addline(
'%s=%s' % (io_var, io_value))
331 def waitDI(self, io_var, io_value, timeout_ms=-1):
332 """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided.""" 333 if type(io_var) != str:
334 io_var =
'$IN[%s]' % str(io_var)
335 if type(io_value) != str:
343 self.
addline(
'WAIT FOR (%s==%s)' % (io_var, io_value))
346 self.
addline(
'$TIMER_STOP[1]=TRUE')
347 self.
addline(
'$TIMER_FLAG[1]=FALSE')
348 self.
addline(
'$TIMER[1]=%.3f' % (float(timeout_ms)*0.001))
349 self.
addline(
'$TIMER_STOP[1]=FALSE')
350 self.
addline(
'WAIT FOR (%s==%s OR $TIMER_FLAG[1])' % (io_var, io_value))
351 self.
addline(
'$TIMER_STOP[1]=TRUE')
352 self.
addline(
'IF $TIMER_FLAG[1]== TRUE THEN')
353 self.
addline(
' HALT ; Timed out!')
354 self.
addline(
' GOTO START_TIMER')
357 def RunCode(self, code, is_function_call = False):
358 """Adds code or a function call""" 360 code.replace(
' ',
'_')
361 if not code.endswith(
')'):
368 """Add a joint movement""" 372 self.
addline(
'Wait for StrClear($LOOP_MSG[])')
373 self.
addline(
'$LOOP_CONT = TRUE')
374 self.
addline(
'$LOOP_MSG[] = "%s"' % message)
378 """Add a program line""" 387 self.
PROG = self.
PROG + newline +
'\n' 391 """Add a log message""" 395 self.
LOG = self.
LOG + newline +
'\n' 400 [x,y,z,r,p,w] = xyzrpw
410 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]])
413 """Test the post with a basic program""" 415 robot =
RobotPost(
'Kuka_custom',
'Generic Kuka')
417 robot.ProgStart(
"Program")
418 robot.RunMessage(
"Program generated by RoboDK",
True)
419 robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
420 robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
421 robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
422 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
423 robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
424 robot.RunMessage(
"Setting air valve 1 on")
425 robot.RunCode(
"TCP_On",
True)
427 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
428 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
429 robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
430 robot.RunMessage(
"Setting air valve off")
431 robot.RunCode(
"TCP_Off",
True)
433 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
434 robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
435 robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
436 robot.ProgFinish(
"Program")
439 if len(robot.LOG) > 0:
440 mbox(
'Program generation LOG:\n\n' + robot.LOG)
442 input(
"Press Enter to close...")
444 if __name__ ==
"__main__":
445 """Function to call when the module is executed by itself: test""" def ProgFinish(self, progname, new_page=False)
def setSpeed(self, speed_mms)
def setFrame(self, pose, frame_id=None, frame_name=None)
def pose_2_str_ext(pose, joints)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def ProgStart(self, progname, new_page=False)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def setTool(self, pose, tool_id=None, tool_name=None)
def progsave(self, folder, progname, ask_user=False, show_result=False)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def setAccelerationJoints(self, accel_degss)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def setAcceleration(self, accel_mmss)
def RunCode(self, code, is_function_call=False)
def MoveL(self, pose, joints, conf_RLF=None)
def setZoneData(self, zone_mm)
def addlog(self, newline)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def MoveJ(self, pose, joints, conf_RLF=None)
def setSpeedJoints(self, speed_degs)
def addline(self, newline)
def RunMessage(self, message, iscomment=False)
bool INCLUDE_SUB_PROGRAMS
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def setDO(self, io_var, io_value)