diff --git a/cablesTF-1LF-006-RS5/part-hires.png b/cablesTF-1LF-006-RS5/part-hires.png deleted file mode 100644 index e3b458b..0000000 Binary files a/cablesTF-1LF-006-RS5/part-hires.png and /dev/null differ diff --git a/fileserver.py b/fileserver.py index 4caf16c..9e222b4 100644 --- a/fileserver.py +++ b/fileserver.py @@ -12,5 +12,5 @@ def run_server(port, directory): # Create the HTTP server handler = http.server.SimpleHTTPRequestHandler with socketserver.TCPServer(("", port), handler) as httpd: - print(f"Serving at port {port}") + print(f"Serving cable images & files at port {port}") httpd.serve_forever() diff --git a/read_datasheet.py b/read_datasheet.py index 83a3e12..53d3d30 100755 --- a/read_datasheet.py +++ b/read_datasheet.py @@ -68,20 +68,23 @@ def find_file_noext(directory, prefix="part-hires"): #print(directory, matching_files) return matching_files -def rotate_and_crop_image(path, image_name): +def rotate_and_crop_image(path, image_name, force_rotate=False): # Open the image file image_path = path + "/" + image_name with Image.open(image_path) as img: # Check if the image is wider than it is tall - if img.width > img.height * 1.2: + if force_rotate or img.width > img.height * 1.2: # Rotate the image by 90 degrees counter-clockwise img = img.rotate(90, expand=True) # Determine the size of the square (the length of the shorter side of the image) square_size = min(img.width, img.height) - - # Crop the image to a square from the top - img_cropped = img.crop((0, 0, square_size, square_size)) + if img.height < img.width: + offset = (img.width - img.height)/2 + img_cropped = img.crop((offset, 0, square_size+offset, square_size)) + else: + # Crop the image to a square from the top + img_cropped = img.crop((0, 0, square_size, square_size)) # Save or display the image img_cropped.save(path + "/" + "thumbnail-" + image_name) # Save the cropped image @@ -184,10 +187,10 @@ def parse(filename, output_dir, partnum, dstype, weburl): count += 1 if os.path.exists(output_dir + "/found_part_hires"): - rotate_and_crop_image(output_dir, find_file_noext(output_dir, prefix="part-hires")[0]) + rotate_and_crop_image(output_dir, find_file_noext(output_dir, prefix="part-hires")[0], force_rotate=(dstype == "Alphawire")) img = weburl + find_file_noext(output_dir, prefix="thumbnail-part-hires")[0] elif len(find_file_noext(output_dir, prefix="part")) > 0: - rotate_and_crop_image(output_dir, find_file_noext(output_dir, prefix="part")[0]) + rotate_and_crop_image(output_dir, find_file_noext(output_dir, prefix="part")[0], force_rotate=(dstype == "Alphawire")) img = weburl + find_file_noext(output_dir, prefix="thumbnail-part")[0] else: img = None diff --git a/run.py b/run.py index 1066aaa..7865fdd 100755 --- a/run.py +++ b/run.py @@ -67,6 +67,8 @@ ring_animation = None led_set_mode = None sensors = [0,0,0,0] websocket_process = None +arm_updates = Queue() +animation_wait = False def arm_start_callback(res): fprint("Arm action complete.") @@ -310,9 +312,10 @@ def setup_server(pool): global to_server_queue global from_server_queue global websocket_process + global arm_updates - arm = Rob(config) + arm = Rob(config, arm_updates) if real: pool.apply_async(ur5_control.powerup_arm, (arm,), callback=arm_start_callback, error_callback=handle_error) else: @@ -443,6 +446,9 @@ def mainloop_server(pool): global cable_list_state global scan_value global oldmode + global arm_updates + global animation_wait + if mode != oldmode: print(" ***** Running mode:", mode, "***** ") oldmode = mode @@ -454,10 +460,16 @@ def mainloop_server(pool): # do every loop! if ring_animation is not None and ledsys.mode != "idle" and real: + if not animation_wait and not arm_updates.empty(): + arm_updates.get() ledsys.mainloop(None, ring_animation) elif ring_animation is not None and real: - ledsys.mainloop(led_set_mode, ring_animation) - led_set_mode = None + if animation_wait: + if not arm_updates.empty(): + animation_wait = False + val = arm_updates.get() + ledsys.mainloop(led_set_mode, ring_animation) + led_set_mode = None else: pass #fprint("Not triggering LED loop: no ring animation") @@ -475,6 +487,7 @@ def mainloop_server(pool): fprint("Getting cable index " + str(counter) + " and scanning...") arm_state = "GET" ring_animation = counter + animation_wait=True led_set_mode = "GrabA" #ur5_control.to_camera(arm, counter) #arm_ready = True diff --git a/ur5_control.py b/ur5_control.py index 6c43e36..4014887 100755 --- a/ur5_control.py +++ b/ur5_control.py @@ -20,8 +20,8 @@ class Rob(): robot = None #offset_x, offset_y, offset_z = (0, 0, 0.14) # Tool offset # - pos_updates = Queue() - def __init__(self, config): + + def __init__(self, config, pos_queue=Queue()): self.config = config armc = config["arm"] self.ip = armc["ip"] @@ -33,6 +33,7 @@ class Rob(): self.limb2 = limbs["limb2"] self.limb3 = limbs["limb3"] self.limb_wrist = limbs["limb_wrist"] + self.pos_updates = pos_queue #self.init_arm() def ping(host):