Force update resource when adding new resource / transfer to another resource

location not passed to ItemizedCarrier when assign child resource

Fix size not pass through.
This commit is contained in:
Xuwznln
2026-01-08 03:04:32 +08:00
parent 024156848e
commit 3f80349d7d
3 changed files with 15 additions and 6 deletions

View File

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

View File

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

View File

@@ -881,6 +881,13 @@ class BaseROS2DeviceNode(Node, Generic[T]):
raise ValueError("tree_set不能为None") raise ValueError("tree_set不能为None")
plr_resources = tree_set.to_plr_resources() plr_resources = tree_set.to_plr_resources()
result = _handle_add(plr_resources, tree_set, additional_add_params) 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) results.append(result)
elif action == "update": elif action == "update":
if tree_set is None: if tree_set is None:
@@ -1758,6 +1765,7 @@ class ROS2DeviceNode:
or driver_class.__name__ == "LiquidHandlerBiomek" or driver_class.__name__ == "LiquidHandlerBiomek"
or driver_class.__name__ == "PRCXI9300Handler" or driver_class.__name__ == "PRCXI9300Handler"
or driver_class.__name__ == "TransformXYZHandler" or driver_class.__name__ == "TransformXYZHandler"
or driver_class.__name__ == "OpcUaClient"
) )
# 创建设备类实例 # 创建设备类实例