This commit is contained in:
edo-neo 2025-08-20 13:14:54 +02:00
parent 0f145f679a
commit 9a514bc064
2 changed files with 28 additions and 6 deletions

View File

@ -8,7 +8,7 @@ import sys
from PyQt5.QtCore import pyqtSignal, QMutex
from PyQt5.QtWidgets import QMessageBox
from components.component import Component
from ..component import Component
from .hikrobot_dll import *
@ -22,6 +22,29 @@ class HikrobotSmartCamera(Component):
self.ok_memory = True
self.ok_frames = []
self.ok_results =[]
self.solution_name = None
self.rotations = "0" # Default rotation value
def update_solution_name(self, recipe_name):
"""
This method is called when the vision component's recipe changes.
It updates the solution_name attribute and triggers a reconfiguration.
It also attempts to get the rotations value from the vision component if available.
"""
self.log.info(f"Updating solution name to: {recipe_name}")
self.solution_name = recipe_name
# Try to get rotations from vision component if available
try:
if hasattr(self, "components") and "vision" in self.components and hasattr(self.components["vision"], "vision_config"):
if self.components["vision"].vision_config is not None and "rotations" in self.components["vision"].vision_config:
self.rotations = self.components["vision"].vision_config["rotations"]
self.log.info(f"Updated rotations to: {self.rotations}")
except Exception as e:
self.log.warning(f"Could not update rotations: {e}")
self.reconfigure()
def config_changed(self):
self.connected = False
@ -85,9 +108,8 @@ class HikrobotSmartCamera(Component):
return -2
# Set the camera recipe
if self.config.vision_config.get("solution_name",None) is not None:
solutionName = self.config.vision_config["solution_name"]
mv_lib.MV_VS_SetStringValue(pHandle, "SrcOperateSolutionName", solutionName)
if self.solution_name is not None:
mv_lib.MV_VS_SetStringValue(pHandle, "SrcOperateSolutionName", self.solution_name)
mv_lib.MV_VS_SetCommandValue(pHandle, "CommandProjectLoad")
time.sleep(5)
@ -105,7 +127,7 @@ class HikrobotSmartCamera(Component):
return
concat_frame = None
concat_results = []
rot = self.config.vision_config["rotations"].split(",")
rot = self.rotations.split(",")
for cam_idx in range(self.num_cameras):
cam = self.cam_list[cam_idx]
self.log.info(f"GET FRAME CAMERA # {cam_idx}")

View File

@ -180,7 +180,7 @@ try:
self.components["vision"].set_sources({"hikrobot_sc": self.components["hikrobot_sc"].out})
# Connect the recipe_changed_signal from Vision to HikrobotSmartCamera
self.components["vision"].recipe_changed_signal.connect(
lambda recipe_name: self.components["hikrobot_sc"].config_changed()
self.components["hikrobot_sc"].update_solution_name
)
# connect tecna to screwdriver