49 """Prints a pose target""" 51 return (
'X=%.3f Y=%.3f Z=%.3f A=%.3f B=%.3f C=%.3f' % (x,y,z,r,p,w))
54 """Prints a joint target""" 56 data = [
'Q1',
'Q2',
'Q3',
'Q4',
'Q5',
'Q6',
'G',
'H',
'I',
'J',
'K',
'L']
57 for i
in range(len(joints)):
58 str = str + (
'%s=%.6f ' % (data[i], joints[i]))
65 """Robot post object""" 80 def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
88 self.
addline(
'; Program %s' % progname)
90 self.
addline(
'N%05i F15000 ; Set default speed' % self.
nId)
93 self.
addline(
'; End of program: %s' % progname)
97 def ProgSave(self, folder, progname, ask_user=False, show_result=False):
98 progname = progname +
'.' + self.
PROG_EXT 100 filesave =
getSaveFile(folder, progname,
'Save program as...')
101 if filesave
is not None:
102 filesave = filesave.name
106 filesave = folder +
'/' + progname
107 fid = open(filesave,
"w")
110 print(
'SAVED: %s\n' % filesave)
114 if type(show_result)
is str:
117 p = subprocess.Popen([show_result, filesave])
118 elif type(show_result)
is list:
120 p = subprocess.Popen(show_result + [filesave])
124 os.startfile(filesave)
126 if len(self.
LOG) > 0:
127 mbox(
'Program generation LOG:\n\n' + self.
LOG)
130 """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". 131 The connection parameters must be provided in the robot connection menu of RoboDK""" 134 def MoveJ(self, pose, joints, conf_RLF=None):
135 """Add a joint movement""" 139 def MoveL(self, pose, joints, conf_RLF=None):
140 """Add a linear movement""" 145 def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
146 """Add a circular movement""" 150 self.
addline(
'N%05i G02 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]))
153 def setFrame(self, pose, frame_id=None, frame_name=None):
154 """Change the robot reference frame""" 160 def setTool(self, pose, tool_id=None, tool_name=None):
161 """Change the robot TCP""" 162 self.
addline(
'; Tool frame set to: ' + tool_name)
165 self.
addline(
'N%05i M72 T=' % self.
nId + str(tool_id))
167 self.
addline(
'; N%05i M108 T=... ; Set Drillbit typenumber (not implemented)' % self.
nId)
170 """Pause the robot program""" 173 self.
addline(
'N%05i M00 ; Machine halt' % self.
nId)
175 self.
addline(
'N%05i M00 ; pause %.3f seconds' % (self.
nId, time_ms*0.001))
178 """Changes the robot speed (in mm/s)""" 179 self.
addline(
'F%.3f' % (speed_mms*60))
182 """Changes the robot acceleration (in mm/s2)""" 183 self.
addlog(
'setAcceleration not defined')
186 """Changes the robot joint speed (in deg/s)""" 187 self.
addlog(
'setSpeedJoints not defined')
190 """Changes the robot joint acceleration (in deg/s2)""" 191 self.
addlog(
'setAccelerationJoints not defined')
194 """Changes the rounding radius (aka CNT, APO or zone data) to make the movement smoother""" 195 self.
addlog(
'setZoneData not defined (%.1f mm)' % zone_mm)
198 """Sets a variable (digital output) to a given value""" 199 if type(io_var) != str:
200 io_var =
'OUT[%s]' % str(io_var)
201 if type(io_value) != str:
208 self.
addline(
'%s=%s' % (io_var, io_value))
210 def waitDI(self, io_var, io_value, timeout_ms=-1):
211 """Waits for a variable (digital input) io_var to attain a given value io_value. Optionally, a timeout can be provided.""" 212 if type(io_var) != str:
213 io_var =
'IN[%s]' % str(io_var)
214 if type(io_value) != str:
222 self.
addline(
'WAIT FOR %s==%s' % (io_var, io_value))
224 self.
addline(
'WAIT FOR %s==%s TIMEOUT=%.1f' % (io_var, io_value, timeout_ms))
226 def RunCode(self, code, is_function_call = False):
227 """Adds code or a function call""" 230 code.replace(
' ',
'_')
231 if not code.endswith(
')'):
239 """Display a message in the robot controller screen (teach pendant)""" 243 self.
addline(
'//(-------------------------------------------------------)')
244 self.
addline(
'//(%s)' % message)
245 self.
addline(
'//(-------------------------------------------------------)')
249 """Add a program line""" 250 self.
PROG = self.
PROG + newline +
'\r\n' 253 """Add a log message""" 254 self.
LOG = self.
LOG + newline +
'\n' 259 [x,y,z,r,p,w] = xyzrpw
269 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]])
272 """Test the post with a basic program""" 276 robot.ProgStart(
"Program")
277 robot.RunMessage(
"Program generated by RoboDK using a custom post processor",
True)
278 robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
279 robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]), 1,
'tool 1')
280 robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
281 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
282 robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
283 robot.RunMessage(
"Setting air valve 1 on")
284 robot.RunCode(
"TCP_On",
True)
286 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
287 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
288 robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
289 robot.RunMessage(
"Setting air valve off")
290 robot.RunCode(
"TCP_Off",
True)
292 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
293 robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
294 robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
295 robot.MoveJ(
None, [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
296 robot.ProgFinish(
"Program")
299 if len(robot.LOG) > 0:
300 mbox(
'Program generation LOG:\n\n' + robot.LOG)
302 input(
"Press Enter to close...")
304 if __name__ ==
"__main__":
305 """Function to call when the module is executed by itself: test""" def setDO(self, io_var, io_value)
def setAccelerationJoints(self, accel_degss)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def setAcceleration(self, accel_mmss)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def setSpeedJoints(self, speed_degs)
def setTool(self, pose, tool_id=None, tool_name=None)
def ProgFinish(self, progname)
def RunCode(self, code, is_function_call=False)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def ProgStart(self, progname)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def addline(self, newline)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def setFrame(self, pose, frame_id=None, frame_name=None)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def RunMessage(self, message, iscomment=False)
def setSpeed(self, speed_mms)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def MoveL(self, pose, joints, conf_RLF=None)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def addlog(self, newline)
def MoveJ(self, pose, joints, conf_RLF=None)
def setZoneData(self, zone_mm)