Compare commits

..

4 Commits

Author SHA1 Message Date
Xuwznln
93cb307396 Fix update with different spot and same parent 2026-01-08 03:46:00 +08:00
Xuwznln
1c312772ae Force update resource when adding new resource / transfer to another resource 2026-01-08 03:07:12 +08:00
Xuwznln
bad1db5094 location not passed to ItemizedCarrier when assign child resource 2026-01-08 03:07:11 +08:00
Xuwznln
f26eb69eca Fix size not pass through. 2026-01-08 03:07:11 +08:00
3 changed files with 32 additions and 6 deletions

View File

@@ -149,6 +149,7 @@ class ItemizedCarrier(ResourcePLR):
if not reassign and self.sites[idx] is not None:
raise ValueError(f"a site with index {idx} already exists")
location = list(self.child_locations.values())[idx]
super().assign_child_resource(resource, location=location, reassign=reassign)
self.sites[idx] = resource

View File

@@ -14,9 +14,9 @@ if TYPE_CHECKING:
class ResourceDictPositionSize(BaseModel):
depth: float = Field(description="Depth", default=0.0)
width: float = Field(description="Width", default=0.0)
height: float = Field(description="Height", default=0.0)
depth: float = Field(description="Depth", default=0.0) # z
width: float = Field(description="Width", default=0.0) # x
height: float = Field(description="Height", default=0.0) # y
class ResourceDictPositionScale(BaseModel):
@@ -469,9 +469,9 @@ class ResourceTreeSet(object):
**res.config,
"name": res.name,
"type": res.config.get("type", plr_type),
"size_x": res.config.get("size_x", 0),
"size_y": res.config.get("size_y", 0),
"size_z": res.config.get("size_z", 0),
"size_x": res.pose.size.width,
"size_y": res.pose.size.height,
"size_z": res.pose.size.depth,
"location": {
"x": res.pose.position.x,
"y": res.pose.position.y,

View File

@@ -844,6 +844,16 @@ class BaseROS2DeviceNode(Node, Generic[T]):
and original_parent_resource is not None
):
self.transfer_to_new_resource(original_instance, tree, additional_add_params)
else:
# 判断是否变更了resource_site
target_site = original_instance.unilabos_extra.get("update_resource_site")
sites = original_instance.parent.sites if original_instance.parent is not None and hasattr(original_instance.parent, "sites") else None
site_names = list(original_instance.parent._ordering.keys()) if original_instance.parent is not None and hasattr(original_instance.parent, "sites") else []
if target_site is not None and sites is not None and site_names is not None:
site_index = sites.index(original_instance)
site_name = site_names[site_index]
if site_name != target_site:
self.transfer_to_new_resource(original_instance, tree, additional_add_params)
# 加载状态
original_instance.load_all_state(states)
@@ -881,6 +891,13 @@ class BaseROS2DeviceNode(Node, Generic[T]):
raise ValueError("tree_set不能为None")
plr_resources = tree_set.to_plr_resources()
result = _handle_add(plr_resources, tree_set, additional_add_params)
new_tree_set = ResourceTreeSet.from_plr_resources(plr_resources)
r = SerialCommand.Request()
r.command = json.dumps(
{"data": {"data": new_tree_set.dump()}, "action": "update"}) # 和Update Resource一致
response: SerialCommand_Response = await self._resource_clients[
"c2s_update_resource_tree"].call_async(r) # type: ignore
self.lab_logger().info(f"确认资源云端 Add 结果: {response.response}")
results.append(result)
elif action == "update":
if tree_set is None:
@@ -891,7 +908,14 @@ class BaseROS2DeviceNode(Node, Generic[T]):
plr_resources.append(tree.root_node)
else:
plr_resources.append(ResourceTreeSet([tree]).to_plr_resources()[0])
new_tree_set = ResourceTreeSet.from_plr_resources(plr_resources)
result = _handle_update(plr_resources, tree_set, additional_add_params)
r = SerialCommand.Request()
r.command = json.dumps(
{"data": {"data": new_tree_set.dump()}, "action": "update"}) # 和Update Resource一致
response: SerialCommand_Response = await self._resource_clients[
"c2s_update_resource_tree"].call_async(r) # type: ignore
self.lab_logger().info(f"确认资源云端 Update 结果: {response.response}")
results.append(result)
elif action == "remove":
result = _handle_remove(resources_uuid)
@@ -1758,6 +1782,7 @@ class ROS2DeviceNode:
or driver_class.__name__ == "LiquidHandlerBiomek"
or driver_class.__name__ == "PRCXI9300Handler"
or driver_class.__name__ == "TransformXYZHandler"
or driver_class.__name__ == "OpcUaClient"
)
# 创建设备类实例