50 """Converts a pose target to a string""" 51 if reference
is not None:
54 return (
'TRANS(%.3f,%.3f,%.3f,%.3f,%.3f,%.3f)' % (x,y,z,w,p,r))
57 """Contverts a joint target to a string""" 58 return '{%s}' % (
','.join(format(ji,
".5f")
for ji
in angles))
63 """Robot post object""" 78 def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
86 self.
addline(
'.PROGRAM %s()' % progname)
94 def ProgSave(self, folder, progname, ask_user = False, show_result = False):
95 progname = progname +
'.' + self.
PROG_EXT 97 filesave =
getSaveFile(folder, progname,
'Save program as...')
98 if filesave
is not None:
99 filesave = filesave.name
103 filesave = folder +
'/' + progname
104 fid = open(filesave,
"w")
107 print(
'SAVED: %s\n' % filesave)
112 if type(show_result)
is str:
115 p = subprocess.Popen([show_result, filesave])
116 elif type(show_result)
is list:
118 p = subprocess.Popen(show_result + [filesave])
122 os.startfile(filesave)
123 if len(self.
LOG) > 0:
124 mbox(
'Program generation LOG:\n\n' + self.
LOG)
127 """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". 128 The connection parameters must be provided in the robot connection menu of RoboDK""" 131 def MoveJ(self, pose, joints, conf_RLF=None):
132 """Add a joint movement""" 133 for i
in range(len(joints)):
138 def MoveL(self, pose, joints, conf_RLF=None):
139 """Add a linear movement""" 144 def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
145 """Add a circular movement""" 146 self.
addlog(
'Circular move is not supported!')
148 def setFrame(self, pose, frame_id=None, frame_name=None):
149 """Change the robot reference frame""" 154 def setTool(self, pose, tool_id=None, tool_name=None):
155 """Change the robot TCP""" 159 """Pause the robot program""" 163 self.
addline(
'DELAY %.3f' % (time_ms*0.001))
166 """Changes the robot speed (in mm/s)""" 169 self.
addline(
'SPEED %.1f, 100 MMPS ALWAYS' % (speed_mms))
173 """Changes the robot acceleration (in mm/s2)""" 175 accel_percentage = min(100,max(0,accel_mmss))
176 self.
addline(
'ACCEL %.1f, %.1f' % (accel_percentage, accel_percentage))
179 """Changes the robot joint speed (in deg/s)""" 180 self.
addlog(
'setSpeedJoints not defined')
183 """Changes the robot joint acceleration (in deg/s2)""" 184 self.
addlog(
'setAccelerationJoints not defined')
187 """Changes the zone data approach (makes the movement more smooth)""" 188 self.
addlog(
'setZoneData not defined (%.1f mm)' % zone_mm)
191 """Sets a variable (output) to a given value""" 192 if type(io_var) != str:
193 io_var =
'OUT[%s]' % str(io_var)
194 if type(io_value) != str:
201 self.
addline(
'%s=%s' % (io_var, io_value))
203 def waitDI(self, io_var, io_value, timeout_ms=-1):
204 """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided.""" 205 if type(io_var) != str:
206 io_var =
'IN[%s]' % str(io_var)
207 if type(io_value) != str:
215 self.
addline(
'WAIT FOR %s==%s' % (io_var, io_value))
217 self.
addline(
'WAIT FOR %s==%s TIMEOUT=%.1f' % (io_var, io_value, timeout_ms))
219 def RunCode(self, code, is_function_call = False):
220 """Adds code or a function call""" 222 code.replace(
' ',
'_')
223 if code.find(
'(') < 0:
230 """Add a joint movement""" 234 self.
addline(
'TYPE "' + message +
'"')
238 """Add a program line""" 242 """Add a log message""" 243 self.
LOG = self.
LOG + newline +
'\n' 248 [x,y,z,r,p,w] = xyzrpw
258 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]])
261 """Test the post with a basic program""" 263 robot =
RobotPost(
'Vplus_custom',
'Generic Adept Robot')
265 robot.ProgStart(
"Program")
266 robot.RunMessage(
"Program generated by RoboDK",
True)
267 robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
268 robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
269 robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
270 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
271 robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
272 robot.RunMessage(
"Setting air valve 1 on")
273 robot.RunCode(
"TCP_On",
True)
275 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
276 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
277 robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
278 robot.RunMessage(
"Setting air valve off")
279 robot.RunCode(
"TCP_Off(55)",
True)
281 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
282 robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
283 robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
284 robot.ProgFinish(
"Program")
287 if len(robot.LOG) > 0:
288 mbox(
'Program generation LOG:\n\n' + robot.LOG)
290 input(
"Press Enter to close...")
292 if __name__ ==
"__main__":
293 """Function to call when the module is executed by itself: test""" def setSpeed(self, speed_mms)
def setSpeedJoints(self, speed_degs)
def setAcceleration(self, accel_mmss)
def MoveJ(self, pose, joints, conf_RLF=None)
def setDO(self, io_var, io_value)
def setAccelerationJoints(self, accel_degss)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def setZoneData(self, zone_mm)
def setTool(self, pose, tool_id=None, tool_name=None)
def RunCode(self, code, is_function_call=False)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def MoveL(self, pose, joints, conf_RLF=None)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def RunMessage(self, message, iscomment=False)
def ProgStart(self, progname)
def setFrame(self, pose, frame_id=None, frame_name=None)
def addline(self, newline)
def addlog(self, newline)
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 ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def ProgFinish(self, progname)
def pose_2_str(pose, joints=None, reference=None)