mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2025-12-17 04:51:10 +00:00
Merge branch 'workstation_dev' into dev
# Conflicts: # .conda/recipe.yaml # recipes/msgs/recipe.yaml # recipes/unilabos/recipe.yaml # setup.py # unilabos/registry/devices/work_station.yaml # unilabos/ros/nodes/base_device_node.py # unilabos/ros/nodes/presets/protocol_node.py # unilabos_msgs/package.xml
This commit is contained in:
@@ -518,6 +518,17 @@ class BaseROS2DeviceNode(Node, Generic[T]):
|
||||
rclpy.get_global_executor().add_node(self)
|
||||
self.lab_logger().debug(f"ROS节点初始化完成")
|
||||
|
||||
async def update_resource(self, resources: List[Any]):
|
||||
r = ResourceUpdate.Request()
|
||||
unique_resources = []
|
||||
for resource in resources: # resource是list[ResourcePLR]
|
||||
# 目前更新资源只支持传入plr的对象,后面要更新convert_resources_from_type函数
|
||||
converted_list = convert_resources_from_type([resource], resource_type=[object], is_plr=True)
|
||||
unique_resources.extend([convert_to_ros_msg(Resource, converted) for converted in converted_list])
|
||||
r.resources = unique_resources
|
||||
response = await self._resource_clients["resource_update"].call_async(r)
|
||||
self.lab_logger().debug(f"资源更新结果: {response}")
|
||||
|
||||
def register_device(self):
|
||||
"""向注册表中注册设备信息"""
|
||||
topics_info = self._property_publishers.copy()
|
||||
@@ -947,6 +958,7 @@ class ROS2DeviceNode:
|
||||
self._driver_class = driver_class
|
||||
self.device_config = device_config
|
||||
self.driver_is_ros = driver_is_ros
|
||||
self.driver_is_workstation = False
|
||||
self.resource_tracker = DeviceNodeResourceTracker()
|
||||
|
||||
# use_pylabrobot_creator 使用 cls的包路径检测
|
||||
@@ -967,10 +979,11 @@ class ROS2DeviceNode:
|
||||
driver_class, children=children, resource_tracker=self.resource_tracker
|
||||
)
|
||||
else:
|
||||
from unilabos.ros.nodes.presets.protocol_node import ROS2ProtocolNode
|
||||
from unilabos.devices.workstation.workstation_base import WorkstationBase
|
||||
|
||||
if issubclass(self._driver_class, ROS2ProtocolNode): # 是ProtocolNode的子节点,就要调用ProtocolNodeCreator
|
||||
self._driver_creator = ProtocolNodeCreator(driver_class, children=children, resource_tracker=self.resource_tracker)
|
||||
if issubclass(self._driver_class, WorkstationBase): # 是WorkstationNode的子节点,就要调用WorkstationNodeCreator
|
||||
self.driver_is_workstation = True
|
||||
self._driver_creator = WorkstationNodeCreator(driver_class, children=children, resource_tracker=self.resource_tracker)
|
||||
else:
|
||||
self._driver_creator = DeviceClassCreator(driver_class, children=children, resource_tracker=self.resource_tracker)
|
||||
|
||||
@@ -985,6 +998,19 @@ class ROS2DeviceNode:
|
||||
# 创建ROS2节点
|
||||
if driver_is_ros:
|
||||
self._ros_node = self._driver_instance # type: ignore
|
||||
elif self.driver_is_workstation:
|
||||
from unilabos.ros.nodes.presets.workstation import ROS2WorkstationNode
|
||||
self._ros_node = ROS2WorkstationNode(
|
||||
protocol_type=driver_params["protocol_type"],
|
||||
children=children,
|
||||
driver_instance=self._driver_instance, # type: ignore
|
||||
device_id=device_id,
|
||||
status_types=status_types,
|
||||
action_value_mappings=action_value_mappings,
|
||||
hardware_interface=hardware_interface,
|
||||
print_publish=print_publish,
|
||||
resource_tracker=self.resource_tracker,
|
||||
)
|
||||
else:
|
||||
self._ros_node = BaseROS2DeviceNode(
|
||||
driver_instance=self._driver_instance,
|
||||
|
||||
Reference in New Issue
Block a user