def main(): # start the server server = Server(server_address, server_port) server.start() server.client_ips.update({"UR": ur_ip}) # create client wrappers, that wrap the underlying communication to the sockets gh = ClientWrapper("GH") ur = ClientWrapper("UR") # wait for the clients to be connected gh.wait_for_connected() ur.wait_for_connected() # now enter fabrication loop while True: # and ur and gh connected # let gh control if we should continue continue_fabrication = gh.wait_for_int( ) #1 client.send(MSG_INT, int(continue_fabrication)) print("1: continue_fabrication: %i" % continue_fabrication) print("start fabrication") ur.send_command_digital_out(0, True) # Turn ON """ if not continue_fabrication: break """ tool_string = gh.wait_for_float_list( ) #2 client.send(MSG_FLOAT_LIST,tool_string_axis) print("2: set tool TCP") ur.send_command_tcp(tool_string) in_pose_cmd = gh.wait_for_float_list( ) #3 client.send(MSG_FLOAT_LIST, safe_in_pose_cmd) print("3: safe pose") x, y, z, ax, ay, az, speed, acc = in_pose_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, a=acc) ur.send_command_wait(0.5) waiting_times = gh.wait_for_float_list( ) #3 client.send(MSG_FLOAT_LIST, safe_in_pose_cmd) print("NEW: waiting_times") len_command = gh.wait_for_int() #4 client.send(MSG_INT, len_command) print("4: len command list") commands_flattened = gh.wait_for_float_list( ) #5 client.send(MSG_FLOAT_LIST, commands_flattened) print("5: command list") # the commands are formatted according to the sent length commands = format_commands(commands_flattened, len_command) print("We received %i commands." % len(commands)) # placing path for i in range(0, len(commands), 1): placing_cmd = commands[i] wait = waiting_times[i] print(wait) if i == 0: x, y, z, ax, ay, az, speed, radius = placing_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius) else: # turn sand on ur.send_command_digital_out(0, False) # Turn ON extruder # wait ur.send_command_wait(1.0) # turn sand off ur.send_command_digital_out(0, True) # Turn OFF extruder # wait again ur.send_command_wait(2.0) # move to next point x, y, z, ax, ay, az, speed, radius = placing_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius) #ur.send_command_movel([x, y, z, ax, ay, az], r=radius, t=2) ur.send_command_digital_out(0, True) # Turn OFF extruder ur.send_command_wait(0.5) ur.wait_for_ready() ### Out Pose ### safe_out_pose_cmd = gh.wait_for_float_list( ) #6 client.send(MSG_FLOAT_LIST, safe_out_pose_cmd) print("6: safe out pose") x, y, z, ax, ay, az, speed, acc = safe_out_pose_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, a=acc) ur.send_command_wait(0.5) ur.wait_for_ready() #ur.wait_for_ready() print("============================================================") ur.quit() gh.quit() server.close() print("Please press a key to terminate the program.") junk = sys.stdin.readline() print("Done.")
def main(): # start the server server = Server(server_address, server_port) server.start() server.client_ips.update({"UR": ur_ip}) # create client wrappers, that wrap the underlying communication to the sockets gh = ClientWrapper("GH") ur = ClientWrapper("UR") # wait for the clients to be connected gh.wait_for_connected() ur.wait_for_connected() # now enter fabrication loop while True: # and ur and gh connected # let gh control if we should continue continue_fabrication = gh.wait_for_int( ) #1 client.send(MSG_INT, int(continue_fabrication)) print("1: continue_fabrication: %i" % continue_fabrication) print("start fabrication") if not continue_fabrication: break tool_string = gh.wait_for_float_list( ) #2 client.send(MSG_FLOAT_LIST,tool_string_axis) print("2: set string tool TCP") ur.send_command_tcp(tool_string) in_pose_cmd = gh.wait_for_float_list( ) #3 client.send(MSG_FLOAT_LIST, safe_in_pose_cmd) print("3: safe string pose") x, y, z, ax, ay, az, speed, acc = in_pose_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, a=acc) ur.send_command_wait(0.5) len_command = gh.wait_for_int() #4 client.send(MSG_INT, len_command) print("4: len command list") commands_flattened = gh.wait_for_float_list( ) #5 client.send(MSG_FLOAT_LIST, commands_flattened) print("5: command list") # the commands are formatted according to the sent length commands = format_commands(commands_flattened, len_command) print("We received %i commands." % len(commands)) # placing path for i in range(0, len(commands), 1): placing_cmd = commands[i] if i == 0: x, y, z, ax, ay, az, speed, radius = placing_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, a=acc) if i == 1: ### Turn on string tool ### ur.send_command_digital_out(0, False) x, y, z, ax, ay, az, speed, radius = placing_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius) else: ### Move smoothly to next plane ### x, y, z, ax, ay, az, speed, radius = placing_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius) ur.send_command_digital_out(0, True) # turn off string tool ur.send_command_wait(0.5) ur.wait_for_ready() ### Out Pose ### safe_out_pose_cmd = gh.wait_for_float_list( ) #6 client.send(MSG_FLOAT_LIST, safe_out_pose_cmd) print("6: safe out pose") x, y, z, ax, ay, az, speed, acc = safe_out_pose_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, a=acc) ur.send_command_wait(0.5) ur.wait_for_ready() #ur.wait_for_ready() ### Gravel Placment ### tool_gravel = gh.wait_for_float_list( ) #7 client.send(MSG_FLOAT_LIST,tool_gravel_axis) ur.send_command_tcp(tool_gravel) ur.wait_for_ready() print("7: Set TCP Done") safe_in_pose_gravel_cmd = gh.wait_for_float_list( ) #8 client.send(MSG_FLOAT_LIST, safe_in_pose_gravel) x, y, z, ax, ay, az, speed, acc = safe_in_pose_gravel_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, a=acc) ur.send_command_wait(0.5) ur.wait_for_ready() print("8: Safe gravel pose Done") pose_gravel_cmd = gh.wait_for_float_list( ) #9 client.send(MSG_FLOAT_LIST, pose_gravel) x, y, z, ax, ay, az, speed, acc = pose_gravel_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, a=acc) ur.send_command_wait(5) ur.wait_for_ready() print("9: gravel pose done") safe_out_pose_gravel_cmd = gh.wait_for_float_list( ) #10 client.send(MSG_FLOAT_LIST, safe_out_pose_gravel) x, y, z, ax, ay, az, speed, acc = safe_out_pose_gravel_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, a=acc) ur.send_command_wait(0.5) ur.wait_for_ready() print("10: Safe out gravel pose Done") print("============================================================") ur.quit() gh.quit() server.close() print("Please press a key to terminate the program.") junk = sys.stdin.readline() print("Done.")
def main(): # start the server server = Server(server_address, server_port) server.start() server.client_ips.update({"UR": ur_ip}) # create client wrappers, that wrap the underlying communication to the sockets gh = ClientWrapper("GH") ur = ClientWrapper("UR") # wait for the clients to be connected gh.wait_for_connected() ur.wait_for_connected() # now enter fabrication loop while True: # and ur and gh connected # let gh control if we should continue continue_fabrication = gh.wait_for_int() #1 client.send(MSG_INT, int(continue_fabrication)) print("1: continue_fabrication: %i" % continue_fabrication) print ("start fabrication") tool_string = gh.wait_for_float_list() #2 client.send(MSG_FLOAT_LIST,tool_string_axis) print("2: set tool TCP") ur.send_command_tcp(tool_string) ### Safe Pose ### safety_pose_cmd = gh.wait_for_float_list() #3 client.send(MSG_FLOAT_LIST, safe_in_pose_cmd) print("3: safe in pose") x, y, z, ax, ay, az, speed, acc = safety_pose_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, a=acc) ur.send_command_wait(1.0) len_command = gh.wait_for_int() #4 client.send(MSG_INT, len_command) print ("4: len command list") commands_flattened = gh.wait_for_float_list() #5 client.send(MSG_FLOAT_LIST, commands_flattened) print ("5: command list") # the commands are formatted according to the sent length commands = format_commands(commands_flattened, len_command) print("We received %i commands." % len(commands)) # ur.wait_for_ready() # print (time.time()) # printing path for i in range(0, len(commands)): printing_cmd = commands[i] x, y, z, ax, ay, az, speed, radius = printing_cmd # print tcp_WCS # joint_angles = ur.get # ur.send_command_movej(joint_angles, v=speed_set, r=radius) # ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius) # ur_frame = Frame([x, y, z], []) ur.wait_for_ready() print (time.time()) ur.wait_for_ready() #ur.wait_for_ready() print("============================================================") ur.quit() gh.quit() server.close() print("Please press a key to terminate the program.") junk = sys.stdin.readline() print("Done.")
def main(): print("hi") # start the server server = Server(server_address, server_port) # print("Server"), server server.start() server.client_ips.update({"UR": ur_ip}) # create client wrappers, that wrap the underlying communication to the sockets gh = ClientWrapper("GH") ur = ClientWrapper("UR") # wait for the clients to be connected gh.wait_for_connected() ur.wait_for_connected() number_of_completed_poses = 0 # now enter fabrication loop while True: # and ur and gh connected # 1. let gh control if we should continue # continue_fabrication = gh.wait_for_int() # print("continue_fabrication: %i" % continue_fabrication) # if not continue_fabrication: # break # 2. set the tool tcp tool_pose = gh.wait_for_float_list( ) # client.send(MSG_FLOAT_LIST, tool_pose) print("2: set tool TCP") ur.send_command_tcp(tool_pose) # 3. receive command length print('3: send length of message') len_command = gh.wait_for_int() print("length", len_command) # 4. receive commands flattened, and format according to the sent length commands_flattened = gh.wait_for_float_list() print("commands", commands_flattened) commands = format_commands(commands_flattened, len_command) print("We received %i commands." % len(commands)) # 5. receive safety commands flattened, and format according to the sent length # savety_commands_flattened = gh.wait_for_float_list() # savety_commands = format_commands(savety_commands_flattened, len_command) # print("savety_commands_flattened: %s" % str(savety_commands_flattened)) for i, cmd in enumerate(commands): # x, y, z, ax, ay, az, acceleration, speed, wait_time = cmd if cmd[0] == 0.0: print((len(cmd) - 1) / 9) for j in range((len(cmd) - 1) / 9): print("inside_loop") ind_s = j + 1 ind_e = j + 1 + 6 pose = cmd[ind_s:ind_e] print("pose", pose) acceleration, speed, wait_time = cmd[ind_e:ind_e + 3] print("speed_data", cmd[ind_e:ind_e + 3]) ##ur.send_command_digital_out(number, True) ur.send_command_movel(pose, a=acceleration, v=speed) ## ur.send_command_digital_out(number, False) ur.wait_for_ready() number_of_completed_poses += 1 else: for j in range((len(cmd) - 4) / 9): if j == cmd[1] or j == cmd[3]: ur.send_command_digital_out(0, False) ur.send_command_digital_out(1, True) elif j == cmd[2]: ur.send_command_digital_out(1, False) ur.send_command_digital_out(0, True) ind_s = j * 9 + 4 ind_e = j * 9 + 4 + 6 pose_joints = cmd[ind_s:ind_e] print("pose_joints", pose_joints) acceleration, speed, wait_time = cmd[ind_e:ind_e + 3] print("speed_data", cmd[ind_e:ind_e + 3]) ##ur.send_command_digital_out(number, True) ur.send_command_movej(pose_joints, a=acceleration, v=speed) ## ur.send_command_digital_out(number, False) # x, y, z, ax, ay, az = cmd[-9:-3] # print("position", cmd[-9:-3]) # acceleration, speed, wait_time = cmd[-3:] # print("speed data", cmd[-3:]) # ur.send_command_movel([x, y, z, ax, ay, az], a=acceleration, v=speed) ur.wait_for_ready() number_of_completed_poses += 1 # current_pose_joint = ur.wait_for_current_pose_joint() # if i == len(commands) - 1: # send savety commands # for cmd in savety_commands: # x, y, z, ax, ay, az, acceleration, speed, wait_time = cmd # ur.send_command_movel([x, y, z, ax, ay, az], a=acceleration, v=speed) # ur.wait_for_ready() # gh.send_float_list(current_pose_joint) # ur.wait_for_ready() # # update time for deposition constantly # deposition_time = gh.wait_for_float_list()[0] # # if the value is not zero, overwrite, otherwise take the list value # if deposition_time == 0: # deposition_time = wait_time # # send cmd to place the material # if i != len(commands) - 1: # send_cmd_place_sand(ur, deposition_time) # check if the routine is paused # pause = gh.wait_for_int() # print("pause: %i" % pause) # if pause: # stop_pause = gh.wait_for_int() print("number of completed robot poses: %i" % number_of_completed_poses) # print("sand_deposition_time: %f" % deposition_time) # ur.wait_for_ready() print("============================================================") """ ur.wait_for_ready() # wait for sensor value digital_in = ur.wait_for_digital_in(number) current_pose_joint = ur.wait_for_current_pose_joint() current_pose_cartesian = ur.get_current_pose_cartesian() # send further to gh gh.send_float_list(digital_in) gh.send_float_list(current_pose_joint) gh.send_float_list(current_pose_cartesian) """ ur.quit() gh.quit() server.close() print("Please press a key to terminate the program.") junk = sys.stdin.readline() print("Done.")
def main(): # start the server server = Server(server_address, server_port) server.start() server.client_ips.update({"UR": ur_ip}) # create client wrappers, that wrap the underlying communication to the sockets gh = ClientWrapper("GH") ur = ClientWrapper("UR") # wait for the clients to be connected gh.wait_for_connected() ur.wait_for_connected() # now enter fabrication loop while True: # and ur and gh connected # let gh control if we should continue continue_fabrication = gh.wait_for_int( ) #1 client.send(MSG_INT, int(continue_fabrication)) print("1: continue_fabrication: %i" % continue_fabrication) print("start fabrication") """ if not continue_fabrication: break """ tool_string = gh.wait_for_float_list( ) #2 client.send(MSG_FLOAT_LIST,tool_string_axis) print("2: set tool TCP") ur.send_command_tcp(tool_string) len_command_picking = gh.wait_for_int( ) #3 client.send(MSG_INT, len_command) print("3: len command list picking") commands_flattened_picking = gh.wait_for_float_list( ) #4 client.send(MSG_FLOAT_LIST, commands_flattened) print("4: command list picking") len_command_placing = gh.wait_for_int( ) #3 client.send(MSG_INT, len_command) print("5: len command list placing") commands_flattened_placing = gh.wait_for_float_list( ) #4 client.send(MSG_FLOAT_LIST, commands_flattened) print("6: command list placing") # the commands are formatted according to the sent length commands_picking = format_commands(commands_flattened_picking, len_command_picking) print("We received %i picking commands." % len(commands_picking)) commands_placing = format_commands(commands_flattened_placing, len_command_placing) print("We received %i placing commands." % len(commands_placing)) # placing path picking_cnt = 0 for i in range(0, len(commands_flattened_placing), 3): ur.send_command_wait(0.3) ur.send_command_digital_out(0, False) ur.send_command_wait(0.3) #above picking placing_cmd = commands_picking[picking_cnt] x, y, z, ax, ay, az, speed, radius = placing_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius) #picking placing_cmd = commands_picking[picking_cnt + 1] x, y, z, ax, ay, az, speed, radius = placing_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius) ur.send_command_wait(1.0) #rotate placing_cmd = commands_picking[picking_cnt + 2] x, y, z, ax, ay, az, speed, radius = placing_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius) ur.send_command_wait(1.0) #above picking placing_cmd = commands_picking[picking_cnt + 3] x, y, z, ax, ay, az, speed, radius = placing_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius) #above placing placing_cmd = commands_placing[i] x, y, z, ax, ay, az, speed, radius = placing_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius) #placing placing_cmd = commands_placing[i + 1] x, y, z, ax, ay, az, speed, radius = placing_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius) ur.send_command_wait(0.3) ur.send_command_digital_out(0, True) ur.send_command_wait(0.3) #above placing placing_cmd = commands_placing[i + 2] x, y, z, ax, ay, az, speed, radius = placing_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius) picking_cnt += 4 ur.send_command_popup() ur.send_command_digital_out(0, True) # Turn ON piston ur.send_command_wait(0.5) ur.wait_for_ready() ### Out Pose ### #safe_out_pose_cmd = gh.wait_for_float_list() #6 client.send(MSG_FLOAT_LIST, safe_out_pose_cmd) #print ("6: safe out pose") #x, y, z, ax, ay, az, speed, acc = safe_out_pose_cmd #ur.send_command_movel([x, y, z, ax, ay, az], v=speed, a=acc) ur.send_command_wait(0.5) ur.wait_for_ready() #ur.wait_for_ready() print("============================================================") ur.quit() gh.quit() server.close() print("Please press a key to terminate the program.") junk = sys.stdin.readline() print("Done.")
def main(): # start the server server = Server(server_address, server_port) server.start() server.client_ips.update({"UR": ur_ip}) # create client wrappers, that wrap the underlying communication to the sockets gh = ClientWrapper("GH") ur = ClientWrapper("UR") # wait for the clients to be connected gh.wait_for_connected() ur.wait_for_connected() # now enter fabrication loop while True: # and ur and gh connected # let gh control if we should continue continue_fabrication = gh.wait_for_int( ) #1 client.send(MSG_INT, int(continue_fabrication)) print("1: continue_fabrication: %i" % continue_fabrication) print("start fabrication") tool_string = gh.wait_for_float_list( ) #2 client.send(MSG_FLOAT_LIST,tool_string_axis) print("2: set tool TCP") ur.send_command_tcp(tool_string) ### Safe Pose ### safety_pose_cmd = gh.wait_for_float_list( ) #3 client.send(MSG_FLOAT_LIST, safe_in_pose_cmd) print("3: safe in pose") x, y, z, ax, ay, az, speed, acc = safety_pose_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, a=acc) ur.send_command_wait(1.0) #turn on air and off motor ur.send_command_digital_out(4, False) ur.send_command_digital_out(5, True) ur.wait_for_ready() ur.send_command_popup(title='hello!', message='Press ok when you are ready!', blocking=True) ur.wait_for_ready() #turn on motor ur.send_command_digital_out(4, True) ur.wait_for_ready() ur.send_command_popup(title='hello!', message='Press ok when you are ready!', blocking=True) ur.wait_for_ready() len_command = gh.wait_for_int() #4 client.send(MSG_INT, len_command) print("4: len command list") commands_flattened = gh.wait_for_float_list( ) #5 client.send(MSG_FLOAT_LIST, commands_flattened) print("5: command list") # the commands are formatted according to the sent length commands = format_commands(commands_flattened, len_command) print("We received %i commands." % len(commands)) # printing path count = 0 for i in range(0, len(commands)): printing_cmd = commands[i] x, y, z, ax, ay, az, speed, radius, extrude_bool = printing_cmd if extrude_bool == 0: count += 1 ur.send_command_digital_out(4, False) ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius) if count > 1: ur.send_command_digital_out(4, True) ur.send_command_wait(0.5) else: count = 0 ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius) for i, cmd in enumerate(commands[:-2]): ur.wait_for_command_executed(i) print("Executed command", i + 1) print(cmd) ### Safe Pose ### safety_pose_cmd = gh.wait_for_float_list( ) #6 client.send(MSG_FLOAT_LIST, safe_out_pose_cmd) print("6: safe out pose") x, y, z, ax, ay, az, speed, acc = safety_pose_cmd ur.send_command_movel([x, y, z, ax, ay, az], v=speed, a=acc) ur.send_command_wait(5.0) # turn off motor and extruder ur.send_command_digital_out(4, False) ur.send_command_wait(0.5) ur.wait_for_ready() #ur.wait_for_ready() print("============================================================") ur.quit() gh.quit() server.close() print("Please press a key to terminate the program.") junk = sys.stdin.readline() print("Done.")