52 ! ------------------------------- 53 ! Define your variables here 58 CUSTOM_FUNCTIONS =
''' 59 ! ------------------------------- 60 ! Define your functions here 66 """Prints a pose target""" 68 return (
'[%.3f, %.3f, %.3f],[%.8f, %.8f, %.8f, %.8f]' % (x,y,z,q1,q2,q3,q4))
71 """Prints a joint target""" 75 angles.extend([0]*(6-njoints))
79 return '[%s]' % (
','.join(format(ji,
".6f")
for ji
in angles[0:6]))
82 """Prints the external axes, if any""" 88 return '[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]' 89 extaxes_str = (
','.join(format(ji,
".6f")
for ji
in angles[6:njoints]))
91 extaxes_str = extaxes_str +
',' +
','.join([
'9E9']*(12-njoints))
95 return '[%s]' % extaxes_str
100 """Robot post object""" 101 MAX_LINES_X_PROG = 5000
102 INCLUDE_SUB_PROGRAMS =
True 106 ROBOT_POST =
'ABB IRC5 including arc welding and 3D printing options' 107 ROBOT_NAME =
'unknown' 119 SPEEDDATA =
'rdkSpeed' 129 ARC_WELDDATA =
'weld1' 130 ARC_WEAVEDATA =
'weave1' 131 ARC_SEAMDATA =
'seam1' 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)
167 self.
addline(
' LANGUAGE:ENGLISH')
170 self.
addline(
'MODULE MOD_%s' % progname_i)
173 if self.
nProgs == 1
and nPages == 0:
176 self.
addline(
'LOCAL PERS tooldata %s := [TRUE,[[0,0,0],[1,0,0,0]],[2,[0,0,15],[1,0,0,0],0,0,0.005]];' % self.
TOOLDATA)
177 self.
addline(
'LOCAL PERS wobjdata %s := [FALSE, TRUE, "", [[0,0,0],[1,0,0,0]],[[0,0,0],[1,0,0,0]]];' % self.
WOBJDATA)
178 self.
addline(
'VAR speeddata %s := [250,500,5000,1000]; ! set default speed' % self.
SPEEDDATA)
184 self.
addline(
'PROC %s()' % progname_i)
185 self.
TAB = ONETAB + ONETAB
191 self.
PROG += [ONETAB +
'ENDPROC\n']
193 self.
PROG += [
'ENDMODULE']
202 def progsave(self, folder, progname, ask_user = False, show_result = False):
203 progname = progname +
'.' + self.
PROG_EXT 205 filesave =
getSaveFile(folder, progname,
'Save program as...')
206 if filesave
is not None:
207 filesave = filesave.name
211 filesave = folder +
'/' + progname
213 fid = open(filesave,
"w")
214 for line
in self.
PROG:
219 print(
'SAVED: %s\n' % filesave)
224 if type(show_result)
is str:
227 p = subprocess.Popen([show_result, filesave])
228 elif type(show_result)
is list:
230 p = subprocess.Popen(show_result + [filesave])
235 os.startfile(filesave)
236 if len(self.
LOG) > 0:
237 mbox(
'Program generation LOG:\n\n' + self.
LOG)
239 def ProgSave(self, folder, progname, ask_user = False, show_result = False):
242 self.
PROG += [
'ENDMODULE']
250 progname_main = progname +
"Main" 252 mainprog += [
"MODULE MOD_%s\n" % progname_main]
253 mainprog += [ONETAB+
"!PROC Main()"]
254 mainprog += [ONETAB+
"PROC %s()" % progname_main]
255 mainprog += [ONETAB+ONETAB+
"! This main program needs to be executed to run: %s\n" % progname]
256 for i
in range(npages):
257 mainprog += [ONETAB+ONETAB+
"%s()" % self.
PROG_NAMES[i]]
258 mainprog += [
"\n"+ONETAB+
"ENDPROC\n"]
259 mainprog += [
"ENDMODULE"]
262 self.
progsave(folder, progname_main, ask_user, show_result)
272 for i
in range(npages):
278 self.
PROG += [
'ENDMODULE']
279 self.
progsave(folder, progname, ask_user, show_result)
283 """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". 284 The connection parameters must be provided in the robot connection menu of RoboDK""" 287 def MoveJ(self, pose, joints, conf_RLF=None):
288 """Add a joint movement""" 289 self.
addline(
'MoveAbsJ [%s,%s],%s,%s,%s,\WObj:=%s;' % (
angles_2_str(joints),
extaxes_2_str(joints), self.
SPEEDDATA, self.
ZONEDATA, self.
TOOLDATA, self.
WOBJDATA))
291 def MoveL(self, pose, joints, conf_RLF=None):
292 """Add a linear movement""" 308 if joints
is not None and len(joints) >= 6:
309 cf1 = math.floor(joints[0]/90.0)
310 cf4 = math.floor(joints[3]/90.0)
311 cf6 = math.floor(joints[5]/90.0)
312 [REAR, LOWERARM, FLIP] = conf_RLF
313 cfx = 4*REAR + 2*LOWERARM + FLIP
314 target =
'[%s,[%i,%i,%i,%i],%s]' % (
pose_2_str(pose), cf1, cf4, cf6,cfx,
extaxes_2_str(joints))
318 self.
addline(
'ArcL %s,%s,%s,%s,\Weave:=%s,%s,%s,\WObj:=%s;' % (target, self.
SPEEDDATA, self.
ARC_SEAMDATA, self.
ARC_WELDDATA, self.
ARC_WEAVEDATA, self.
ZONEDATA, self.
TOOLDATA, self.
WOBJDATA))
320 self.
addline(
'CladL %s,%s,%s,%s,%s,\WObj:=%s;' % (target, self.
SPEEDDATA, self.
CLAD_DATA, self.
ZONEDATA, self.
TOOLDATA, self.
WOBJDATA))
327 def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
328 """Add a circular movement""" 334 if conf_RLF_1
is None:
339 if joints1
is not None and len(joints1) >= 6:
340 cf1_1 = math.floor(joints1[0]/90.0)
341 cf4_1 = math.floor(joints1[3]/90.0)
342 cf6_1 = math.floor(joints1[5]/90.0)
343 [REAR, LOWERARM, FLIP] = conf_RLF_1
344 cfx_1 = 4*REAR + 2*LOWERARM + FLIP
345 target1 =
'[%s,[%i,%i,%i,%i],%s]' % (
pose_2_str(pose1), cf1_1, cf4_1, cf6_1,cfx_1,
extaxes_2_str(joints1))
350 if conf_RLF_2
is None:
355 if joints2
is not None and len(joints2) >= 6:
356 cf1_2 = math.floor(joints2[0]/90.0)
357 cf4_2 = math.floor(joints2[3]/90.0)
358 cf6_2 = math.floor(joints2[5]/90.0)
359 [REAR, LOWERARM, FLIP] = conf_RLF_2
360 cfx_2 = 4*REAR + 2*LOWERARM + FLIP
361 target2 =
'[%s,[%i,%i,%i,%i],%s]' % (
pose_2_str(pose2), cf1_2, cf4_2, cf6_2,cfx_2,
extaxes_2_str(joints2))
365 self.
addline(
'ArcC %s,%s,%s,%s,%s,\Weave:=%s,%s,%s,\WObj:=%s;' % (target1, target2, self.
SPEEDDATA, self.
ARC_SEAMDATA, self.
ARC_WELDDATA, self.
ARC_WEAVEDATA, self.
ZONEDATA, self.
TOOLDATA, self.
WOBJDATA))
367 self.
addline(
'CladC %s,%s,%s,%s,%s,%s,\WObj:=%s;' % (target1, target2, self.
SPEEDDATA, self.
CLAD_DATA, self.
ZONEDATA, self.
TOOLDATA, self.
WOBJDATA))
369 self.
addline(
'MoveC %s,%s,%s,%s,%s,\WObj:=%s;' % (target1, target2, self.
SPEEDDATA, self.
ZONEDATA, self.
TOOLDATA, self.
WOBJDATA))
371 def setFrame(self, pose, frame_id=None, frame_name=None):
372 """Change the robot reference frame""" 376 def setTool(self, pose, tool_id=None, tool_name=None):
377 """Change the robot TCP""" 382 """Pause the robot program""" 386 self.
addline(
'WaitTime %.3f;' % (time_ms*0.001))
389 """Changes the robot speed (in mm/s)""" 394 """Changes the robot acceleration (in mm/s2)""" 395 self.
addlog(
'setAcceleration is not defined')
398 """Changes the robot joint speed (in deg/s)""" 399 self.
addlog(
'setSpeedJoints not defined')
402 """Changes the robot joint acceleration (in deg/s2)""" 403 self.
addlog(
'setAccelerationJoints not defined')
406 """Changes the zone data approach (makes the movement more smooth)""" 413 """Sets a variable (output) to a given value""" 414 if type(io_var) != str:
415 io_var =
'D_OUT_%s' % str(io_var)
416 if type(io_value) != str:
423 self.
addline(
'SetDO %s, %s;' % (io_var, io_value))
425 def waitDI(self, io_var, io_value, timeout_ms=-1):
426 """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided.""" 427 if type(io_var) != str:
428 io_var =
'D_IN_%s' % str(io_var)
429 if type(io_value) != str:
437 self.
addline(
'WaitDI %s, %s;' % (io_var, io_value))
439 self.
addline(
'WaitDI %s, %s, \MaxTime:=%.1f;' % (io_var, io_value, timeout_ms*0.001))
441 def RunCode(self, code, is_function_call = False):
442 """Adds code or a function call""" 444 code = code.replace(
' ',
'_')
445 if code.startswith(
'ArcLStart'):
447 elif code.startswith(
'ArcLEnd'):
449 elif code.startswith(
'CladLStart'):
451 elif code.startswith(
'CladLEnd'):
453 elif code.startswith(
"Extruder("):
469 if code.startswith(
'END')
or code.startswith(
'ELSEIF'):
471 self.
TAB = self.
TAB[:-len(ONETAB)]
473 self.
addline(code.replace(
'\t',
' '))
475 if code.startswith(
'IF ')
or code.startswith(
'ELSEIF ')
or code.startswith(
'WHILE '):
477 self.
TAB = self.
TAB + ONETAB
481 """Add a joint movement""" 485 self.
addline(
'TPWrite "%s";' % message)
489 """Add a program line""" 498 self.
PROG += [self.
TAB + newline]
502 """Add a log message""" 505 self.
LOG = self.
LOG + newline +
'\n' 508 """Adds custom code, such as a custom header""" 515 [x,y,z,r,p,w] = xyzrpw
525 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]])
528 """Test the post with a basic program""" 530 robot =
RobotPost(
r'ABB_RAPID_IRC5',
r'ABB IRB 6700-155/2.85', 6, axes_type=[
'R','R','R','R','R','R']) 532 robot.ProgStart(r'Prog1')
533 robot.RunMessage(
r'Program generated by RoboDK 3.1.5 for ABB IRB 6700-155/2.85 on 18/05/2017 11:02:41',
True)
534 robot.RunMessage(
r'Using nominal kinematics.',
True)
535 robot.setFrame(
Pose([0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000]),-1,
r'ABB IRB 6700-155/2.85 Base')
536 robot.setTool(
Pose([380.000000, 0.000000, 200.000000, 0.000000, 90.000000, 0.000000]),1,
r'Tool 1')
537 robot.setSpeed(2000.000)
538 robot.MoveJ(
Pose([2103.102861, 0.000000, 1955.294643, -180.000000, -3.591795, -180.000000]), [0.00000, 3.93969, -14.73451, 0.00000, 14.38662, -0.00000], [0.0, 0.0, 0.0])
539 robot.MoveJ(
Pose([2065.661612, 700.455189, 1358.819971, 180.000000, -3.591795, -180.000000]), [22.50953, 5.58534, 8.15717, 67.51143, -24.42689, -64.06258], [0.0, 0.0, 1.0])
541 robot.setSpeed(100.000)
542 robot.RunCode(
r'ArcLStart',
True)
543 robot.MoveL(
Pose([2065.661612, 1074.197508, 1358.819971, 149.453057, -3.094347, -178.175378]), [36.19352, 22.86988, -12.37860, 88.83085, -66.57439, -81.72795], [0.0, 0.0, 1.0])
544 robot.MoveC(
Pose([2468.239418, 1130.614560, 1333.549802, -180.000000, -3.591795, -180.000000]), [28.37934, 35.45210, -28.96667, 85.54799, -28.41204, -83.00289],
Pose([2457.128674, 797.241647, 1156.545094, 180.000000, -37.427062, -180.000000]), [18.58928, 43.77805, -40.05410, 155.58093, -37.76022, -148.70252], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0])
545 robot.MoveL(
Pose([2457.128674, 797.241647, 1156.545094, 180.000000, -37.427062, -180.000000]), [18.58928, 43.77805, -40.05410, 155.58093, -37.76022, -148.70252], [0.0, 0.0, 1.0])
546 robot.MoveL(
Pose([2469.684137, 397.051453, 1356.565545, -180.000000, -3.591795, -180.000000]), [10.73523, 21.17902, -10.22963, 56.13802, -12.93695, -54.77268], [0.0, 0.0, 1.0])
547 robot.MoveL(
Pose([2494.452316, 404.343933, 1751.146172, -180.000000, -3.591795, -180.000000]), [10.80299, 25.05092, -31.54821, 132.79244, -14.76878, -133.06820], [0.0, 0.0, 1.0])
548 robot.MoveL(
Pose([2494.452316, 834.649436, 1751.146172, -180.000000, -3.591795, -180.000000]), [21.49850, 33.45974, -43.37980, 121.21995, -25.32130, -122.42907], [0.0, 0.0, 1.0])
549 robot.setZoneData(5.000)
550 robot.MoveL(
Pose([2147.781731, 834.649436, 1772.906995, -180.000000, -3.591795, -180.000000]), [25.21677, 13.65153, -17.95808, 107.03387, -26.40518, -107.19412], [0.0, 0.0, 1.0])
551 robot.MoveL(
Pose([2147.781731, 375.769504, 1772.906995, -180.000000, -3.591795, -180.000000]), [11.97030, 5.74930, -8.96838, 119.55454, -13.76610, -119.51539], [0.0, 0.0, 1.0])
552 robot.MoveL(
Pose([2147.781731, 61.363728, 1772.906995, -180.000000, -3.591795, -180.000000]), [1.98292, 3.75693, -6.84136, -16.54793, 6.96416, 16.55673], [0.0, 0.0, 0.0])
553 robot.RunCode(
r'ArcLEnd',
True)
554 robot.MoveL(
Pose([2147.781731, 275.581430, 1772.906995, -180.000000, -3.591795, -180.000000]), [8.83799, 4.80606, -7.95436, 127.27676, -11.11070, -127.24243], [0.0, 0.0, 1.0])
555 robot.ProgFinish(
r'Prog1')
556 for line
in robot.PROG:
559 if len(robot.LOG) > 0:
560 mbox(
'Program generation LOG:\n\n' + robot.LOG)
561 input(
"Press Enter to close...")
563 if __name__ ==
"__main__":
564 """Function to call when the module is executed by itself: test"""
def addlog(self, newline)
def setSpeed(self, speed_mms)
def setDO(self, io_var, io_value)
def ProgFinish(self, progname, new_page=False)
def addline(self, newline)
def waitDI(self, io_var, io_value, timeout_ms=-1)
bool INCLUDE_SUB_PROGRAMS
def setAccelerationJoints(self, accel_degss)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def setAcceleration(self, accel_mmss)
def RunCode(self, code, is_function_call=False)
def MoveL(self, pose, joints, conf_RLF=None)
def setSpeedJoints(self, speed_degs)
def progsave(self, folder, progname, ask_user=False, show_result=False)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def RunMessage(self, message, iscomment=False)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def MoveJ(self, pose, joints, conf_RLF=None)
def ProgStart(self, progname, new_page=False)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def setZoneData(self, zone_mm)
def extaxes_2_str(angles)
def setFrame(self, pose, frame_id=None, frame_name=None)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def setTool(self, pose, tool_id=None, tool_name=None)