47 JOINT_DATA = [
'X',
'Y',
'Z',
'PH',
'RH',
'RZ']
52 """Prints a pose target""" 56 if joints
is not None:
57 for j
in range(len(joints)):
58 str_xyzwpr += (
'%s %.6f ' % (JOINT_DATA[j], joints[j]))
60 str_xyzwpr = str_xyzwpr[:-1]
62 str_xyzwpr =
'X %.3f Y %.3f Z %.3f A %.3f B %.3f C %.3f' % (x,y,z,r,p,w)
67 """Prints a joint target""" 69 for i
in range(len(joints)):
70 str = str + (
'%s %.6f ' % (JOINT_DATA[i], joints[i]))
77 """Robot post object""" 93 def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
99 for k,v
in kwargs.items():
100 if k ==
'lines_x_prog':
104 self.
addline(
'// program: %s' % progname)
108 self.
addline(
'// end of program ' + progname)
110 def ProgSave(self, folder, progname, ask_user=False, show_result=False):
111 progname = progname +
'.' + self.
PROG_EXT 113 filesave =
getSaveFile(folder, progname,
'Save program as...')
114 if filesave
is not None:
115 filesave = filesave.name
119 filesave = folder +
'/' + progname
120 fid = open(filesave,
"w")
123 print(
'SAVED: %s\n' % filesave)
127 if type(show_result)
is str:
130 p = subprocess.Popen([show_result, filesave])
131 elif type(show_result)
is list:
133 p = subprocess.Popen(show_result + [filesave])
137 os.startfile(filesave)
139 if len(self.
LOG) > 0:
140 mbox(
'Program generation LOG:\n\n' + self.
LOG)
143 """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". 144 The connection parameters must be provided in the robot connection menu of RoboDK""" 147 def MoveJ(self, pose, joints, conf_RLF=None):
148 """Add a joint movement""" 151 def MoveL(self, pose, joints, conf_RLF=None):
152 """Add a linear movement""" 155 def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
156 """Add a circular movement""" 160 def setFrame(self, pose, frame_id=None, frame_name=None):
161 """Change the robot reference frame""" 165 def setTool(self, pose, tool_id=None, tool_name=None):
166 """Change the robot TCP""" 171 """Pause the robot program""" 175 self.
addline(
'DWELL %.3f' % (time_ms*0.001))
178 """Changes the robot speed (in mm/s)""" 183 """Changes the robot acceleration (in mm/s2)""" 188 """Changes the robot joint speed (in deg/s)""" 193 """Changes the robot joint acceleration (in deg/s2)""" 198 """Changes the rounding radius (aka CNT, APO or zone data) to make the movement smoother""" 200 self.addline(
'ROUNDING ON')
202 self.addline(
'ROUNDING OFF')
205 """Sets a variable (digital output) to a given value""" 206 if type(io_var) != str:
207 io_var =
'OUT[%s]' % str(io_var)
208 if type(io_value) != str:
215 self.
addline(
'%s=%s' % (io_var, io_value))
217 def waitDI(self, io_var, io_value, timeout_ms=-1):
218 """Waits for a variable (digital input) io_var to attain a given value io_value. Optionally, a timeout can be provided.""" 219 if type(io_var) != str:
220 io_var =
'IN[%s]' % str(io_var)
221 if type(io_value) != str:
229 self.
addline(
'WAIT FOR %s==%s' % (io_var, io_value))
231 self.
addline(
'WAIT FOR %s==%s TIMEOUT=%.1f' % (io_var, io_value, timeout_ms))
233 def RunCode(self, code, is_function_call = False):
234 """Adds code or a function call""" 236 code.replace(
' ',
'_')
237 if not code.endswith(
')'):
244 """Display a message in the robot controller screen (teach pendant)""" 248 self.
addline(
'MSGBOX (DF_MSGBOX_OKONLY),"%s" ' % message)
252 """Add a program line""" 253 self.
PROG = self.
PROG + newline +
'\n' 256 """Add a log message""" 257 self.
LOG = self.
LOG + newline +
'\n' 262 [x,y,z,r,p,w] = xyzrpw
272 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]])
275 """Test the post with a basic program""" 279 robot.ProgStart(
"Program")
280 robot.RunMessage(
"Program generated by RoboDK using a custom post processor",
True)
281 robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
282 robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
283 robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
284 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
285 robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
286 robot.RunMessage(
"Setting air valve 1 on")
287 robot.RunCode(
"TCP_On",
True)
289 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
290 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
291 robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
292 robot.RunMessage(
"Setting air valve off")
293 robot.RunCode(
"TCP_Off",
True)
295 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
296 robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
297 robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
298 robot.MoveJ(
None, [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
299 robot.ProgFinish(
"Program")
302 if len(robot.LOG) > 0:
303 mbox(
'Program generation LOG:\n\n' + robot.LOG)
305 input(
"Press Enter to close...")
307 if __name__ ==
"__main__":
308 """Function to call when the module is executed by itself: test"""
def setSpeed(self, speed_mms)
def ProgStart(self, progname)
def addlog(self, newline)
def setFrame(self, pose, frame_id=None, frame_name=None)
def pose_2_str(pose, joints=None)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def setSpeedJoints(self, speed_degs)
def MoveJ(self, pose, joints, conf_RLF=None)
def setZoneData(self, zone_mm)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def ProgFinish(self, progname)
def addline(self, newline)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def setAccelerationJoints(self, accel_degss)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def setDO(self, io_var, io_value)
def RunMessage(self, message, iscomment=False)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def MoveL(self, pose, joints, conf_RLF=None)
def setTool(self, pose, tool_id=None, tool_name=None)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def RunCode(self, code, is_function_call=False)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def setAcceleration(self, accel_mmss)