44 MACRO_MESSAGE_TP =
'''-- Display message on the teach pendant: 46 -- popup window over window USR1 47 WIN_POPUP('POP1:', 'USR1:') 48 -- open a lun on window POP1 49 OPEN FILE lun ('POP1:', 'rw') 52 -- let user read the message 54 -- Remove and delete window POP1 from user screen 64 RATIO_EXTAX = [1,1,1,1,1,1]
71 """Robot post processor class""" 73 MAX_LINES_X_PROG = 5000
74 INCLUDE_SUB_PROGRAMS =
True 105 """Contverts a joint target to a string""" 106 if joints
is not None and len(joints) > 6:
107 joints[6] = joints[6]*RATIO_EXTAX[0]
108 return '{%s}' % (
','.join(format(ji,
".5f")
for ji
in joints))
111 """Converts a pose target to a string""" 115 if conf_RLF
is not None:
122 if joints
is not None:
125 if len(joints) >= 5
and joints[4] < 0:
129 t1 = round((joints[3]+180) // 360)
130 config.append(
'T1:%i' % t1)
133 t2 = round((joints[5]+180) // 360)
134 config.append(
'T2:%i' % t2)
135 t3 = round((joints[2]+180) // 360)
136 config.append(
'T3:%i' % t3)
138 pos_str =
"POS(%.4f, %.4f, %.4f, %.4f, %.4f, %.4f, '%s')" % (x,y,z,w,p,r,
' '.join(config))
139 if joints
is None or len(joints) <= 6:
143 self.
addline(
'pxtn.POS := ' + pos_str)
144 for i
in range(6,len(joints)):
145 self.
addline(
'pxtn.AUX[%i] := %.5f' % (i-6+1, joints[i]*RATIO_EXTAX[i-6]))
149 def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
155 for k,v
in kwargs.items():
156 if k ==
'lines_x_prog':
160 progname_i = progname
163 raise Exception(
"Multiple pages per program is not supported when adding routines in the main program")
166 progname_i = progname
168 progname_i =
"%s%i" % (self.
PROG_NAME, nPages)
179 self.
IMPORTS.remove(progname_i)
180 self.
addline(
'ROUTINE R_%s' % progname_i)
187 self.
addline(
'PROGRAM %s' % progname_i)
191 self.
addline(
'ROUTINE R_%s EXPORTED FROM %s GLOBAL' % (progname_i, progname_i))
196 self.
addline(
'ROUTINE R_%s' % progname_i)
202 self.
addline(
'-- VARIABLES --')
205 self.
addline(
'$ORNT_TYPE := RS_WORLD')
206 self.
addline(
'$MOVE_TYPE := JOINT')
207 self.
addline(
'$JNT_MTURN := TRUE')
208 self.
addline(
'$CNFG_CARE := TRUE')
209 self.
addline(
'$TURN_CARE := TRUE')
210 self.
addline(
'$SING_CARE := FALSE')
211 self.
addline(
'$TERM_TYPE := NOSETTLE')
214 self.
addline(
'$FLY_TYPE := FLY_CART')
215 self.
addline(
'$FLY_TRAJ := FLY_PASS')
218 self.
addline(
'$STRESS_PER:= 65')
223 variables =
' %s\n' % line
225 self.
PROG = self.
PROG.replace(
'-- VARIABLES --\n', variables,1)
232 self.
PROG = self.
PROG +
"END R_%s\n\n" % progname
234 self.
PROG = self.
PROG +
"BEGIN\n R_%s\nEND %s\n\n" % (progname, progname)
243 def progsave(self, folder, progname, ask_user = False, show_result = False):
244 progname = progname +
'.' + self.
PROG_EXT 246 filesave =
getSaveFile(folder, progname,
'Save program as...')
247 if filesave
is not None:
248 filesave = filesave.name
252 filesave = folder +
'/' + progname
256 for i
in range(len(self.
IMPORTS)):
257 imports = imports +
"IMPORT '%s'\n" % self.
IMPORTS[i]
258 self.
PROG = self.
PROG.replace(
"-- IMPORTS --\n", imports, 1)
262 fid = open(filesave,
"w")
265 print(
'SAVED: %s\n' % filesave)
270 if type(show_result)
is str:
273 p = subprocess.Popen([show_result, filesave])
274 elif type(show_result)
is list:
276 p = subprocess.Popen(show_result + [filesave])
280 os.startfile(filesave)
281 if len(self.
LOG) > 0:
282 mbox(
'Program generation LOG:\n\n' + self.
LOG)
284 def ProgSave(self, folder, progname, ask_user = False, show_result = False):
292 progname_main = progname +
"Main" 293 mainprog =
"PROGRAM %s\n" % progname_main
294 for i
in range(npages):
295 mainprog +=
"IMPORT '%s'\n" % self.
PROG_NAMES[i]
297 mainprog +=
"CONST\nVAR\n" 298 mainprog +=
"BEGIN\n" 299 for i
in range(npages):
302 mainprog +=
"END %s\n" % progname_main
304 self.
progsave(folder, progname_main, ask_user, show_result)
309 for i
in range(npages):
314 self.
progsave(folder, progname, ask_user, show_result)
318 """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". 319 The connection parameters must be provided in the robot connection menu of RoboDK""" 322 def MoveJ(self, pose, joints, conf_RLF=None):
323 """Add a joint movement""" 331 def Calculate_Time(Dist, Vmax, Amax):
332 '''Calculate the time it takes to move a distance Dist at Amax acceleration and Vmax speed''' 334 Xacc = 0.5*Amax*tacc*tacc;
337 tacc =
sqrt(Dist/Amax)
341 Xvmax = Dist - 2*Xacc
343 Ttot = 2*tacc + Tvmax
350 distance_mm =
norm(
subs3(pose1.Pos(), pose2.Pos()))
354 self.
addline(
"$AOUT[5] := %.3f" % (add_material/time_s))
362 def MoveL(self, pose, joints, conf_RLF=None):
363 """Add a linear movement""" 365 if self.LAST_POSE
is not None and pose
is not None:
372 target = self.joints_2_str(joints)
374 target = self.pose_2_str(pose,joints)
377 if self.FLY_DIST > 0:
378 self.addline(
'MOVEFLY LINEAR TO %s ADVANCE' % target)
380 self.addline(
'MOVE LINEAR TO ' + target)
382 self.LAST_POSE = pose
384 def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
385 """Add a circular movement""" 394 def setFrame(self, pose, frame_id=None, frame_name=None):
395 """Change the robot reference frame""" 398 def setTool(self, pose, tool_id=None, tool_name=None):
399 """Change the robot TCP""" 403 """Pause the robot program""" 407 self.
addline(
'DELAY %.0f' % (time_ms))
410 """Changes the robot speed (in mm/s)""" 412 self.
addline(
'$SPD_OPT := SPD_LIN')
413 self.
addline(
'$LIN_SPD := %.3f' % (speed_mms*0.001))
416 """Changes the robot acceleration (in mm/s2)""" 418 self.
addlog(
'setAcceleration not defined')
421 """Changes the robot joint speed (in deg/s)""" 422 self.
addline(
'$ROT_SPD := %.3f' % (speed_degs*pi/180.0))
425 """Changes the robot joint acceleration (in deg/s2)""" 426 self.
addlog(
'setAccelerationJoints not defined')
429 """Changes the zone data approach (makes the movement more smooth)""" 432 self.
addline(
'$FLY_DIST := %.3f' % zone_mm)
435 """Sets a variable (output) to a given value""" 436 if type(io_var) != str:
437 io_var =
'$DOUT[%s]' % str(io_var)
438 if type(io_value) != str:
445 self.
addline(
'%s := %s' % (io_var, io_value))
447 def waitDI(self, io_var, io_value, timeout_ms=-1):
448 """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided.""" 449 if type(io_var) != str:
450 io_var =
'$DIN[%s]' % str(io_var)
451 if type(io_value) != str:
463 self.
addline(
'UNTIL (%s = %s)' % (io_var, io_value))
468 self.
addline(
'UNTIL (%s = %s) OR ($TIMER[1] > %.1f)' % (io_var, io_value, timeout_ms))
469 self.
addline(
'IF $TIMER[1] > %.1f THEN' % timeout_ms)
470 self.
addline(
'-- TIMED OUT! Important: This section must be updated accordingly')
475 def RunCode(self, code, is_function_call = False):
476 """Adds code or a function call""" 481 if code.startswith(
"Extruder("):
487 code.replace(
' ',
'_')
488 bracket_id = code.find(
'(')
496 import_prog = code[:bracket_id]
499 if not import_prog
in self.
IMPORTS:
500 self.
IMPORTS.append(import_prog)
507 """Add a joint movement""" 521 """Add a program line""" 538 """Add a log message""" 542 self.
LOG = self.
LOG + newline +
'\n' 547 [x,y,z,r,p,w] = xyzrpw
557 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]])
560 """Test the post with a basic program""" 562 robot =
RobotPost(
'Comau_custom',
'Generic Comau robot')
564 robot.ProgStart(
"Program")
565 robot.RunMessage(
"Program generated by RoboDK",
True)
566 robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
567 robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
568 robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
569 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
570 robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
571 robot.RunMessage(
"Setting air valve 1 on")
572 robot.RunCode(
"TCP_On",
True)
574 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
575 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
576 robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
577 robot.RunMessage(
"Setting air valve off")
578 robot.RunCode(
"TCP_Off(55)",
True)
580 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
581 robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
582 robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
583 robot.ProgFinish(
"Program")
586 if len(robot.LOG) > 0:
587 mbox(
'Program generation LOG:\n\n' + robot.LOG)
589 input(
"Press Enter to close...")
591 if __name__ ==
"__main__":
592 """Function to call when the module is executed by itself: test"""
def pose_2_str(self, pose, joints=None, conf_RLF=None)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def addlog(self, newline)
def ProgStart(self, progname, new_page=False)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def setSpeed(self, speed_mms)
def setFrame(self, pose, frame_id=None, frame_name=None)
def MoveJ(self, pose, joints, conf_RLF=None)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def ProgFinish(self, progname, new_page=False)
bool INCLUDE_SUB_PROGRAMS
def setAccelerationJoints(self, accel_degss)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def progsave(self, folder, progname, ask_user=False, show_result=False)
def joints_2_str(self, joints)
def pose_angle_between(pose1, pose2)
def addline(self, newline)
def setTool(self, pose, tool_id=None, tool_name=None)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def setSpeedJoints(self, speed_degs)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def MoveL(self, pose, joints, conf_RLF=None)
def setDO(self, io_var, io_value)
def RunMessage(self, message, iscomment=False)
def new_move(self, pose1, pose2)
def new_movec(self, pose1, pose2, pose3)
def setZoneData(self, zone_mm)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def setAcceleration(self, accel_mmss)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def RunCode(self, code, is_function_call=False)