mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2025-12-17 13:01:12 +00:00
@@ -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()
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user