49 """Prints a pose target""" 51 return (
'%.3f %.3f %.3f %.3f %.3f %.3f' % (x,y,z,r,p,w))
54 """Prints a joint target""" 56 for i
in range(len(angles)):
57 str = str + (
'%.6f,' % (angles[i]))
64 """Robot post object""" 79 def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
91 self.
addline(
"'**********************************")
92 self.
addline(
"'Sub Routine: %s " % progname)
93 self.
addline(
"'**********************************")
98 self.
addline(
"'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
99 self.
addline(
'\' Main 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)
128 if type(show_result)
is str:
131 p = subprocess.Popen([show_result, filesave])
132 elif type(show_result)
is list:
134 p = subprocess.Popen(show_result + [filesave])
138 os.startfile(filesave)
140 if len(self.
LOG) > 0:
141 mbox(
'Program generation LOG:\n\n' + self.
LOG)
144 """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". 145 The connection parameters must be provided in the robot connection menu of RoboDK""" 148 def MoveJ(self, pose, joints, conf_RLF=None):
149 """Add a joint movement""" 152 for i
in range(len(joints)):
153 self.
addline(
'DRIVE(%i,%.3f)' % (i+1, joints[i]))
155 def MoveL(self, pose, joints, conf_RLF=None):
156 """Add a linear movement""" 157 poseabs = self.
FRAME * pose
160 def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
161 """Add a circular movement""" 162 poseabs1 = self.
FRAME * pose1
163 poseabs2 = self.
FRAME * pose2
166 def setFrame(self, pose, frame_id=None, frame_name=None):
167 """Change the robot reference frame""" 171 def setTool(self, pose, tool_id=None, tool_name=None):
172 """Change the robot TCP""" 177 """Pause the robot program""" 181 self.
addline(
'DELAY %.3f' % (time_ms))
184 """Changes the robot speed (in mm/s)""" 185 self.
addline(
'SPEED %i' % max(min(speed_mms/5000, 100),1))
188 """Changes the robot acceleration (in mm/s2)""" 189 self.
addline(
'ACCEL %i' % max(min(accel_mmss/500, 100),1))
192 """Changes the robot joint speed (in deg/s)""" 193 self.
addlog(
'setSpeedJoints not defined')
196 """Changes the robot joint acceleration (in deg/s2)""" 197 self.
addlog(
'setAccelerationJoints not defined')
200 """Changes the zone data approach (makes the movement more smooth)""" 201 self.
addlog(
'setZoneData not defined (%.1f mm)' % zone_mm)
204 """Sets a variable (output) to a given value""" 205 if type(io_var) != str:
206 io_var =
'OUT[%s]' % str(io_var)
207 if type(io_value) != str:
214 self.
addline(
'%s=%s' % (io_var, io_value))
216 def waitDI(self, io_var, io_value, timeout_ms=-1):
217 """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided.""" 218 if type(io_var) != str:
219 io_var =
'IN[%s]' % str(io_var)
220 if type(io_value) != str:
228 self.
addline(
'WAIT FOR %s==%s' % (io_var, io_value))
230 self.
addline(
'WAIT FOR %s==%s TIMEOUT=%.1f' % (io_var, io_value, timeout_ms))
232 def RunCode(self, code, is_function_call = False):
233 """Adds code or a function call""" 235 code.replace(
' ',
'_')
239 self.
addline(
'GOSUB *' + code +
" ' Call sub routine: " + code)
244 """Display a message in the robot controller screen (teach pendant)""" 248 self.
addline(
'PRINT "%s"' % message)
252 """Add a program line""" 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.ProgFinish(
"Program")
301 if len(robot.LOG) > 0:
302 mbox(
'Program generation LOG:\n\n' + robot.LOG)
304 input(
"Press Enter to close...")
306 if __name__ ==
"__main__":
307 """Function to call when the module is executed by itself: test""" def addline(self, newline)
def setDO(self, io_var, io_value)
def MoveL(self, pose, joints, conf_RLF=None)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def RunMessage(self, message, iscomment=False)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def ProgStart(self, progname)
def addlog(self, newline)
def setZoneData(self, zone_mm)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def setSpeedJoints(self, speed_degs)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def setTool(self, pose, tool_id=None, tool_name=None)
def setAcceleration(self, accel_mmss)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def RunCode(self, code, is_function_call=False)
def setAccelerationJoints(self, accel_degss)
def setSpeed(self, speed_mms)
def MoveJ(self, pose, joints, conf_RLF=None)
def setFrame(self, pose, frame_id=None, frame_name=None)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def ProgFinish(self, progname)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)