complete require packages

msg converter support array string
implements create resource logic
This commit is contained in:
wznln
2025-05-15 02:47:45 +08:00
parent 93c40e236f
commit c04202c6e0
10 changed files with 61 additions and 27 deletions

View File

@@ -102,11 +102,11 @@ class HostNode(BaseROS2DeviceNode):
self.devices_instances: Dict[str, ROS2DeviceNode] = {} # 存储设备实例
self.device_machine_names: Dict[str, str] = {device_id: "本地", } # 存储设备ID到机器名称的映射
self._action_clients: Dict[str, ActionClient] = { # 为了方便了解实际的数据类型host的默认写好
"/devices/host_node/add_resource_from_outer_easy": ActionClient(
self, lab_registry.ResourceCreateFromOuterEasy, "/devices/host_node/add_resource_from_outer_easy", callback_group=self.callback_group
"/devices/host_node/create_resource": ActionClient(
self, lab_registry.ResourceCreateFromOuterEasy, "/devices/host_node/create_resource", callback_group=self.callback_group
),
"/devices/host_node/add_resource_from_outer": ActionClient(
self, lab_registry.ResourceCreateFromOuter, "/devices/host_node/add_resource_from_outer", callback_group=self.callback_group
"/devices/host_node/create_resource_detailed": ActionClient(
self, lab_registry.ResourceCreateFromOuter, "/devices/host_node/create_resource_detailed", callback_group=self.callback_group
)
} # 用来存储多个ActionClient实例
self._action_value_mappings: Dict[str, Dict] = {} # 用来存储多个ActionClient的type, goal, feedback, result的变量名映射关系
@@ -290,7 +290,7 @@ class HostNode(BaseROS2DeviceNode):
except Exception as e:
self.lab_logger().error(f"[Host Node] Failed to create ActionClient for {action_id}: {str(e)}")
def add_resource_from_outer(self, resources: list["Resource"], device_ids: list[str], bind_parent_ids: list[str], bind_locations: list[Point], other_calling_params: list[str]):
def create_resource_detailed(self, resources: list["Resource"], device_ids: list[str], bind_parent_ids: list[str], bind_locations: list[Point], other_calling_params: list[str]):
for resource, device_id, bind_parent_id, bind_location, other_calling_param in zip(resources, device_ids, bind_parent_ids, bind_locations, other_calling_params):
# 这里要求device_id传入必须是edge_device_id
namespace = "/devices/" + device_id
@@ -299,7 +299,7 @@ class HostNode(BaseROS2DeviceNode):
sclient.wait_for_service()
request = SerialCommand.Request()
request.command = json.dumps({
"resource": resource,
"resource": resource, # 单个/单组 可为 list[list[Resource]]
"namespace": namespace,
"edge_device_id": device_id,
"bind_parent_id": bind_parent_id,
@@ -314,7 +314,7 @@ class HostNode(BaseROS2DeviceNode):
pass
pass
def add_resource_from_outer_easy(self, device_id: str, res_id: str, class_name: str, parent: str, bind_locations: Point, liquid_input_slot: list[int], liquid_type: list[str], liquid_volume: list[int], slot_on_deck: int):
def create_resource(self, device_id: str, res_id: str, class_name: str, parent: str, bind_locations: Point, liquid_input_slot: list[int], liquid_type: list[str], liquid_volume: list[int], slot_on_deck: int):
init_new_res = initialize_resource({
"name": res_id,
"class": class_name,
@@ -324,8 +324,8 @@ class HostNode(BaseROS2DeviceNode):
"y": bind_locations.y,
"z": bind_locations.z,
}
})
resources = init_new_res
}) # flatten的格式
resources = [init_new_res]
device_id = [device_id]
bind_parent_id = [parent]
bind_location = [bind_locations]
@@ -337,7 +337,7 @@ class HostNode(BaseROS2DeviceNode):
"slot": slot_on_deck
})]
return self.add_resource_from_outer(resources, device_id, bind_parent_id, bind_location, other_calling_param)
return self.create_resource_detailed(resources, device_id, bind_parent_id, bind_location, other_calling_param)
def initialize_device(self, device_id: str, device_config: Dict[str, Any]) -> None:
"""