diff --git a/config/machine_settings/defaults.ini b/config/machine_settings/defaults.ini index 285590c..052f33f 100644 --- a/config/machine_settings/defaults.ini +++ b/config/machine_settings/defaults.ini @@ -48,7 +48,6 @@ balance_blue: 1.5 time_format: %Y-%m-%d_%H-%M-%S path: ./data/images minimum_disk_free_space_gb: 20 -resize_resolution: 612x512 [archive_synchronizer] portal_address: https://r5portal.it/ diff --git a/config/machine_settings/test-windows.ini b/config/machine_settings/test-windows.ini index f499164..79c5146 100644 --- a/config/machine_settings/test-windows.ini +++ b/config/machine_settings/test-windows.ini @@ -5,7 +5,7 @@ image_for_warning= st-ten-1 [hardware_config] -archive_synchronizer: absent +archive_synchronizer: present galaxy_camera: absent uvc_camera: absent hikrobot_sc: present @@ -20,6 +20,11 @@ fixture_id: absent digital_io: absent external_flush_blow: absent +[archive_synchronizer] +portal_address: https://dev.r5portal.it/ +poll_time: 10 +hold_time: 10 + [tecna_t3] port: COM4 model: t3p diff --git a/config/vision/recipes/000952054.ini b/config/vision/recipes/000952054.ini index bd403ab..93c968e 100644 --- a/config/vision/recipes/000952054.ini +++ b/config/vision/recipes/000952054.ini @@ -28,9 +28,9 @@ rotations=2,1 [markers] [zones] -p1: 620,630 600,600 ok -p2: 1420,630 600,600 ok +SX: 620,630 600,600 ok +DX: 1420,630 600,600 ok [labels] -p1: 340,200 120 0xffffffff 0xff000000 4 O-RING 1 -p2: 1170,200 120 0xffffffff 0xff000000 4 O-RING 2 +SX: 160,230 100 0xffffffff 0xff000000 4 GUARNIZIONE SX +DX: 1100,230 100 0xffffffff 0xff000000 4 GUARNIZIONE DX diff --git a/src/components/archive_synchronizer.py b/src/components/archive_synchronizer.py index 2ee36a0..684ce0a 100644 --- a/src/components/archive_synchronizer.py +++ b/src/components/archive_synchronizer.py @@ -78,7 +78,7 @@ class ArchiveSynchronizer(Component): save_ok = self.remote_archive(record) is True e = time.time() else: - save_ok=True + save_ok = True if record.uploaded is not True: record.uploaded = self.remote_store(record) is True else: @@ -87,9 +87,10 @@ class ArchiveSynchronizer(Component): if save_ok: record.archived |= (1 << bit_pos) - self.log.info(f"({self.name}) id {record.id}: archived remotely") + # self.log.info(f"({self.name}) id {record.id}: archived remotely") else: - self.log.info(f"({self.name}) id {record.id}: failed to archive remotely") + pass + # self.log.info(f"({self.name}) id {record.id}: failed to archive remotely") self.main_window.run_request.emit(record.save, [], {}) if self.hold_time > 0: @@ -118,9 +119,10 @@ class ArchiveSynchronizer(Component): else: self.parse_response_and_execute(response) except AssertionError as e: - self.log.warning( - f"Status: {self.machine_status}: failed to update machine status: {str(e)}: {response.status_code if response else 'no response'}: {response.content if response else 'no response'}" - ) + if response is not None: + self.log.warning(f"Status: {self.machine_status}: failed to update machine status: {str(e)}: {response.status_code} : {response.content}") + else: + self.log.warning(f"Status: no response") return False except (requests.ConnectionError, requests.Timeout) as e: self.log.warning( @@ -129,7 +131,7 @@ class ArchiveSynchronizer(Component): return False except Exception: self.log.error( - f"Status: {self.machine_status}: failed to update machine status:\n{traceback.format_exc()}:\n{response.status_code if response else 'no response'}: {response.content if response else 'no response'}" + f"Status: {self.machine_status}: failed to update machine status:\n{traceback.format_exc()}:\n{response.status_code}: {response.content}" ) return False @@ -255,7 +257,7 @@ class ArchiveSynchronizer(Component): self.gcs_bucket = None if self.gcs_bucket is None: return False - for path in record.test_data["vision"]["0"]["files"]: + for path in record.test_data["vision"]["files"]: dt = record.time # path_in = f"{self.images_path}/{dt.strftime('%Y')}/{dt.strftime('%m')}/{os.path.basename(path)}" path_in = path diff --git a/src/components/component.py b/src/components/component.py index 599e8c3..020e10f 100644 --- a/src/components/component.py +++ b/src/components/component.py @@ -3,6 +3,7 @@ import traceback import types from lib.helpers import timing +from PyQt5.QtWidgets import QDialog, QMessageBox from PyQt5.QtCore import (QMutex, QObject, QSemaphore, Qt, QThread, QTimer, pyqtSignal) @@ -62,6 +63,7 @@ class Component(QObject): Component.reconfigurators.remove(self) Component.reconfigurators_lock.unlock() return ret + QMessageBox.critical(None, "ERRORE", f"ERRORE COMPONENTE {self.name}") raise RuntimeError(f"retried to run {f} and reconfigure {self} with no success for {t_limit} times. giving up.") return wrapper diff --git a/src/components/hikrobot_sc/hikrobot_sc.py b/src/components/hikrobot_sc/hikrobot_sc.py index ac8e72a..488d41a 100644 --- a/src/components/hikrobot_sc/hikrobot_sc.py +++ b/src/components/hikrobot_sc/hikrobot_sc.py @@ -13,7 +13,7 @@ from .hikrobot_dll import * class HikrobotSmartCamera(Component): - def __init__(self, config=None, name=None, period=1, lazy=True, paused=False, threaded=True): + def __init__(self, config=None, name=None, period=0.5, lazy=True, paused=False, threaded=True): super().__init__(config=config, name=name, period=period, lazy=lazy, paused=paused, threaded=threaded) self.lock = QMutex() self.simulate = "--sim-camera" in sys.argv @@ -102,3 +102,9 @@ class HikrobotSmartCamera(Component): concat_results.append(not res) super()._get([concat_frame,concat_results]) + def resume(self): + for cam_idx in range(self.num_cameras): + cam = self.cam_list[cam_idx] + nRet = mv_lib.MV_VS_SetCommandValue(cam["handle"], b"AcquisitionStart") + frame_res = MV_VS_GetFrame(cam["handle"]) + super().resume() diff --git a/src/components/vision.py b/src/components/vision.py index ee68995..8ac7c24 100644 --- a/src/components/vision.py +++ b/src/components/vision.py @@ -1,3 +1,4 @@ +import copy import logging import os import sys @@ -537,30 +538,48 @@ class Vision(Component): return parsed_detections - def read_smart_camera_results(self, detections): - + def read_smart_camera_results(self, results): + dummy_detection = { + "box": [0, 0, 0, 0], + "center": [0, 0], + "class": {}, + "score": 1, + "size": [0, 0], + } if self.zones is None or not len(self.zones): return None - results = dict.fromkeys(self.zones) + results_out = dict.fromkeys(self.zones) idx=0 checked = {} - for zone_name, detection in results.items(): + detections_out=[] + for zone_name, detection in results_out.items(): + res_det=copy.deepcopy(dummy_detection) + if results[idx]: + res_det["class"] = {"id": 1, "name": "OK", "color": "#00ff00"} + else: + res_det["class"] = {"id": 2, "name": "KO", "color": "#ff0000"} checked[zone_name] = { - "ok": detections[idx], - "expected": {"name": "OK", - "color": "rgb(0,255,0)"}, + "ok": results[idx], + "expected": {"id": 1, "name": "OK", "color": "#00ff00"}, + "detection": res_det } - idx+=1 - + detection_out=copy.deepcopy(dummy_detection) + detection_out["class"]={"id":1,"name":"OK","color":"rgb(0,255,0)"} if results[idx] else {"id":1,"name":"KO","color":"rgb(255,0,0)"} + detections_out.append(detection_out) + idx += 1 global vision_override if vision_override is None: - ok = all(map(lambda detection: detection["ok"] is True, checked.values())) + ok = all(map(lambda detection_l: detection_l["ok"] is True, checked.values())) else: ok = vision_override - return { + + + results={ "ok": ok, "results": checked, } + return results,detections_out + @@ -887,8 +906,7 @@ class Vision(Component): detections = self.check_features(consumable["frame"]) results = self.process_detections(detections) elif self.vision_config["type"]=="smart_camera": - results = self.read_smart_camera_results(consumable["detections"]) - detections = [] + results,detections = self.read_smart_camera_results(consumable["detections"]) return {"detections": detections, "results": results} diff --git a/src/ui/test/test.py b/src/ui/test/test.py index f7481e3..2afd73f 100755 --- a/src/ui/test/test.py +++ b/src/ui/test/test.py @@ -622,20 +622,19 @@ class Test(Widget): self.data[leak]["results"] = results if "vision" in self.data: - vision_test_1 = self.data.get("vision", {}).get("0", {}) + vision = self.data.get("vision", {}) out_paths = self.components["vision_saver"].save( - save_time=vision_test_1.get("time", None), - frame=vision_test_1.get("frame", None), + save_time=vision.get("time", None), + frame=vision.get("frame", None), # vision=vision_test_1.get("detections", None), ) - self.data.get("vision", {}).get("0", {})["files"] = out_paths + vision["files"] = out_paths self.log.info(f"cycle vision saved locally: {out_paths!r}") - for vision in self.data.get("vision", {}).values(): - vision.pop("frame", None) - vision.pop("render", None) - vision.pop("detections", None) - if "results" in vision.keys(): - vision["results"].pop("results", None) + vision.pop("frame", None) + vision.pop("render", None) + vision.pop("detections", None) + if "results" in vision.keys(): + vision["results"].pop("results", None) if self.autotesting: self.data["autotest"] = True self.data["autotest_reason"] = self.autotesting_reason @@ -691,7 +690,15 @@ class Test(Widget): psetminp2_a = leak_test_2_step_spec.get("settling_pressure_min_percent", 0) * (100 + leak_test_2_step_spec.get("test_pressure_qneg", 0) / 100) psetmaxp2_a = leak_test_2_step_spec.get("settling_pressure_max_percent", 0) * (100 + leak_test_2_step_spec.get("test_pressure_qpos", 0) / 100) if self.tester_component is not None: - leak_test_1_results["Running test: pressure at the end of measure"] = leak_test_1_results["Running test: pressure at the end of settling"] + leak_test_1_results["Running test: measured leak"] + if self.recipe.spec["leak_1"]: + leak_test_1_results["Running test: pressure at the end of measure"] = ( + leak_test_1_results["Running test: pressure at the end of settling"] + + leak_test_1_results["Running test: measured leak"]) + if self.recipe.spec["leak_1"]: + leak_test_2_results["Running test: pressure at the end of measure"] = ( + leak_test_2_results["Running test: pressure at the end of settling"] + + leak_test_2_results["Running test: measured leak"]) + printer_fields = self.print_step.spec context = { # RECIPE DATA @@ -781,7 +788,8 @@ class Test(Widget): else: compiled_label = self.components["label_printer"].print_label(label, context=context) self.log.info(f"Main label printed: {context!r}") - return compiled_label + # return fields used to print label for saving into test archive + return context def print_extra_labels(self): # PRINT EXTRA LABELS IF NEEDED (BEFORE LEAK TEST) diff --git a/src/ui/test_test/test_test.py b/src/ui/test_test/test_test.py index cb55ff7..707b23a 100644 --- a/src/ui/test_test/test_test.py +++ b/src/ui/test_test/test_test.py @@ -150,7 +150,7 @@ class Test_Test(Widget): else: result_ok = data.get("results", {}).get("ok", None) duration=cur_timing - self.start_time - data.pop("step",None) + data.pop("step", None) self.last = { **data, "overridden": override, diff --git a/src/ui/test_vision/test_vision.py b/src/ui/test_vision/test_vision.py index e5d97d7..c968cce 100644 --- a/src/ui/test_vision/test_vision.py +++ b/src/ui/test_vision/test_vision.py @@ -58,10 +58,11 @@ class Test_Vision(Test_Test): def stop(self): # disable camera-vision loop - if "uvc_camera" in self.components: - self.components["uvc_camera"].pause() - elif "galaxy_camera" in self.components: - self.components["galaxy_camera"].pause() + cam_type = self.components["vision"].vision_config["camera_type"] + if cam_type in ("uvc_camera","galaxy_camera","hikrobot_sc"): + self.components[cam_type].pause() + else: + return self.components["vision"].pause() self.disconnect(self.get_connection) self.disconnect(self.request_frame_connection) @@ -75,7 +76,7 @@ class Test_Vision(Test_Test): # super().reset() def get(self, data=None, override=False): - if self.done: # avoid proccessing if completed + if self.done: # avoid processing if completed return if data is None or data[-1] is None: super().get(None, override=override) diff --git a/src/ui/test_vision/test_vision.ui b/src/ui/test_vision/test_vision.ui index 707efb5..164fb13 100644 --- a/src/ui/test_vision/test_vision.ui +++ b/src/ui/test_vision/test_vision.ui @@ -6,8 +6,8 @@ 0 0 - 1250 - 629 + 1018 + 1064 @@ -145,9 +145,15 @@ 0 + + + 400 + 0 + + - 500 + 600 16777215 @@ -199,7 +205,7 @@ - + 0 0