50 """Prints a pose target""" 52 return (
'%.3f,%.3f,%.3f,%.3f,%.3f' % (x,y,z,p,w))
55 """Prints a joint target""" 57 for i
in range(len(angles)):
60 str = str + (
'%.6f,' % (angles[i]))
67 """Robot post object""" 81 def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs):
95 def ProgSave(self, folder, progname, ask_user=False, show_result=False):
96 progname = progname +
'.' + self.
PROG_EXT 98 filesave =
getSaveFile(folder, progname,
'Save program as...')
99 if filesave
is not None:
100 filesave = filesave.name
104 filesave = folder +
'/' + progname
105 fid = open(filesave,
"w")
108 print(
'SAVED: %s\n' % filesave)
113 if type(show_result)
is str:
116 p = subprocess.Popen([show_result, filesave])
117 elif type(show_result)
is list:
119 p = subprocess.Popen(show_result + [filesave])
123 os.startfile(filesave)
125 if len(self.
LOG) > 0:
126 mbox(
'Program generation LOG:\n\n' + self.
LOG)
129 """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". 130 The connection parameters must be provided in the robot connection menu of RoboDK""" 133 def MoveJ(self, pose, joints, conf_RLF=None):
134 """Add a joint movement""" 138 def MoveL(self, pose, joints, conf_RLF=None):
139 """Add a linear movement""" 143 def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None):
144 """Add a circular movement""" 145 self.
addlog(
'Circular move not possible')
147 def setFrame(self, pose, frame_id=None, frame_name=None):
148 """Change the robot reference frame""" 152 def setTool(self, pose, tool_id=None, tool_name=None):
153 """Change the robot TCP""" 154 self.
addline(
'TL %.0f' % pose.Pos()[2])
157 """Pause the robot program""" 161 self.
addline(
'TI %.0f' % (time_ms*0.01))
164 """Changes the robot speed (in mm/s)""" 166 speed_percent = min(speed_mms*9/5000, 9)
167 self.
addline(
'SP %.0f' % speed_percent)
170 """Changes the robot acceleration (in mm/s2)""" 171 self.
addlog(
'setAcceleration not defined')
174 """Changes the robot joint speed (in deg/s)""" 175 self.
addlog(
'setSpeedJoints not defined')
178 """Changes the robot joint acceleration (in deg/s2)""" 179 self.
addlog(
'setAccelerationJoints not defined')
182 """Changes the smoothing radius (aka CNT, APO or zone data) to make the movement smoother""" 183 self.
addlog(
'Rounding not possible')
186 """Sets a variable (digital output) to a given value""" 187 if type(io_var) != str:
188 io_var =
'OUT(%s)' % str(io_var)
189 if type(io_value) != str:
196 self.
addline(
'%s=%s' % (io_var, io_value))
198 def waitDI(self, io_var, io_value, timeout_ms=-1):
199 """Waits for a variable (digital input) io_var to attain a given value io_value. Optionally, a timeout can be provided.""" 200 if type(io_var) != str:
201 io_var =
'IN(%s)' % str(io_var)
202 if type(io_value) != str:
210 self.
addline(
'Wait %s=%s' % (io_var, io_value))
212 self.
addline(
'Wait %s=%s Timeout=%.1f' % (io_var, io_value, timeout_ms))
214 def RunCode(self, code, is_function_call = False):
215 """Adds code or a function call""" 217 code.replace(
' ',
'_')
223 """Display a message in the robot controller screen (teach pendant)""" 227 self.
addlog(
'Show message on teach pendant not implemented (%s)' % message)
231 """Add a program line""" 232 self.
PROG = self.
PROG + newline +
'\n' 235 """Add a log message""" 236 self.
LOG = self.
LOG + newline +
'\n' 241 [x,y,z,r,p,w] = xyzrpw
251 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]])
254 """Test the post with a basic program""" 258 robot.ProgStart(
"Program")
259 robot.RunMessage(
"Program generated by RoboDK using a custom post processor",
True)
260 robot.setFrame(
Pose([807.766544, -963.699898, 41.478944, 0, 0, 0]))
261 robot.setTool(
Pose([62.5, -108.253175, 100, -60, 90, 0]))
262 robot.MoveJ(
Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
263 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
264 robot.MoveL(
Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] )
265 robot.RunMessage(
"Setting air valve 1 on")
266 robot.RunCode(
"TCP_On",
True)
268 robot.MoveL(
Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] )
269 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
270 robot.MoveL(
Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] )
271 robot.RunMessage(
"Setting air valve off")
272 robot.RunCode(
"TCP_Off",
True)
274 robot.MoveL(
Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] )
275 robot.MoveL(
Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] )
276 robot.MoveL(
Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] )
277 robot.MoveJ(
None, [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] )
278 robot.ProgFinish(
"Program")
281 if len(robot.LOG) > 0:
282 mbox(
'Program generation LOG:\n\n' + robot.LOG)
284 input(
"Press Enter to close...")
286 if __name__ ==
"__main__":
287 """Function to call when the module is executed by itself: test"""
def ProgStart(self, progname)
def __init__(self, robotpost=None, robotname=None, robot_axes=6, kwargs)
def waitDI(self, io_var, io_value, timeout_ms=-1)
def setZoneData(self, zone_mm)
def ProgFinish(self, progname)
def setSpeed(self, speed_mms)
def RunMessage(self, message, iscomment=False)
def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None)
def MoveJ(self, pose, joints, conf_RLF=None)
def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass)
def setTool(self, pose, tool_id=None, tool_name=None)
def ProgSave(self, folder, progname, ask_user=False, show_result=False)
def pose_2_str(pose, ref_frame)
def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass)
def RunCode(self, code, is_function_call=False)
def setFrame(self, pose, frame_id=None, frame_name=None)
def setAcceleration(self, accel_mmss)
def addline(self, newline)
def mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)
def setDO(self, io_var, io_value)
def setAccelerationJoints(self, accel_degss)
def MoveL(self, pose, joints, conf_RLF=None)
def addlog(self, newline)
def getSaveFile(strdir='C:\\', strfile='file.txt', strtitle='Save file as ...')
def setSpeedJoints(self, speed_degs)