-
{{ device.class_json }}
+
{{ device.class|tojson(indent=4) }}
{% if device.is_online %}
在线
diff --git a/unilabos/registry/registry.py b/unilabos/registry/registry.py
index b8120330..feba3fef 100644
--- a/unilabos/registry/registry.py
+++ b/unilabos/registry/registry.py
@@ -7,7 +7,7 @@ from typing import Any
import yaml
from unilabos.utils import logger
-from unilabos.ros.msgs.message_converter import msg_converter_manager
+from unilabos.ros.msgs.message_converter import msg_converter_manager, ros_action_to_json_schema
from unilabos.utils.decorator import singleton
from unilabos.utils.type_check import TypeEncoder
@@ -131,6 +131,7 @@ class Registry:
action_config["type"] = self._replace_type_with_class(
action_config["type"], device_id, f"动作 {action_name}"
)
+ action_config["schema"] = ros_action_to_json_schema(action_config["type"])
self.device_type_registry.update(data)
@@ -150,11 +151,7 @@ class Registry:
for device_id, device_info in self.device_type_registry.items():
msg = {
"id": device_id,
- "name": device_info.get("name", "未命名"),
- "file_path": device_info.get("file_path", ""),
- "class_json": json.dumps(
- device_info.get("class", {}), indent=4, ensure_ascii=False, cls=TypeEncoder
- ),
+ **device_info
}
devices.append(msg)
return devices
diff --git a/unilabos/ros/main_slave_run.py b/unilabos/ros/main_slave_run.py
index 5c038bdc..974359a3 100644
--- a/unilabos/ros/main_slave_run.py
+++ b/unilabos/ros/main_slave_run.py
@@ -1,3 +1,4 @@
+import copy
import json
import os
import traceback
@@ -85,7 +86,7 @@ def slave(
"""从节点函数"""
rclpy.init(args=args)
rclpy.__executor = executor = MultiThreadedExecutor()
-
+ devices_config_copy = copy.deepcopy(devices_config)
for device_id, device_config in devices_config.items():
d = initialize_device_from_dict(device_id, device_config)
if d is None:
@@ -109,20 +110,19 @@ def slave(
request.command = json.dumps({
"machine_name": machine_name,
"type": "slave",
- "devices_config": devices_config,
+ "devices_config": devices_config_copy,
"registry_config": lab_registry.obtain_registry_device_info()
}, ensure_ascii=False, cls=TypeEncoder)
- response = sclient.call_async(request)
- logger.info(f"Slave node info update response: {response}")
+ response = sclient.call_async(request).result()
+ logger.info(f"Slave node info updated.")
rclient = n.create_client(ResourceAdd, "/resources/add")
rclient.wait_for_service() # FIXME 可能一直等待,加一个参数
request = ResourceAdd.Request()
request.resources = [convert_to_ros_msg(Resource, resource) for resource in resources_config]
- response = rclient.call_async(request)
- logger.info(f"Slave resource add response: {response}")
-
+ response = rclient.call_async(request).result()
+ logger.info(f"Slave resource added.")
run_event_loop_in_thread()
diff --git a/unilabos/ros/nodes/presets/host_node.py b/unilabos/ros/nodes/presets/host_node.py
index 8e07e05c..e8d43b35 100644
--- a/unilabos/ros/nodes/presets/host_node.py
+++ b/unilabos/ros/nodes/presets/host_node.py
@@ -516,7 +516,13 @@ class HostNode(BaseROS2DeviceNode):
"""
self.lab_logger().info(f"[Host Node] Node info update request received: {request}")
try:
+ from unilabos.app.mq import mqtt_client
info = json.loads(request.command)
+ machine_name = info["machine_name"]
+ devices_config = info["devices_config"]
+ registry_config = info["registry_config"]
+ for device_config in registry_config:
+ mqtt_client.publish_registry(device_config["id"], device_config)
self.lab_logger().info(f"[Host Node] Node info update: {info}")
response.response = "OK"
except Exception as e: