52 """Prints a pose target""" 54 return (
'%.3f %.3f %.3f %.3f %.3f %.3f' % (x,y,z,r,p,w))
57 """Prints a joint target""" 59 data = [
'',
'',
'',
'',
'',
'']
60 for i
in range(len(angles)):
61 str = str + (
'%.3f ' % angles[i])
68 """Robot post object""" 73 ROBOT_NAME =
'generic' 83 def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
94 self.
addline(
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
97 self.
addline(
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
99 self.
addline(
' Dim prof1 As New Profile')
100 self.
addline(
' Dim loc1 As New Location')
101 self.
addline(
' prof1.Speed = 40')
102 self.
addline(
' prof1.Straight = True')
103 self.
addline(
' Public Sub MAIN')
105 self.
addline(
' Controller.PowerEnabled = 1')
106 self.
addline(
' Robot.Attached = 1')
114 def ProgSave(self, folder, progname, ask_user=False, show_result=False):
115 progname = progname +
'.' + self.
PROG_EXT 117 filesave =
getSaveFile(folder, progname,
'Save program as...')
118 if filesave
is not None:
119 filesave = filesave.name
123 filesave = folder +
'/' + progname
124 fid = open(filesave,
"w")
127 print(
'SAVED: %s\n' % filesave)
132 if type(show_result)
is str:
135 p = subprocess.Popen([show_result, filesave])
136 elif type(show_result)
is list:
138 p = subprocess.Popen(show_result + [filesave])
142 os.startfile(filesave)
144 if len(self.
LOG) > 0:
145 mbox(
'Program generation LOG:\n\n' + self.
LOG)
148 """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". 149 The connection parameters must be provided in the robot connection menu of RoboDK""" 152 def MoveJ(self, pose, joints, conf_RLF=None):
153 """Add a joint movement""" 157 def MoveL(self, pose, joints, conf_RLF=None):
158 """Add a linear movement""" 161 def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
162 """Add a circular movement""" 165 def setFrame(self, pose, frame_id=None, frame_name=None):
166 """Change the robot reference frame""" 169 def setTool(self, pose, tool_id=None, tool_name=None):
170 """Change the robot TCP""" 174 """Pause the robot program""" 175 self.
addline(
' Move.Delay(%s)' % (time_ms*0.001))
178 """Changes the robot speed (in mm/s)""" 179 self.
addline(
' prof1.Speed = %0.2f' % speed_mms)
182 """Changes the robot acceleration (in %)""" 183 self.
addline(
' prof1.Accel = %0.2f' % accel_ptg)
186 """Changes the robot deceleration (in %)""" 187 self.
addlog(
' prof1.decel = %0.2f' % decel_ptg)
190 """Changes the robot joint speed (in deg/s)""" 191 self.
addlog(
'setSpeedJoints not defined')
194 """Changes the robot joint acceleration (in deg/s2)""" 195 self.
addlog(
'setAccelerationJoints not defined')
198 """Changes the zone data approach (makes the movement more smooth)""" 199 self.
addlog(
'setZoneData not defined (%.1f mm)' % zone_mm)
202 """Sets a variable (output) to a given value""" 203 if type(io_var) != str:
204 io_var =
'OUT[%s]' % str(io_var)
205 if type(io_value) != str:
212 self.
addline(
'%s=%s' % (io_var, io_value))
214 def waitDI(self, io_var, io_value, timeout_ms=-1):
215 """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided.""" 216 if type(io_var) != str:
217 io_var =
'IN[%s]' % str(io_var)
218 if type(io_value) != str:
226 self.
addline(
'WAIT FOR %s==%s' % (io_var, io_value))
228 self.
addline(
'WAIT FOR %s==%s TIMEOUT=%.1f' % (io_var, io_value, timeout_ms))
230 def RunCode(self, code, is_function_call = False):
231 """Adds code or a function call""" 233 code.replace(
' ',
'_')
234 if not code.endswith(
')'):
241 """Display a message in the robot controller screen (teach pendant)""" 245 self.
addlog(
'Show message on teach pendant not implemented (%s)' % message)
249 """Add a program line""" 250 self.
PROG = self.
PROG + newline +
'\n' 253 """Add a log message""" 254 self.
LOG = self.
LOG + newline +
'\n' 259 [x,y,z,r,p,w] = xyzrpw
269 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]])
272 """Test the post with a basic program""" 276 robot.ProgStart(
"Program")
277 robot.RunMessage(
"Program generated by RoboDK using a custom post processor",
True)
278 robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
279 robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
280 robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
281 robot.MoveL(
Pose([200, 250, 15, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
282 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])
285 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
286 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
287 robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
289 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
290 robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
291 robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
292 robot.ProgFinish(
"Program")
295 if len(robot.LOG) > 0:
296 mbox(
'Program generation LOG:\n\n' + robot.LOG)
298 input(
"Press Enter to close...")
300 if __name__ ==
"__main__":
301 """Function to call when the module is executed by itself: test""" def ProgFinish(self, progname)
def RunMessage(self, message, iscomment=False)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def addlog(self, newline)
def Deceleration(self, decel_ptg)
def addline(self, newline)
def Speed(self, speed_mms)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def MoveL(self, pose, joints, conf_RLF=None)
def setDO(self, io_var, io_value)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def setZoneData(self, zone_mm)
def MoveJ(self, pose, joints, conf_RLF=None)
def setAccelerationJoints(self, accel_degss)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def RunCode(self, code, is_function_call=False)
def setFrame(self, pose, frame_id=None, frame_name=None)
def setSpeedJoints(self, speed_degs)
def Acceleration(self, accel_ptg)
def ProgStart(self, progname)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def setTool(self, pose, tool_id=None, tool_name=None)