def robot_script(): sel_pt = rs.GetPoint("select point") #1) Use 6 values pose1 = urs.pose(sel_pt.X, sel_pt.Y, sel_pt.Z, 0, 0, 0) #2) Use two tuples - vector and orientation pose2_pos = (sel_pt.X, sel_pt.Y, sel_pt.Z + 0.15) pose2 = urs.pose_by_vectors(pose2_pos, (0, 0, 0)) #3) Use a Rhino plane plane3 = rg.Plane(sel_pt, rg.Vector3d.ZAxis) pose3 = urs.pose_by_plane(plane3) #4) Use an origin and 2 vectors - same as a plane pose4_pos = (sel_pt.X, sel_pt.Y - 0.15, sel_pt.Z + 0.15) pose4 = urs.pose_by_origin_axis(pose4_pos, (1, 0, 0), (0, 1, 0)) #5) Use a listened pose pose5_vals = comm.listen(ip)['tool_pose'] pose5 = urs.pose(*pose5_vals) #Create a list of statements commands = [] poses = (pose1, pose2, pose3, pose4) #Go through all poses for i in range(len(poses)): #Add a comment commands.append(urs.comment("Movement {}".format(i))) #Add a command commands.append(urs.movel(poses[i])) # return to pose 5 via movej commands.append(urs.movej(pose5)) #3) Create a program using commands as argument my_program = urs.create_function("main", commands) return my_program
""" Sample 1 : A barebones script Loading : 1)Referencing folder or 2)importing ur.dll """ #1) Import import urscript as urs import comm #2) Create a command command = urs.popup("hi students", "title is title") #3) Create a program my_program = urs.create_function('main', [command]) print my_program #4) Send the program comm.send_script(my_program, "192.168.10.13")
functions (in, optional) [Generic Data] - Optional. Custom UR Script functions to include in the program Returns: out [Text] - The execution information, as output and error streams a [Generic Data] - Script variable Python """ import comm import urscript as ur from Grasshopper.Kernel import GH_RuntimeMessageLevel as gh_msg error_inputs = [] if not send: error_inputs.append('send') if not id: error_inputs.append('id') if not commands: error_inputs.append('commands') if not error_inputs: ip = '192.168.10.%d' % (10 * int(id) + 3) script = "" statements = statements if hasattr(commands, '__iter__') else list(commands) statements.insert(0, ur.popup('Running script')) if functions and not None in functions: script += ur.create_function('main', statements, functions) else: script += ur.create_function('main', statements) a = script if _send: comm.send_script(script, ip) else: error_message = 'Failed to collect data for {0} required input(s): {1}'.format( len(error_inputs), ','.join(error_inputs)) ghenv.Component.AddRuntimeMessage(gh_msg.Warning, error_message)
def place_script(target): place_pose = ur.pose(*target), place = ur.statements(ur.comment('placing now'), ur.action(place_pose, 1, False)) return ur.create_function('place', place)
def pick_script(target): pick_pose = ur.pose(*target) pick = ur.statements(ur.comment('picking now'), ur.action(pick_pose, 1, True)) return ur.create_function('pick', pick)
pick_pose = ur.pose(*target) pick = ur.statements(ur.comment('picking now'), ur.action(pick_pose, 1, True)) return ur.create_function('pick', pick) # Return a place function def place_script(target): place_pose = ur.pose(*target), place = ur.statements(ur.comment('placing now'), ur.action(place_pose, 1, False)) return ur.create_function('place', place) # Listen to robot safety = comm.listen(ip)['actual_joints_pos'] # Create body of main program main_statements = ur.statements(ur.popup("starting now"), ur.movej(safety), ur.custom_function('pick'), ur.movej(safety), ur.custom_function("place"), ur.movej(safety)) # Create pick and place functions pick_function = pick_script(pick_target) place_function = place_script(place_target) main_script = ur.create_function("main", main_statements, [pick_script(), place_script()]) print main_script #comm.send_script(main_script,ip)