st-ten-1/src/ui/test_pipe_cutter/test_pipe_cutter.py

88 lines
3.4 KiB
Python
Raw Normal View History

2025-01-17 14:14:28 +00:00
from PyQt5.QtGui import QMovie
import logging
from ui.test_test import Test_Test
from components import PipeCutterComponent
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class Test_Pipe_Cutter(Test_Test):
"""
A class to manage and operate a pipe cutter machine in a test environment.
"""
2025-01-21 09:51:06 +00:00
def __init__(self, config, components, recipe=None, run_once=False,reset_on_start=False, enable_override=False, bench_name="generic", step=None,):
super().__init__(components=components, recipe=recipe, step=None, run_once=run_once,reset_on_start=reset_on_start, enable_override=enable_override,)
2025-01-21 14:44:47 +00:00
self.config = config
2025-01-17 14:14:28 +00:00
self.bench_name = bench_name
2025-01-21 14:44:47 +00:00
2025-01-17 14:14:28 +00:00
self.current_cut_length = 0.0
self.max_cut_length = config.get("max_cut_length", 10.0)
self.movie = QMovie(config.get("config/instruction_images/st-ten-10/pipe.gif ")) # Animation Path
self.current_status = None
def start(self, recipe=None, step=None, pieces=None):
2025-01-21 14:44:47 +00:00
print(self.config)
self.components["pipe_cutter"].resume()
2025-01-17 14:14:28 +00:00
if step is not None :
self.start_cutting()
self.display_cutting_animation(True)
self.stop_cutting()
def start_cutting(self,recipe=None,step=None):
"""
Start the pipe cutting process and activate the pipe cutter component.
"""
2025-01-21 14:44:47 +00:00
self.current_status = self.components["pipe_cutter"]._get()
2025-01-17 14:14:28 +00:00
if self.current_status == 102 : # ready for operation
try:
self.reset_machine()
2025-01-21 14:44:47 +00:00
self.components["pipe_cutter"].write_total_length(self.recipe.spec.get("length", None))
self.components["pipe_cutter"].write_od_of_pipe(self.recipe.spec.get("diameter", None))
self.components["pipe_cutter"].write_bit_with_delay(600,0,100)
2025-01-17 14:14:28 +00:00
except Exception as e:
logger.error(f"Failed to start the pipe cutting process: {e}")
else:
try:
2025-01-21 14:44:47 +00:00
self.components["pipe_cutter"].write_bit_with_delay(600, 1, 100) # resetting
2025-01-17 14:14:28 +00:00
except Exception as e:
logger.error(f"Failed to reset the pipe cutting process: {e}")
def stop_cutting(self):
"""
Stop the pipe cutting process and deactivate the pipe cutter component.
"""
try:
2025-01-21 14:44:47 +00:00
self.current_status = self.components["pipe_cutter"]._get()
2025-01-17 14:14:28 +00:00
if self.current_status in(106,107):
2025-01-21 14:44:47 +00:00
self.components["pipe_cutter"].write_bit_with_delay(600, 2, 100)
2025-01-17 14:14:28 +00:00
self.reset_machine()
except Exception as e:
logger.error(f"Failed to stop the pipe cutting process: {e}")
def reset_machine(self):
"""
Reset the pipe cutter machine to its initial state.
"""
try:
2025-01-21 14:44:47 +00:00
self.components["pipe_cutter"].write_bit_with_delay(600, 1, 100)
2025-01-17 14:14:28 +00:00
except Exception as e:
logger.error(f"Failed to reset the pipe cutter machine: {e}")
def display_cutting_animation(self, show: bool):
"""
Show or hide the cutting animation GIF.
Args:
show (bool): Whether to display or stop the animation.
"""
if show:
self.pipe_gif.setVisible(True)
self.movie.start()
logger.info("Cutting animation started.")
else:
self.movie.stop()
self.pipe_gif.setVisible(False)
logger.info("Cutting animation stopped.")