# This file is a sample POST PROCESSOR script for RoboDK to generate programs for a Staubli robot using VAL3 programming language # # To edit/test this POST PROCESSOR script file: # Select "Program"->"Add/Edit Post Processor", then select your post or create a new one. # You can edit this file using any text editor or Python editor. Using a Python editor allows to quickly evaluate a sample program at the end of this file. # Python should be automatically installed with RoboDK # # You can also edit the POST PROCESSOR manually: # 1- Open the *.py file with Python IDLE (right click -> Edit with IDLE) # 2- Make the necessary changes # 3- Run the file to open Python Shell: Run -> Run module (F5 by default) # 4- The "test_post()" function is called automatically # Alternatively, you can edit this file using a Notepad and run it with Python # # To use a POST PROCESSOR file you must place the *.py file in "C:/RoboDK/Posts/" # To select one POST PROCESSOR for your robot in RoboDK you must follow these steps: # 1- Open the robot panel (double click a robot) # 2- Select "Parameters" # 3- Select "Unlock advanced options" # 4- Select your post as the file name in the "Robot brand" box # # To delete an existing POST PROCESSOR scritp, simply delete this file (.py file) # ---------------------------------------------------- # Import RoboDK tools from robodk import * # ---------------------------------------------------- def pose_2_str(pose,joints=None): """Converts a pose target to a string""" [x,y,z,w,p,r] = Pose_2_Adept(pose) return ('{%.3f,%.3f,%.3f,%.3f,%.3f,%.3f}' % (x,y,z,w,p,r)) def joints_2_str(angles): """Contverts a joint target to a string""" return '{%s}' % (','.join(format(ji, ".5f") for ji in angles)) # ---------------------------------------------------- # Object class that handles the robot instructions/syntax class RobotPost(object): """Robot post object""" PROG_EXT = 'val3' # set the program extension # other variables ROBOT_POST = '' ROBOT_NAME = '' PROG = '' LOG = '' nAxes = 6 TAB = '' REF_FRAME = None def __init__(self, robotpost=None, robotname=None, robot_axes = 6): self.ROBOT_POST = robotpost self.ROBOT_NAME = robotname self.PROG = '' self.LOG = '' self.nAxes = robot_axes def ProgStart(self, progname): self.addline('Begin') self.TAB = ' ' def ProgFinish(self, progname): self.TAB = '' self.addline('end') def ProgSave(self, folder, progname, ask_user = False, show_result = False): progname = progname + '.' + self.PROG_EXT if ask_user or not DirExists(folder): filesave = getSaveFile(folder, progname, 'Save program as...') if filesave is not None: filesave = filesave.name else: return else: filesave = folder + '/' + progname fid = open(filesave, "w") fid.write(self.PROG) fid.close() # open file with default application if show_result: import os os.startfile(filesave) if len(self.LOG) > 0: mbox('Program generation LOG:\n\n' + self.LOG) def MoveJ(self, pose, joints): """Add a joint movement""" self.addline('movej(%s,tTool,mNomSpeed)' % joints_2_str(joints)) def MoveL(self, pose, joints): """Add a linear movement""" self.addline('movel(%s,tTool,mNomSpeed)' % pose_2_str(pose,joints)) def MoveC(self, pose1, joints1, pose2, joints2): """Add a circular movement""" self.addline('movec(%s,%s,tTool,mNomSpeed)' % (pose_2_str(pose2,joints2), pose_2_str(pose1,joints1))) def setFrame(self, pose): """Change the robot reference frame""" self.addline('tFrame=%s' % pose_2_str(pose)) def setTool(self, pose): """Change the robot TCP""" self.addline('tTool=%s' % pose_2_str(pose)) def Pause(self, time_ms): """Pause the robot program""" if time_ms <= 0: self.addline('pause()') else: self.addline('waitEndMove()') self.addline('delay(%.3f)' % (time_ms*0.001)) def setSpeed(self, speed_mms): """Changes the robot speed (in mm/s)""" self.addlog('setSpeed not defined') def setAcceleration(self, accel_mmss): """Changes the robot acceleration (in mm/s2)""" self.addlog('setAcceleration not defined') def setSpeedJoints(self, speed_degs): """Changes the robot joint speed (in deg/s)""" self.addlog('setSpeedJoints not defined') def setAccelerationJoints(self, accel_degss): """Changes the robot joint acceleration (in deg/s2)""" self.addlog('setAccelerationJoints not defined') def setZoneData(self, zone_mm): """Changes the zone data approach (makes the movement more smooth)""" self.addlog('setZoneData not defined (%.1f mm)' % zone_mm) def RunCode(self, code, is_function_call = False): """Adds code or a function call""" if is_function_call: code.replace(' ','_') if code.find('(') < 0: code = code + '()' self.addline('call %s' % code) else: self.addline(code) def RunMessage(self, message, iscomment = False): """Add a joint movement""" if iscomment: self.addline('; ' + message) else: self.addline('display("' + message + '")') # ------------------ private ---------------------- def addline(self, newline): """Add a program line""" self.PROG = self.PROG + self.TAB + newline + '\n' def addlog(self, newline): """Add a log message""" self.LOG = self.LOG + newline + '\n' # ------------------------------------------------- # ------------ For testing purposes --------------- def Pose(xyzrpw): [x,y,z,r,p,w] = xyzrpw a = r*math.pi/180 b = p*math.pi/180 c = w*math.pi/180 ca = math.cos(a) sa = math.sin(a) cb = math.cos(b) sb = math.sin(b) cc = math.cos(c) sc = math.sin(c) 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]]) def test_post(): """Test the post with a basic program""" robot = RobotPost('Staubli_custom', 'Generic Staubli robot') robot.ProgStart("Program") robot.RunMessage("Program generated by RoboDK", True) robot.setFrame(Pose([807.766544, -963.699898, 41.478944, 0, 0, 0])) robot.setTool(Pose([62.5, -108.253175, 100, -60, 90, 0])) robot.MoveJ(Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] ) robot.MoveL(Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] ) robot.MoveL(Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] ) robot.RunMessage("Setting air valve 1 on") robot.RunCode("TCP_On", True) robot.Pause(1000) robot.MoveL(Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] ) robot.MoveL(Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] ) robot.MoveL(Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] ) robot.RunMessage("Setting air valve off") robot.RunCode("TCP_Off(55)", True) robot.Pause(1000) robot.MoveL(Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] ) robot.MoveL(Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] ) robot.MoveL(Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] ) robot.ProgFinish("Program") # robot.ProgSave(".","Program",True) print(robot.PROG) if len(robot.LOG) > 0: mbox('Program generation LOG:\n\n' + robot.LOG) input("Press Enter to close...") if __name__ == "__main__": """Function to call when the module is executed by itself: test""" test_post()