52 """Prints a pose target""" 54 return (
'XY(%.3f, %.3f, %.3f, %.3f, %.3f, %.3f)' % (x,y,z,c,b,a))
57 """Prints a joint target""" 59 for i
in range(len(angles)):
61 str = str + (
'%.3f,' % (angles[i]))
63 return "AglToPls(" + str +
")" 68 """Robot post object""" 85 def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
95 self.
addline(
'Function %s' % progname)
104 def ProgSave(self, folder, progname, ask_user=True, show_result=True):
105 progname = progname +
'.' + self.
PROG_EXT 107 filesave =
getSaveFile(folder, progname,
'Save program as...')
108 if filesave
is not None:
109 filesave = filesave.name
113 filesave = folder +
'/' + progname
114 fid = open(filesave,
"w")
117 print(
'SAVED: %s\n' % filesave)
122 if type(show_result)
is str:
125 p = subprocess.Popen([show_result, filesave])
126 elif type(show_result)
is list:
128 p = subprocess.Popen(show_result + [filesave])
132 os.startfile(filesave)
134 if len(self.
LOG) > 0:
135 mbox(
'Program generation LOG:\n\n' + self.
LOG)
138 """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". 139 The connection parameters must be provided in the robot connection menu of RoboDK""" 142 def MoveJ(self, pose, joints, conf_RLF=None):
143 """Add a joint movement""" 148 def MoveL(self, pose, joints, conf_RLF=None):
149 """Add a linear movement""" 150 poseabs = self.
FRAME * pose
153 def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
154 """Add a circular movement""" 155 poseabs1 = self.
FRAME * pose1
156 poseabs2 = self.
FRAME * pose2
159 def setFrame(self, pose, frame_id = None, frame_name = None):
160 """Change the robot reference frame""" 164 def setTool(self, pose, tool_id = None, tool_name = None):
165 """Change the robot TCP""" 169 self.
addline(
"' Using Tool frame %s: %s" % (tool_name, pose_str))
173 self.
addline(
'TLSet ' + str(tool_id) +
", " + pose_str)
174 self.
addline(
'Tool ' + str(tool_id))
177 """Pause the robot program""" 178 self.
addline(
'Wait %.3f' % (time_ms*0.001))
181 """Changes the robot speed (in mm/s)""" 182 self.
addline(
'Speed %.2f' % speed_mms)
185 """Changes the robot acceleration (in %)""" 186 accel_ptg = min(accel_ptg, 100)
187 self.
addline(
'Accel %.2f, %.2f' % (accel_ptg, accel_ptg))
190 """Changes the robot joint speed (in deg/s)""" 195 """Changes the robot joint acceleration (in deg/s2)""" 200 """Changes the zone data approach (makes the movement more smooth)""" 205 """Sets a variable (output) to a given value""" 206 if type(io_var) != str:
207 io_var =
'%s' % str(io_var)
208 if type(io_value) != str:
215 self.addline(
'%s %s' % (io_value, io_var))
217 def waitDI(self, io_var, io_value, timeout_ms=-1):
218 """Waits for an 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 %s = %s' % (io_var, io_value))
231 self.
addline(
'Wait %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(
' ',
'_')
242 """Display a message in the robot controller screen (teach pendant)""" 246 self.
addline(
'Print "%s"' % message)
250 """Add a program line""" 254 """Add a log message""" 255 self.
LOG = self.
LOG + newline +
'\n' 260 [x,y,z,r,p,w] = xyzrpw
270 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]])
273 """Test the post with a basic program""" 277 robot.ProgStart(
"Program")
279 robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
280 robot.MoveL(
Pose([200, 250, 15, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
281 robot.MoveC(
Pose([200, 200, 34, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122],
Pose([200, 200, 15, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122])
289 if len(robot.LOG) > 0:
290 mbox(
'Program generation LOG:\n\n' + robot.LOG)
292 input(
"Press Enter to close...")
294 if __name__ ==
"__main__":
295 """Function to call when the module is executed by itself: test""" def setDO(self, io_var, io_value)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def setSpeed(self, speed_mms)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def MoveJ(self, pose, joints, conf_RLF=None)
def setFrame(self, pose, frame_id=None, frame_name=None)
def MoveL(self, pose, joints, conf_RLF=None)
def RunMessage(self, message, iscomment=False)
def ProgStart(self, progname)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def setTool(self, pose, tool_id=None, tool_name=None)
def setAccelerationJoints(self, accel_degss)
def addlog(self, newline)
def addline(self, newline)
def Acceleration(self, accel_ptg)
def setZoneData(self, zone_mm)
def ProgFinish(self, progname)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def setSpeedJoints(self, speed_degs)
def RunCode(self, code, is_function_call=False)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def ProgSave(self, folder, progname, ask_user=True, show_result=True)