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""" 366 if self.LAST_POSE
is not None and pose
is not None:
373 target = self.joints_2_str(joints)
375 target = self.pose_2_str(pose,joints)
378 if self.FLY_DIST > 0:
379 self.addline(
'MOVEFLY LINEAR TO %s ADVANCE' % target)
381 self.addline(
'MOVE LINEAR TO ' + target)
383 self.LAST_POSE = pose
385 def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
386 """Add a circular movement""" 395 def setFrame(self, pose, frame_id=None, frame_name=None):
396 """Change the robot reference frame""" 399 def setTool(self, pose, tool_id=None, tool_name=None):
400 """Change the robot TCP""" 404 """Pause the robot program""" 408 self.
addline(
'DELAY %.0f' % (time_ms))
411 """Changes the robot speed (in mm/s)""" 413 self.
addline(
'$SPD_OPT := SPD_LIN')
414 self.
addline(
'$LIN_SPD := %.3f' % (speed_mms*0.001))
417 """Changes the robot acceleration (in mm/s2)""" 419 self.
addlog(
'setAcceleration not defined')
422 """Changes the robot joint speed (in deg/s)""" 423 self.
addline(
'$ROT_SPD := %.3f' % (speed_degs*pi/180.0))
426 """Changes the robot joint acceleration (in deg/s2)""" 427 self.
addlog(
'setAccelerationJoints not defined')
430 """Changes the zone data approach (makes the movement more smooth)""" 433 self.
addline(
'$FLY_DIST := %.3f' % zone_mm)
436 """Sets a variable (output) to a given value""" 437 if type(io_var) != str:
438 io_var =
'$DOUT[%s]' % str(io_var)
439 if type(io_value) != str:
446 self.
addline(
'%s := %s' % (io_var, io_value))
448 def waitDI(self, io_var, io_value, timeout_ms=-1):
449 """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided.""" 450 if type(io_var) != str:
451 io_var =
'$DIN[%s]' % str(io_var)
452 if type(io_value) != str:
464 self.
addline(
'UNTIL (%s = %s)' % (io_var, io_value))
469 self.
addline(
'UNTIL (%s = %s) OR ($TIMER[1] > %.1f)' % (io_var, io_value, timeout_ms))
470 self.
addline(
'IF $TIMER[1] > %.1f THEN' % timeout_ms)
471 self.
addline(
'-- TIMED OUT! Important: This section must be updated accordingly')
476 def RunCode(self, code, is_function_call = False):
477 """Adds code or a function call""" 482 if code.startswith(
"Extruder("):
488 code.replace(
' ',
'_')
489 bracket_id = code.find(
'(')
497 import_prog = code[:bracket_id]
500 if not import_prog
in self.
IMPORTS:
501 self.
IMPORTS.append(import_prog)
508 """Add a joint movement""" 522 """Add a program line""" 539 """Add a log message""" 543 self.
LOG = self.
LOG + newline +
'\n' 548 [x,y,z,r,p,w] = xyzrpw
558 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]])
561 """Test the post with a basic program""" 563 robot =
RobotPost(
'Comau_custom',
'Generic Comau robot')
565 robot.ProgStart(
"Program")
566 robot.RunMessage(
"Program generated by RoboDK",
True)
567 robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
568 robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
569 robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
570 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
571 robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
572 robot.RunMessage(
"Setting air valve 1 on")
573 robot.RunCode(
"TCP_On",
True)
575 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
576 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
577 robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
578 robot.RunMessage(
"Setting air valve off")
579 robot.RunCode(
"TCP_Off(55)",
True)
581 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
582 robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
583 robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
584 robot.ProgFinish(
"Program")
587 if len(robot.LOG) > 0:
588 mbox(
'Program generation LOG:\n\n' + robot.LOG)
590 input(
"Press Enter to close...")
592 if __name__ ==
"__main__":
593 """Function to call when the module is executed by itself: test"""
def ProgFinish(self, progname, new_page=False)
def setAcceleration(self, accel_mmss)
def setSpeedJoints(self, speed_degs)
def RunMessage(self, message, iscomment=False)
def MoveL(self, pose, joints, conf_RLF=None)
def addline(self, newline)
def new_move(self, pose1, pose2)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def addlog(self, newline)
def progsave(self, folder, progname, ask_user=False, show_result=False)
bool INCLUDE_SUB_PROGRAMS
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def setAccelerationJoints(self, accel_degss)
def ProgStart(self, progname, new_page=False)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def RunCode(self, code, is_function_call=False)
def MoveJ(self, pose, joints, conf_RLF=None)
def pose_angle_between(pose1, pose2)
def setDO(self, io_var, io_value)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def setZoneData(self, zone_mm)
def setFrame(self, pose, frame_id=None, frame_name=None)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def joints_2_str(self, joints)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def setSpeed(self, speed_mms)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def new_movec(self, pose1, pose2, pose3)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def pose_2_str(self, pose, joints=None, conf_RLF=None)
def setTool(self, pose, tool_id=None, tool_name=None)