From 69eb9a9f5f8c573e413df21ee32e313c52932706 Mon Sep 17 00:00:00 2001 From: germano laptop Date: Mon, 27 Jan 2025 12:54:07 +0100 Subject: [PATCH] pipe cutter test ok recipe ok need calibration for first cut --- src/ui/test/test.py | 4 +- src/ui/test_pipe_cutter/test_pipe_cutter.py | 115 +++++++++----------- 2 files changed, 52 insertions(+), 67 deletions(-) diff --git a/src/ui/test/test.py b/src/ui/test/test.py index fe9d8f7..3c85aad 100755 --- a/src/ui/test/test.py +++ b/src/ui/test/test.py @@ -362,9 +362,7 @@ class Test(Widget): self.data["recipe"] = model_to_dict(self.recipe) w = self.cycle_available_steps[self.step.step_type] show = None - if self.step.step_type == "pipe_cutter": - if current_w != w : - self.setCentralWidget(w) + if self.step.step_type == "leak_2": self.setCentralWidget(w) # NEED TO PRESHOW UI if hasattr(w, "start"): diff --git a/src/ui/test_pipe_cutter/test_pipe_cutter.py b/src/ui/test_pipe_cutter/test_pipe_cutter.py index 661482a..549f940 100644 --- a/src/ui/test_pipe_cutter/test_pipe_cutter.py +++ b/src/ui/test_pipe_cutter/test_pipe_cutter.py @@ -15,6 +15,8 @@ class Test_Pipe_Cutter(Test_Test): def __init__(self, config, components, recipe=None, run_once=False,reset_on_start=True, enable_override=False, bench_name="generic", step=None,): super().__init__(components=components, recipe=recipe, step=step, run_once=run_once,reset_on_start=reset_on_start, enable_override=enable_override,) + self.current_status = None + self.previous_status = None self.end_cut = None self.config = config self.bench_name = bench_name @@ -39,77 +41,14 @@ class Test_Pipe_Cutter(Test_Test): if show is False: return show - # Define status messages - status_actions = { - 102: "ready for operation", - 103: "running", - 105: "emergency", - 100: "need to reset" - } - - # Initialize variables to track current and previous status - previous_status = None self.current_status = None self.get_connection = self.components["pipe_cutter"].out.connect(self.get) self.components["pipe_cutter"].resume() - - # Continuously monitor and handle pipe cutter statuses - while True: - self.current_status = self.components["pipe_cutter"].read(register=766) - print(self.current_status) - - # Status: 102 (ready for operation) - if self.current_status == 102: - if previous_status == 103: - #print("Transition detected: 103 -> 102. Stopping the cutting process.") - self.stop_cutting() - - # Start cutting if machine is ready - self.start_cutting(recipe=recipe, step=step) - - # Status: 103 (running) - elif self.current_status == 103: - #print(f"Status {self.current_status}: The pipe cutter is running. Monitoring the system.") - self.display_text(text="TAGLIO CORRUGATO IN CORSO", bg_color="green") - - # Status: 105 (emergency) - elif self.current_status == 105: - #print(f"Status {self.current_status}: Emergency detected! Resetting the system.") - try: - self.display_text(text="EMERGENZA INTERVENUTA RIPETERE IL TEST", bg_color="red") - self.start_cutting() - except Exception as e: - logger.error(f"Failed to handle the emergency state: {e}") - - # Status: 100 (need to reset) - elif self.current_status == 100: - #print(f"Status {self.current_status}: The system requires resetting. Performing reset.") - try: - self.display_text(text="RESET IN CORSO", bg_color="yellow") - self.reset_machine() - self.display_text(text="TAGLIO CORRUGATO IN CORSO", bg_color="green") - self.start_cutting(recipe=recipe, step=step) - - - except Exception as e: - logger.error(f"Failed to reset the system: {e}") - - # Unknown status - else: - # print(f"Unknown status {self.current_status}. Skipping operation.") - logger.warning(f"Unknown pipe cutter status {self.current_status} detected.") - - previous_status = self.current_status - if step is not None and self.end_cut: - print("Cutting process complete. Exiting monitoring loop.") - break - - self.stop() return show - def start_cutting(self, recipe=None, step=None): + def start_cutting(self): """ Perform the pipe cutting process when in the 'ready for operation' state (102). """ @@ -165,6 +104,54 @@ class Test_Pipe_Cutter(Test_Test): super().get(None, override=override) return data = data[-1] + + self.previus_status = None + self.current_status = self.components["pipe_cutter"].read(register=766) + print(self.current_status) + + # Status: 102 (ready for operation) + if self.current_status == 102: + if self.previous_status == 103: + #print("Transition detected: 103 -> 102. Stopping the cutting process.") + self.stop_cutting() + + # Start cutting if machine is ready + self.start_cutting() + + # Status: 103 (running) + elif self.current_status == 103: + #print(f"Status {self.current_status}: The pipe cutter is running. Monitoring the system.") + self.display_text(text="TAGLIO CORRUGATO IN CORSO", bg_color="green") + + # Status: 105 (emergency) + elif self.current_status == 105: + #print(f"Status {self.current_status}: Emergency detected! Resetting the system.") + try: + self.display_text(text="EMERGENZA INTERVENUTA RIPETERE IL TEST", bg_color="red") + self.end_cut=False + except Exception as e: + logger.error(f"Failed to handle the emergency state: {e}") + + # Status: 100 (need to reset) + elif self.current_status == 100: + #print(f"Status {self.current_status}: The system requires resetting. Performing reset.") + try: + self.display_text(text="RESET IN CORSO", bg_color="yellow") + self.reset_machine() + self.display_text(text="TAGLIO CORRUGATO IN CORSO", bg_color="green") + self.start_cutting() + + + except Exception as e: + logger.error(f"Failed to reset the system: {e}") + + # Unknown status + else: + # print(f"Unknown status {self.current_status}. Skipping operation.") + logger.warning(f"Unknown pipe cutter status {self.current_status} detected.") + + self.previous_status = self.current_status + if self.end_cut is True: ok = True else: