feat: add outer resource

This commit is contained in:
wznln
2025-05-06 21:57:34 +08:00
parent de28c50d8b
commit ed2858a610
4 changed files with 35 additions and 67 deletions

View File

@@ -0,0 +1,5 @@
使用plr_test.json启动将Well加入Plate中
```bash
ros2 action send_goal /devices/host_node/add_resource_from_outer unilabos_msgs/action/_resource_create_from_outer/ResourceCreateFromOuter "{ resources: [ { 'category': '', 'children': [], 'config': { 'type': 'Well', 'size_x': 6.86, 'size_y': 6.86, 'size_z': 10.67, 'rotation': { 'x': 0, 'y': 0, 'z': 0, 'type': 'Rotation' }, 'category': 'well', 'model': null, 'max_volume': 360, 'material_z_thickness': 0.5, 'compute_volume_from_height': null, 'compute_height_from_volume': null, 'bottom_type': 'flat', 'cross_section_type': 'circle' }, 'data': { 'liquids': [], 'pending_liquids': [], 'liquid_history': [] }, 'id': 'plate_well_11_7', 'name': 'plate_well_11_7', 'pose': { 'orientation': { 'w': 1.0, 'x': 0.0, 'y': 0.0, 'z': 0.0 }, 'position': { 'x': 0.0, 'y': 0.0, 'z': 0.0 } }, 'sample_id': '', 'parent': 'plate', 'type': 'device' } ], device_ids: [ 'PLR_STATION' ], bind_parent_ids: [ 'plate' ], bind_locations: [ { 'x': 0.0, 'y': 0.0, 'z': 0.0 } ], other_calling_params: [ '{}' ] }"
```

View File

@@ -6679,8 +6679,7 @@
"plate_well_11_3", "plate_well_11_3",
"plate_well_11_4", "plate_well_11_4",
"plate_well_11_5", "plate_well_11_5",
"plate_well_11_6", "plate_well_11_6"
"plate_well_11_7"
], ],
"parent": "deck", "parent": "deck",
"type": "device", "type": "device",
@@ -10508,45 +10507,6 @@
"pending_liquids": [], "pending_liquids": [],
"liquid_history": [] "liquid_history": []
} }
},
{
"id": "plate_well_11_7",
"name": "plate_well_11_7",
"sample_id": null,
"children": [],
"parent": "plate",
"type": "device",
"class": "",
"position": {
"x": 109.87,
"y": 7.77,
"z": 3.03
},
"config": {
"type": "Well",
"size_x": 6.86,
"size_y": 6.86,
"size_z": 10.67,
"rotation": {
"x": 0,
"y": 0,
"z": 0,
"type": "Rotation"
},
"category": "well",
"model": null,
"max_volume": 360,
"material_z_thickness": 0.5,
"compute_volume_from_height": null,
"compute_height_from_volume": null,
"bottom_type": "flat",
"cross_section_type": "circle"
},
"data": {
"liquids": [],
"pending_liquids": [],
"liquid_history": []
}
} }
], ],
"links": [] "links": []

View File

@@ -15,7 +15,7 @@ from rclpy.action.server import ServerGoalHandle
from rclpy.client import Client from rclpy.client import Client
from rclpy.callback_groups import ReentrantCallbackGroup from rclpy.callback_groups import ReentrantCallbackGroup
from rclpy.service import Service from rclpy.service import Service
from unilabos_msgs.srv._serial_command import SerialCommand_Request from unilabos_msgs.srv._serial_command import SerialCommand_Request, SerialCommand_Response
from unilabos.resources.graphio import convert_resources_to_type, convert_resources_from_type, resource_ulab_to_plr from unilabos.resources.graphio import convert_resources_to_type, convert_resources_from_type, resource_ulab_to_plr
from unilabos.ros.msgs.message_converter import ( from unilabos.ros.msgs.message_converter import (
@@ -305,7 +305,7 @@ class BaseROS2DeviceNode(Node, Generic[T]):
res.response = "" res.response = ""
return res return res
def append_resource(req: SerialCommand_Request, res): def append_resource(req: SerialCommand_Request, res: SerialCommand_Response):
# 物料传输到对应的node节点 # 物料传输到对应的node节点
rclient = self.create_client(ResourceAdd, "/resources/add") rclient = self.create_client(ResourceAdd, "/resources/add")
rclient.wait_for_service() rclient.wait_for_service()
@@ -314,7 +314,7 @@ class BaseROS2DeviceNode(Node, Generic[T]):
namespace = command_json["namespace"] namespace = command_json["namespace"]
bind_parent_id = command_json["bind_parent_id"] bind_parent_id = command_json["bind_parent_id"]
edge_device_id = command_json["edge_device_id"] edge_device_id = command_json["edge_device_id"]
location = command_json["location"] location = command_json["bind_location"]
other_calling_param = command_json["other_calling_param"] other_calling_param = command_json["other_calling_param"]
resources = command_json["resource"] resources = command_json["resource"]
# 本地拿到这个物料,可能需要先做初始化? # 本地拿到这个物料,可能需要先做初始化?
@@ -341,8 +341,9 @@ class BaseROS2DeviceNode(Node, Generic[T]):
except Exception as e: except Exception as e:
self.lab_logger().error("Host请求添加物料时出错") self.lab_logger().error("Host请求添加物料时出错")
self.lab_logger().error(traceback.format_exc()) self.lab_logger().error(traceback.format_exc())
pass return res
# noinspection PyTypeChecker
self._service_server: Dict[str, Service] = { self._service_server: Dict[str, Service] = {
"query_host_name": self.create_service( "query_host_name": self.create_service(
SerialCommand, f"/srv{self.namespace}/query_host_name", query_host_name_cb, callback_group=self.callback_group SerialCommand, f"/srv{self.namespace}/query_host_name", query_host_name_cb, callback_group=self.callback_group
@@ -571,6 +572,7 @@ class BaseROS2DeviceNode(Node, Generic[T]):
del future del future
# 向Host更新物料当前状态 # 向Host更新物料当前状态
if action_name != "add_resource_from_outer":
for k, v in goal.get_fields_and_field_types().items(): for k, v in goal.get_fields_and_field_types().items():
if v not in ["unilabos_msgs/Resource", "sequence<unilabos_msgs/Resource>"]: if v not in ["unilabos_msgs/Resource", "sequence<unilabos_msgs/Resource>"]:
continue continue

View File

@@ -286,10 +286,11 @@ class HostNode(BaseROS2DeviceNode):
"y": bind_location.y, "y": bind_location.y,
"z": bind_location.z, "z": bind_location.z,
}, },
"other_calling_param": json.loads(other_calling_param), "other_calling_param": json.loads(other_calling_param) if other_calling_param else {},
}, ensure_ascii=False) }, ensure_ascii=False)
response = sclient.call(request) response = sclient.call(request)
pass pass
pass
def initialize_device(self, device_id: str, device_config: Dict[str, Any]) -> None: def initialize_device(self, device_id: str, device_config: Dict[str, Any]) -> None:
""" """