48 JOINT_DATA = [
'X',
'Y',
'Z',
'A',
'B',
'C',
'X1=',
'Y1=',
'Z1=']
52 """Prints a pose target""" 54 str_xyzwpr =
'X%.4f Y%.4f Z%.4f A%.4f B%.4f C%.4f' % (x,y,z,r,p,w)
55 if joints
is not None:
57 for j
in range(6,len(joints)):
58 str_xyzwpr += (
' %s%.6f ' % (JOINT_DATA[j], joints[j]))
63 """Prints a joint target""" 65 for i
in range(len(joints)):
66 str = str + (
'%s%.6f ' % (JOINT_DATA[i], joints[i]))
73 """Robot post object""" 91 MOVE_NAMES.append(
"MCS")
93 MOVE_NAMES.append(
"HSC")
95 MOVE_NAMES.append(
"PTP")
101 def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
109 self.
addline(
'%% program: %s()' % progname,
False)
112 self.
addline(
'#HSC [BSPLINE PATH_DEV 0.0000 TRACK_DEV 0.0000]',
False)
114 self.
addline(
'#CS DEF[1][0.0000,0.0000,0.0000,0.0000,0.0000,0.0000]')
121 self.
addline(
'%% End of program %s' % progname,
False)
123 def ProgSave(self, folder, progname, ask_user=False, show_result=False):
124 progname = progname +
'.' + self.
PROG_EXT 126 filesave =
getSaveFile(folder, progname,
'Save program as...')
127 if filesave
is not None:
128 filesave = filesave.name
132 filesave = folder +
'/' + progname
133 fid = open(filesave,
"w")
134 for line
in self.
PROG:
135 fid.write(line +
'\n')
137 print(
'SAVED: %s\n' % filesave)
141 if type(show_result)
is str:
144 p = subprocess.Popen([show_result, filesave])
145 elif type(show_result)
is list:
147 p = subprocess.Popen(show_result + [filesave])
151 os.startfile(filesave)
153 if len(self.
LOG) > 0:
154 mbox(
'Program generation LOG:\n\n' + self.
LOG)
157 """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". 158 The connection parameters must be provided in the robot connection menu of RoboDK""" 174 def MoveJ(self, pose, joints, conf_RLF=None):
175 """Add a joint movement""" 183 def MoveL(self, pose, joints, conf_RLF=None):
184 """Add a linear movement""" 189 def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
190 """Add a circular movement""" 193 self.
addline(
'G2 X%.3f Y%.3f Z%.3f I1=%.3f J1=%.3f K1=%.3f' % (xyz2[0], xyz2[1], xyz2[2], xyz1[0], xyz1[1], xyz1[2]))
196 def setFrame(self, pose, frame_id=None, frame_name=None):
197 """Change the robot reference frame""" 199 self.
addline(
'%% Using Reference %s: %s' % (frame_name,
pose_2_str(pose)),
False)
200 self.
addline(
'%% (Using absolute coordinates)',
False)
202 def setTool(self, pose, tool_id=None, tool_name=None):
203 """Change the robot TCP""" 211 self.
addline(
'M6 T%i' % tool_id)
221 """Pause the robot program""" 223 self.
addline(
'%% PAUSE',
False)
225 self.
addline(
'%% WAIT %.3f' % (time_ms*0.001),
False)
228 """Changes the robot speed (in mm/s)""" 229 self.
SPEED_F =
' F%.3f' % (speed_mms*60)
232 """Changes the robot acceleration (in mm/s2)""" 233 self.
addlog(
'setAcceleration not defined')
236 """Changes the robot joint speed (in deg/s)""" 237 self.
addlog(
'setSpeedJoints not defined')
240 """Changes the robot joint acceleration (in deg/s2)""" 241 self.
addlog(
'setAccelerationJoints not defined')
244 """Changes the rounding radius (aka CNT, APO or zone data) to make the movement smoother""" 245 self.
addlog(
'setZoneData not defined (%.1f mm)' % zone_mm)
248 """Sets a variable (digital output) to a given value""" 249 if type(io_var) != str:
250 io_var =
'OUT[%s]' % str(io_var)
251 if type(io_value) != str:
258 self.
addline(
'%s=%s' % (io_var, io_value))
260 def waitDI(self, io_var, io_value, timeout_ms=-1):
261 """Waits for a variable (digital input) io_var to attain a given value io_value. Optionally, a timeout can be provided.""" 262 if type(io_var) != str:
263 io_var =
'IN[%s]' % str(io_var)
264 if type(io_value) != str:
272 self.
addline(
'WAIT FOR %s==%s' % (io_var, io_value))
274 self.
addline(
'WAIT FOR %s==%s TIMEOUT=%.1f' % (io_var, io_value, timeout_ms))
276 def RunCode(self, code, is_function_call = False):
277 """Adds code or a function call""" 279 code.replace(
' ',
'_')
280 if not code.endswith(
')'):
287 """Display a message in the robot controller screen (teach pendant)""" 289 self.
addline(
'%% ' + message,
False)
291 self.
addline(
'%% Show message: %s' % message,
False)
295 """Add a program line""" 298 newline =
'N%i ' % self.
nId + newline
300 self.
PROG.append(newline)
303 """Add a log message""" 304 self.
LOG = self.
LOG + newline +
'\n' 309 [x,y,z,r,p,w] = xyzrpw
319 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]])
322 """Test the post with a basic program""" 326 robot.ProgStart(
"Program")
327 robot.RunMessage(
"Program generated by RoboDK using a custom post processor",
True)
328 robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]), 3,
'Reference 2')
329 robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]), 5,
'Tool 5')
330 robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
331 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
332 robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
333 robot.RunMessage(
"Setting air valve 1 on")
334 robot.RunCode(
"TCP_On",
True)
336 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
337 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
338 robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
339 robot.RunMessage(
"Setting air valve off")
340 robot.RunCode(
"TCP_Off",
True)
342 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
343 robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
344 robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
345 robot.MoveJ(
None, [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
346 robot.ProgFinish(
"Program")
348 for line
in robot.PROG:
351 if len(robot.LOG) > 0:
352 mbox(
'Program generation LOG:\n\n' + robot.LOG)
354 input(
"Press Enter to close...")
356 if __name__ ==
"__main__":
357 """Function to call when the module is executed by itself: test""" def waitDI(self, io_var, io_value, timeout_ms=-1)
def setAccelerationJoints(self, accel_degss)
def MoveJ(self, pose, joints, conf_RLF=None)
def ProgStart(self, progname)
def setSpeedJoints(self, speed_degs)
def ProgFinish(self, progname)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def setTool(self, pose, tool_id=None, tool_name=None)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def MoveL(self, pose, joints, conf_RLF=None)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def setAcceleration(self, accel_mmss)
def addline(self, newline, add_N=True)
def setFrame(self, pose, frame_id=None, frame_name=None)
def RunMessage(self, message, iscomment=False)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
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 RunCode(self, code, is_function_call=False)
def setDO(self, io_var, io_value)
def set_move_type(self, move_type)
def pose_2_str(pose, joints=None)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def setZoneData(self, zone_mm)
def addlog(self, newline)