50 """Converts a pose target to a string""" 51 if reference
is not None:
55 return (
'TRANS(%.3f,%.3f,%.3f,%.4f,%.4f,%.4f)' % (x,y,z,w,p,r))
58 """Contverts a joint target to a string""" 59 return '[%s]' % (
', '.join(format(ji,
".5f")
for ji
in joints))
64 """Robot post object""" 78 def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
86 self.
addline(
'.PROGRAM %s()' % progname)
93 def ProgSave(self, folder, progname, ask_user = False, show_result = False):
94 progname = progname +
'.' + self.
PROG_EXT 96 filesave =
getSaveFile(folder, progname,
'Save program as...')
97 if filesave
is not None:
98 filesave = filesave.name
102 filesave = folder +
'/' + progname
103 fid = open(filesave,
"w")
106 print(
'SAVED: %s\n' % filesave)
111 if type(show_result)
is str:
114 p = subprocess.Popen([show_result, filesave])
115 elif type(show_result)
is list:
117 p = subprocess.Popen(show_result + [filesave])
121 os.startfile(filesave)
122 if len(self.
LOG) > 0:
123 mbox(
'Program generation LOG:\n\n' + self.
LOG)
126 """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". 127 The connection parameters must be provided in the robot connection menu of RoboDK""" 130 def MoveJ(self, pose, joints, conf_RLF=None):
131 """Add a joint movement""" 134 def MoveL(self, pose, joints, conf_RLF=None):
135 """Add a linear movement""" 138 def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
139 """Add a circular movement""" 143 def setFrame(self, pose, frame_id=None, frame_name=None):
144 """Change the robot reference frame""" 147 def setTool(self, pose, tool_id=None, tool_name=None):
148 """Change the robot TCP""" 152 """Pause the robot program""" 156 self.
addline(
'TWAIT %.3f' % (time_ms*0.001))
159 """Changes the robot speed (in mm/s)""" 160 speed_mms = min(5000, speed_mms)
161 self.
addline(
'SPEED %.1f MM/S ALWAYS' % (speed_mms))
164 """Changes the robot acceleration (in mm/s2)""" 166 accel_percentage = min(100,max(0,accel_mmss))
167 self.
addline(
'ACCEL %.1f %.1f' % (accel_percentage, accel_percentage))
170 """Changes the robot joint speed (in deg/s)""" 172 self.
addline(
'SPEED %.1f ALWAYS' % (min(100,100*speed_degs/500)))
175 """Changes the robot joint acceleration (in deg/s2)""" 176 self.
addlog(
'setAccelerationJoints not defined')
179 """Changes the zone data approach (makes the movement more smooth)""" 180 self.
addline(
'ACCURACY %.3f ALWAYS' % zone_mm)
183 """Sets a variable (output) to a given value""" 184 if type(io_var) != str:
185 io_var =
'%s' % str(io_var)
186 if type(io_value) != str:
193 self.
addline(
'SIGNAL %s%s' % (io_value, io_var))
195 def waitDI(self, io_var, io_value, timeout_ms=-1):
196 """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided.""" 197 if type(io_var) != str:
198 io_var =
'%s' % str(io_var)
199 if type(io_value) != str:
207 self.
RunMessage(
'Timeout not implemented',
True)
209 self.
addline(
'WAIT SIG(%s%s)' % (io_value, io_var))
211 def RunCode(self, code, is_function_call = False):
212 """Adds code or a function call""" 214 code.replace(
' ',
'_')
215 if code.find(
'(') < 0:
222 """Add a joint movement""" 226 self.
addline(
'TYPE "' + message +
'"')
230 """Add a program line""" 234 """Add a log message""" 235 self.
LOG = self.
LOG + newline +
'\n' 240 [x,y,z,r,p,w] = xyzrpw
250 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]])
253 """Test the post with a basic program""" 255 robot =
RobotPost(
'Vplus_custom',
'Generic Adept Robot')
257 robot.ProgStart(
"Program")
258 robot.RunMessage(
"Program generated by RoboDK",
True)
259 robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
260 robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
261 robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
262 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
263 robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
264 robot.RunMessage(
"Setting air valve 1 on")
265 robot.RunCode(
"TCP_On",
True)
267 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
268 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
269 robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
270 robot.RunMessage(
"Setting air valve off")
271 robot.RunCode(
"TCP_Off(55)",
True)
273 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
274 robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
275 robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
276 robot.ProgFinish(
"Program")
279 if len(robot.LOG) > 0:
280 mbox(
'Program generation LOG:\n\n' + robot.LOG)
282 input(
"Press Enter to close...")
284 if __name__ ==
"__main__":
285 """Function to call when the module is executed by itself: test""" def ProgStart(self, progname)
def ProgFinish(self, progname)
def MoveJ(self, pose, joints, conf_RLF=None)
def RunCode(self, code, is_function_call=False)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def setTool(self, pose, tool_id=None, tool_name=None)
def pose_2_str(pose, joints=None, reference=None)
def setAccelerationJoints(self, accel_degss)
def setAcceleration(self, accel_mmss)
def setSpeed(self, speed_mms)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def setSpeedJoints(self, speed_degs)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def addline(self, newline)
def setZoneData(self, zone_mm)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def MoveL(self, pose, joints, conf_RLF=None)
def RunMessage(self, message, iscomment=False)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def setFrame(self, pose, frame_id=None, frame_name=None)
def setDO(self, io_var, io_value)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def addlog(self, newline)