47 JOINT_DATA = [
'Q1',
'Q2',
'Q3',
'Q4',
'Q5',
'Q6',
'Ra',
'Rb',
'Rc']
51 """Prints a pose target""" 53 str_xyzwpr =
'X %.3f Y %.3f Z %.3f A %.3f B %.3f C %.3f' % (x,y,z,r,p,w)
54 if joints
is not None:
56 for j
in range(6,len(joints)):
57 str_xyzwpr += (
' %s %.6f ' % (JOINT_DATA[j], joints[j]))
62 """Prints a joint target""" 64 for i
in range(len(joints)):
65 str = str + (
'%s %.6f ' % (JOINT_DATA[i], joints[i]))
72 """Robot post object""" 87 def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
95 self.
addline(
'; program: %s()' % progname)
103 def ProgSave(self, folder, progname, ask_user=False, show_result=False):
104 progname = progname +
'.' + self.
PROG_EXT 106 filesave =
getSaveFile(folder, progname,
'Save program as...')
107 if filesave
is not None:
108 filesave = filesave.name
112 filesave = folder +
'/' + progname
113 fid = open(filesave,
"w")
116 print(
'SAVED: %s\n' % filesave)
120 if type(show_result)
is str:
123 p = subprocess.Popen([show_result, filesave])
124 elif type(show_result)
is list:
126 p = subprocess.Popen(show_result + [filesave])
130 os.startfile(filesave)
132 if len(self.
LOG) > 0:
133 mbox(
'Program generation LOG:\n\n' + self.
LOG)
136 """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". 137 The connection parameters must be provided in the robot connection menu of RoboDK""" 140 def MoveJ(self, pose, joints, conf_RLF=None):
141 """Add a joint movement""" 145 def MoveL(self, pose, joints, conf_RLF=None):
146 """Add a linear movement""" 151 def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
152 """Add a circular movement""" 156 self.
addline(
'N%02i G90 G102 X%.3f Y%.3f Z%.3f I1=%.3f J1=%.3f K1=%.3f' % (self.
nId, xyz2[0], xyz2[1], xyz2[2], xyz1[0], xyz1[1], xyz1[2]))
159 def setFrame(self, pose, frame_id=None, frame_name=None):
160 """Change the robot reference frame""" 165 def setTool(self, pose, tool_id=None, tool_name=None):
166 """Change the robot TCP""" 173 """Pause the robot program""" 177 self.
addline(
'; WAIT %.3f' % (time_ms*0.001))
180 """Changes the robot speed (in mm/s)""" 181 self.
addline(
'F%.3f' % (speed_mms*60))
184 """Changes the robot acceleration (in mm/s2)""" 185 self.
addlog(
'setAcceleration not defined')
188 """Changes the robot joint speed (in deg/s)""" 189 self.
addlog(
'setSpeedJoints not defined')
192 """Changes the robot joint acceleration (in deg/s2)""" 193 self.
addlog(
'setAccelerationJoints not defined')
196 """Changes the rounding radius (aka CNT, APO or zone data) to make the movement smoother""" 197 self.
addlog(
'setZoneData not defined (%.1f mm)' % zone_mm)
200 """Sets a variable (digital output) to a given value""" 201 if type(io_var) != str:
202 io_var =
'OUT[%s]' % str(io_var)
203 if type(io_value) != str:
210 self.
addline(
'%s=%s' % (io_var, io_value))
212 def waitDI(self, io_var, io_value, timeout_ms=-1):
213 """Waits for a variable (digital input) io_var to attain a given value io_value. Optionally, a timeout can be provided.""" 214 if type(io_var) != str:
215 io_var =
'IN[%s]' % str(io_var)
216 if type(io_value) != str:
224 self.
addline(
'WAIT FOR %s==%s' % (io_var, io_value))
226 self.
addline(
'WAIT FOR %s==%s TIMEOUT=%.1f' % (io_var, io_value, timeout_ms))
228 def RunCode(self, code, is_function_call = False):
229 """Adds code or a function call""" 231 code.replace(
' ',
'_')
232 if not code.endswith(
')'):
239 """Display a message in the robot controller screen (teach pendant)""" 243 self.
addline(
'; Show message: %s' % message)
247 """Add a program line""" 248 self.
PROG = self.
PROG + newline +
'\n' 251 """Add a log message""" 252 self.
LOG = self.
LOG + newline +
'\n' 257 [x,y,z,r,p,w] = xyzrpw
267 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]])
270 """Test the post with a basic program""" 274 robot.ProgStart(
"Program")
275 robot.RunMessage(
"Program generated by RoboDK using a custom post processor",
True)
276 robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
277 robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
278 robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
279 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
280 robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
281 robot.RunMessage(
"Setting air valve 1 on")
282 robot.RunCode(
"TCP_On",
True)
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([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
286 robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
287 robot.RunMessage(
"Setting air valve off")
288 robot.RunCode(
"TCP_Off",
True)
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, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
292 robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
293 robot.MoveJ(
None, [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
294 robot.ProgFinish(
"Program")
297 if len(robot.LOG) > 0:
298 mbox(
'Program generation LOG:\n\n' + robot.LOG)
300 input(
"Press Enter to close...")
302 if __name__ ==
"__main__":
303 """Function to call when the module is executed by itself: test""" def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def setTool(self, pose, tool_id=None, tool_name=None)
def setSpeed(self, speed_mms)
def RunMessage(self, message, iscomment=False)
def setSpeedJoints(self, speed_degs)
def setDO(self, io_var, io_value)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def ProgStart(self, progname)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def setAcceleration(self, accel_mmss)
def setZoneData(self, zone_mm)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def addlog(self, newline)
def MoveL(self, pose, joints, conf_RLF=None)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def MoveJ(self, pose, joints, conf_RLF=None)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def addline(self, newline)
def pose_2_str(pose, joints=None)
def setFrame(self, pose, frame_id=None, frame_name=None)
def ProgFinish(self, progname)
def setAccelerationJoints(self, accel_degss)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def RunCode(self, code, is_function_call=False)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)