diff --git a/test/experiments/test_copy.json b/test/experiments/test_copy.json index 56127a24..9b1debed 100644 --- a/test/experiments/test_copy.json +++ b/test/experiments/test_copy.json @@ -37,7 +37,7 @@ "teaching_carrier" ], "parent": "PLR_STATION", - "type": "device", + "type": "deck", "class": "OTDeck", "position": { "x": 0, diff --git a/unilabos/app/backend.py b/unilabos/app/backend.py index 19cebff0..b12ef888 100644 --- a/unilabos/app/backend.py +++ b/unilabos/app/backend.py @@ -29,7 +29,9 @@ def start_backend( backend_thread = threading.Thread( target=main if not without_host else slave, - args=(devices_config, resources_config, graph, controllers_config, bridges) + args=(devices_config, resources_config, graph, controllers_config, bridges), + name="backend_thread", + daemon=True, ) backend_thread.start() logger.info(f"Backend {backend} started.") diff --git a/unilabos/app/main.py b/unilabos/app/main.py index d26536f0..2c564dc2 100644 --- a/unilabos/app/main.py +++ b/unilabos/app/main.py @@ -1,8 +1,11 @@ import argparse +import asyncio import os import signal import sys import json +import time + import yaml from copy import deepcopy import threading @@ -125,7 +128,7 @@ def main(): print_unilab_banner(args_dict) # 注册表 - registry_dict = build_registry(args_dict["registry_path"]) + build_registry(args_dict["registry_path"]) if args_dict["graph"] is not None: @@ -180,14 +183,17 @@ def main(): enable_rviz=True elif args_dict["visual"] == "web": enable_rviz=False - resource_visualization = ResourceVisualization(devices_and_resources, args_dict["resources_config"],registry_dict,enable_rviz=enable_rviz) + resource_visualization = ResourceVisualization(devices_and_resources, args_dict["resources_config"] ,enable_rviz=enable_rviz) devices_config_add = add_resource_mesh_manager_node(resource_visualization.resource_model, args_dict["resources_config"]) args_dict["devices_config"] = {**args_dict["devices_config"], **devices_config_add} - - server_thread = threading.Thread(target=start_server) - server_thread.start() start_backend(**args_dict) + + from unilabos.ros.nodes.base_device_node import ROS2DeviceNode + while ROS2DeviceNode.get_loop() is None: + time.sleep(0.1) + asyncio.set_event_loop(ROS2DeviceNode.get_loop()) resource_visualization.start() + start_server() else: start_backend(**args_dict) start_server() diff --git a/unilabos/app/mq.py b/unilabos/app/mq.py index a6123fb2..d0975e91 100644 --- a/unilabos/app/mq.py +++ b/unilabos/app/mq.py @@ -35,7 +35,8 @@ class MQTTClient: self.client.on_disconnect = self._on_disconnect def _on_log(self, client, userdata, level, buf): - logger.info(f"[MQTT] log: {buf}") + # logger.info(f"[MQTT] log: {buf}") + pass def _on_connect(self, client, userdata, flags, rc, properties=None): logger.info("[MQTT] Connected with result code " + str(rc)) diff --git a/unilabos/device_mesh/resource_visalization.py b/unilabos/device_mesh/resource_visalization.py index e56e96fa..14ff50c6 100644 --- a/unilabos/device_mesh/resource_visalization.py +++ b/unilabos/device_mesh/resource_visalization.py @@ -6,9 +6,11 @@ from launch_ros.actions import Node as nd import xacro from lxml import etree +from unilabos.registry.registry import lab_registry + class ResourceVisualization: - def __init__(self, device: dict, resource: dict, registry: dict, enable_rviz: bool = True): + def __init__(self, device: dict, resource: dict, enable_rviz: bool = True): """初始化资源可视化类 该类用于将设备和资源的3D模型可视化展示。通过解析设备和资源的配置信息, @@ -24,9 +26,10 @@ class ResourceVisualization: self.launch_description = LaunchDescription() self.resource_dict = resource self.resource_model = {} - self.resource_type = ['plate', 'container'] + self.resource_type = ['deck', 'plate', 'container'] self.mesh_path = Path(__file__).parent.absolute() self.enable_rviz = enable_rviz + registry = lab_registry self.srdf_str = ''' diff --git a/unilabos/registry/devices/deck.yaml b/unilabos/registry/devices/deck.yaml deleted file mode 100644 index 4ebd46c1..00000000 --- a/unilabos/registry/devices/deck.yaml +++ /dev/null @@ -1,5 +0,0 @@ -OTDeck: - description: Opentrons deck 3d model - model: - type: device - mesh: opentrons_liquid_handler \ No newline at end of file diff --git a/unilabos/ros/main_slave_run.py b/unilabos/ros/main_slave_run.py index 9ac96748..92d3aec4 100644 --- a/unilabos/ros/main_slave_run.py +++ b/unilabos/ros/main_slave_run.py @@ -2,6 +2,7 @@ import copy import json import os import threading +import time from typing import Optional, Dict, Any, List import rclpy @@ -66,7 +67,7 @@ def main( thread.start() while True: - input() + time.sleep(1) def slave( @@ -120,7 +121,7 @@ def slave( logger.info(f"Slave resource added.") while True: - input() + time.sleep(1) if __name__ == "__main__": main()