50 """Converts a pose target to a string""" 52 return (
'P(%.3f,%.3f,%.3f,%.3f,%.3f,%.3f)' % (x,y,z,w,p,r))
55 """Contverts a joint target to a string""" 56 return 'J(%s)' % (
','.join(format(ji,
".5f")
for ji
in angles))
61 """Robot post object""" 79 def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
92 self.
addline(
'Sub %s' % progname)
99 def ProgSave(self, folder, progname, ask_user = False, show_result = False):
100 progname = progname +
'.' + self.
PROG_EXT 102 filesave =
getSaveFile(folder, progname,
'Save program as...')
103 if filesave
is not None:
104 filesave = filesave.name
108 filesave = folder +
'/' + progname
109 fid = open(filesave,
"w")
112 print(
'SAVED: %s\n' % filesave)
117 if type(show_result)
is str:
120 p = subprocess.Popen([show_result, filesave])
121 elif type(show_result)
is list:
123 p = subprocess.Popen(show_result + [filesave])
127 os.startfile(filesave)
128 if len(self.
LOG) > 0:
129 mbox(
'Program generation LOG:\n\n' + self.
LOG)
132 """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". 133 The connection parameters must be provided in the robot connection menu of RoboDK""" 136 def MoveJ(self, pose, joints, conf_RLF=None):
137 """Add a joint movement""" 141 def MoveL(self, pose, joints, conf_RLF=None):
142 """Add a linear movement""" 149 def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
150 """Add a circular movement""" 155 def setFrame(self, pose, frame_id=None, frame_name=None):
156 """Change the robot reference frame""" 157 if frame_id
is not None and frame_id > 0:
162 def setTool(self, pose, tool_id=None, tool_name=None):
163 """Change the robot TCP""" 164 if tool_id
is not None and tool_id > 0:
170 """Pause the robot program""" 174 self.
addline(
'DELAY %i' % time_ms)
177 """Changes the robot speed (in mm/s)""" 181 """Changes the robot acceleration (in mm/s2)""" 188 """Changes the robot joint speed (in deg/s)""" 193 """Changes the robot joint acceleration (in deg/s2)""" 198 """Changes the zone data approach (makes the movement more smooth)""" 208 """Sets a variable (output) to a given value""" 209 if type(io_var) != str:
210 io_var =
'IO[%s]' % str(io_var)
211 if type(io_value) != str:
218 self.
addline(
'OUT %s = %s' % (io_var, io_value))
220 def waitDI(self, io_var, io_value, timeout_ms=-1):
221 """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided.""" 222 if type(io_var) != str:
223 io_var =
'IO[%s]' % str(io_var)
224 if type(io_value) != str:
232 self.
addline(
'WAIT %s = %s' % (io_var, io_value))
234 self.
addline(
'WAIT %s = %s, %.0f' % (io_var, io_value, timeout_ms))
236 def RunCode(self, code, is_function_call = False):
237 """Adds code or a function call""" 239 code.replace(
' ',
'_')
240 if code.find(
'(') < 0:
247 """Add a joint movement""" 251 self.
addline(
'\'Output "' + message +
'"')
255 """Add a program line""" 259 """Add a log message""" 260 self.
LOG = self.
LOG + newline +
'\n' 265 [x,y,z,r,p,w] = xyzrpw
275 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]])
278 """Test the post with a basic program""" 280 robot =
RobotPost(
'Vplus_custom',
'Generic Adept Robot')
282 robot.ProgStart(
"Program")
283 robot.RunMessage(
"Program generated by RoboDK",
True)
284 robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
285 robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
286 robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
287 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
288 robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
289 robot.RunMessage(
"Setting air valve 1 on")
290 robot.RunCode(
"TCP_On",
True)
292 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
293 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
294 robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
295 robot.RunMessage(
"Setting air valve off")
296 robot.RunCode(
"TCP_Off(55)",
True)
298 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
299 robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
300 robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
301 robot.ProgFinish(
"Program")
304 if len(robot.LOG) > 0:
305 mbox(
'Program generation LOG:\n\n' + robot.LOG)
307 input(
"Press Enter to close...")
309 if __name__ ==
"__main__":
310 """Function to call when the module is executed by itself: test""" def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def MoveJ(self, pose, joints, conf_RLF=None)
def setZoneData(self, zone_mm)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def setFrame(self, pose, frame_id=None, frame_name=None)
def MoveL(self, pose, joints, conf_RLF=None)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def RunMessage(self, message, iscomment=False)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def setSpeedJoints(self, speed_degs)
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 addline(self, newline)
def setAcceleration(self, accel_mmss)
def ProgFinish(self, progname)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def setSpeed(self, speed_mms)
def setDO(self, io_var, io_value)
def RunCode(self, code, is_function_call=False)
def addlog(self, newline)
def ProgStart(self, progname)