mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2026-02-05 05:45:10 +00:00
* Update README and MQTTClient for installation instructions and code improvements * feat: 支持local_config启动 add: 增加对crt path的说明,为传入config.py的相对路径 move: web component * add: registry description * add 3d visualization * 完成在main中启动设备可视化 完成在main中启动设备可视化,并输出物料ID:mesh的对应关系resource_model 添加物料模型管理类,遍历物料与resource_model,完成TF数据收集 * 完成TF发布 * 修改模型方向,在yaml中添加变换属性 * 添加物料tf变化时,发送topic到前端 另外修改了物料初始化的方法,防止在tf还未发布时提前建立物料模型与发布话题 * 添加关节发布节点与物料可视化节点进入unilab * 使用json启动plr与3D模型仿真 * feat: node_info_update srv fix: OTDeck cant create * close #12 feat: slave node registry * feat: show machine name fix: host node registry not uploaded * feat: add hplc registry * feat: add hplc registry * fix: hplc status typo * fix: devices/ * 完成启动OT并联动rviz * add 3d visualization * 完成在main中启动设备可视化 完成在main中启动设备可视化,并输出物料ID:mesh的对应关系resource_model 添加物料模型管理类,遍历物料与resource_model,完成TF数据收集 * 完成TF发布 * 修改模型方向,在yaml中添加变换属性 * 添加物料tf变化时,发送topic到前端 另外修改了物料初始化的方法,防止在tf还未发布时提前建立物料模型与发布话题 * 添加关节发布节点与物料可视化节点进入unilab * 使用json启动plr与3D模型仿真 * 完成启动OT并联动rviz * fix: device.class possible null * fix: HPLC additions with online service * fix: slave mode spin not working * fix: slave mode spin not working * 修复rviz位置问题, 修复rviz位置问题, 在无tf变动时减缓发送频率 在backend中添加物料跟随方法 * feat: 多ProtocolNode 允许子设备ID相同 feat: 上报发现的ActionClient feat: Host重启动,通过discover机制要求slaveNode重新注册,实现信息及时上报 * feat: 支持env设置config * fix: running logic * fix: running logic * fix: missing ot * 在main中直接初始化republisher和物料的mesh节点 * 将joint_republisher和resource_mesh_manager添加进 main_slave_run.py中 * Device visualization (#14) * add 3d visualization * 完成在main中启动设备可视化 完成在main中启动设备可视化,并输出物料ID:mesh的对应关系resource_model 添加物料模型管理类,遍历物料与resource_model,完成TF数据收集 * 完成TF发布 * 修改模型方向,在yaml中添加变换属性 * 添加物料tf变化时,发送topic到前端 另外修改了物料初始化的方法,防止在tf还未发布时提前建立物料模型与发布话题 * 添加关节发布节点与物料可视化节点进入unilab * 使用json启动plr与3D模型仿真 * 完成启动OT并联动rviz * add 3d visualization * 完成在main中启动设备可视化 完成在main中启动设备可视化,并输出物料ID:mesh的对应关系resource_model 添加物料模型管理类,遍历物料与resource_model,完成TF数据收集 * 完成TF发布 * 修改模型方向,在yaml中添加变换属性 * 添加物料tf变化时,发送topic到前端 另外修改了物料初始化的方法,防止在tf还未发布时提前建立物料模型与发布话题 * 添加关节发布节点与物料可视化节点进入unilab * 使用json启动plr与3D模型仿真 * 完成启动OT并联动rviz * 修复rviz位置问题, 修复rviz位置问题, 在无tf变动时减缓发送频率 在backend中添加物料跟随方法 * fix: running logic * fix: running logic * fix: missing ot * 在main中直接初始化republisher和物料的mesh节点 * 将joint_republisher和resource_mesh_manager添加进 main_slave_run.py中 --------- Co-authored-by: zhangshixiang <@zhangshixiang> Co-authored-by: wznln <18435084+Xuwznln@users.noreply.github.com> * fix: missing hostname in devices_names fix: upload_file for model file * fix: missing paho-mqtt package bump version to 0.9.0 * fix startup add ResourceCreateFromOuter.action * fix type hint * update actions * update actions * host node add_resource_from_outer fix cmake list * pass device config to device class * add: bind_parent_ids to resource create action fix: message convert string * fix: host node should not be re_discovered * feat: resource tracker support dict * feat: add more necessary params * feat: fix boolean null in registry action data * feat: add outer resource * 编写mesh添加action * feat: append resource * add action * feat: vis 2d for plr * fix * fix: browser on rviz * fix: cloud bridge error fallback to local * fix: salve auto run rviz * 初始化两个plate * Device visualization (#22) * add 3d visualization * 完成在main中启动设备可视化 完成在main中启动设备可视化,并输出物料ID:mesh的对应关系resource_model 添加物料模型管理类,遍历物料与resource_model,完成TF数据收集 * 完成TF发布 * 修改模型方向,在yaml中添加变换属性 * 添加物料tf变化时,发送topic到前端 另外修改了物料初始化的方法,防止在tf还未发布时提前建立物料模型与发布话题 * 添加关节发布节点与物料可视化节点进入unilab * 使用json启动plr与3D模型仿真 * 完成启动OT并联动rviz * add 3d visualization * 完成在main中启动设备可视化 完成在main中启动设备可视化,并输出物料ID:mesh的对应关系resource_model 添加物料模型管理类,遍历物料与resource_model,完成TF数据收集 * 完成TF发布 * 修改模型方向,在yaml中添加变换属性 * 添加物料tf变化时,发送topic到前端 另外修改了物料初始化的方法,防止在tf还未发布时提前建立物料模型与发布话题 * 添加关节发布节点与物料可视化节点进入unilab * 使用json启动plr与3D模型仿真 * 完成启动OT并联动rviz * 修复rviz位置问题, 修复rviz位置问题, 在无tf变动时减缓发送频率 在backend中添加物料跟随方法 * fix: running logic * fix: running logic * fix: missing ot * 在main中直接初始化republisher和物料的mesh节点 * 将joint_republisher和resource_mesh_manager添加进 main_slave_run.py中 * 编写mesh添加action * add action * fix * fix: browser on rviz * fix: cloud bridge error fallback to local * fix: salve auto run rviz * 初始化两个plate --------- Co-authored-by: zhangshixiang <@zhangshixiang> Co-authored-by: wznln <18435084+Xuwznln@users.noreply.github.com> * fix: multi channel * fix: aspirate * fix: aspirate * fix: aspirate * fix: aspirate * 提交 * fix: jobadd * fix: jobadd * fix: msg converter * tijiao * add resource creat easy action * identify debug msg * mq client id * unify liquid_handler definition * Update virtual_device.yaml * 更正了stir和heater的连接方式 * 区分了虚拟仪器中的八通阀和电磁阀,添加了两个阀门的驱动 * 修改了add protocol * 修复了阀门更新版的bug * 修复了添加protocol前缀导致的不能启动的bug * Fix handles * bump version to 0.9.6 * add resource edge upload * update container registry and handles * add virtual_separator virtual_rotavap fix transfer_pump * fix container value add parent_name to edge device id * 大图的问题都修复好了,添加了gassource和vacuum pump的驱动以及注册表 * default resource upload mode is false * 添加了icon的文件名在注册表里面 * 修改了json图中link的格式 * fix resource and edge upload * fix device ports * Fix edge id * 移除device的父节点关联 * separate registry sync and resource_add * 默认不进行注册表报送,通过命令unilabos-register或者增加启动参数 * 完善tip * protocol node不再嵌套显示 * bump version to 0.9.7 新增一个测试PumpTransferProtocol的teststation,亲测可以运行,将八通阀们和转移泵与pump_protocol适配 * protocol node 执行action不应携带自身device id * 添加了一套简易双八通阀工作站JSON,亲测能跑 * 修复了很多protocol,亲测能跑 * 添加了run column和filter through的protocol,亲测能跑 * fix mock_reactor * 修改了大图和小图的json,但是在前端上没看到改变 --------- Co-authored-by: Harvey Que <Q-Query@outlook.com> Co-authored-by: wznln <18435084+Xuwznln@users.noreply.github.com> Co-authored-by: zhangshixiang <@zhangshixiang> Co-authored-by: q434343 <73513873+q434343@users.noreply.github.com> Co-authored-by: Junhan Chang <changjh@pku.edu.cn>
147 lines
4.6 KiB
Python
147 lines
4.6 KiB
Python
import time
|
|
import asyncio
|
|
from typing import Union
|
|
|
|
|
|
class VirtualSolenoidValve:
|
|
"""
|
|
虚拟电磁阀门 - 简单的开关型阀门,只有开启和关闭两个状态
|
|
"""
|
|
def __init__(self, device_id: str = None, config: dict = None, **kwargs):
|
|
# 从配置中获取参数,提供默认值
|
|
if config is None:
|
|
config = {}
|
|
|
|
self.device_id = device_id
|
|
self.port = config.get("port", "VIRTUAL")
|
|
self.voltage = config.get("voltage", 12.0)
|
|
self.response_time = config.get("response_time", 0.1)
|
|
|
|
# 状态属性
|
|
self._status = "Idle"
|
|
self._valve_state = "Closed" # "Open" or "Closed"
|
|
self._is_open = False
|
|
|
|
async def initialize(self) -> bool:
|
|
"""初始化设备"""
|
|
self._status = "Idle"
|
|
return True
|
|
|
|
async def cleanup(self) -> bool:
|
|
"""清理资源"""
|
|
return True
|
|
|
|
@property
|
|
def status(self) -> str:
|
|
return self._status
|
|
|
|
@property
|
|
def valve_state(self) -> str:
|
|
return self._valve_state
|
|
|
|
@property
|
|
def is_open(self) -> bool:
|
|
return self._is_open
|
|
|
|
def get_valve_position(self) -> str:
|
|
"""获取阀门位置状态"""
|
|
return "OPEN" if self._is_open else "CLOSED"
|
|
|
|
async def set_valve_position(self, command: str = None, **kwargs):
|
|
"""
|
|
设置阀门位置 - ROS动作接口
|
|
|
|
Args:
|
|
command: "OPEN"/"CLOSED" 或其他控制命令
|
|
"""
|
|
if command is None:
|
|
return {"success": False, "message": "Missing command parameter"}
|
|
|
|
print(f"SOLENOID_VALVE: {self.device_id} 接收到命令: {command}")
|
|
|
|
self._status = "Busy"
|
|
|
|
# 模拟阀门响应时间
|
|
await asyncio.sleep(self.response_time)
|
|
|
|
# 处理不同的命令格式
|
|
if isinstance(command, str):
|
|
cmd_upper = command.upper()
|
|
if cmd_upper in ["OPEN", "ON", "TRUE", "1"]:
|
|
self._is_open = True
|
|
self._valve_state = "Open"
|
|
result_msg = f"Valve {self.device_id} opened"
|
|
elif cmd_upper in ["CLOSED", "CLOSE", "OFF", "FALSE", "0"]:
|
|
self._is_open = False
|
|
self._valve_state = "Closed"
|
|
result_msg = f"Valve {self.device_id} closed"
|
|
else:
|
|
# 可能是端口名称,处理路径设置
|
|
# 对于简单电磁阀,任何非关闭命令都视为开启
|
|
self._is_open = True
|
|
self._valve_state = "Open"
|
|
result_msg = f"Valve {self.device_id} set to position: {command}"
|
|
else:
|
|
self._status = "Error"
|
|
return {"success": False, "message": "Invalid command type"}
|
|
|
|
self._status = "Idle"
|
|
print(f"SOLENOID_VALVE: {result_msg}")
|
|
|
|
return {
|
|
"success": True,
|
|
"message": result_msg,
|
|
"valve_position": self.get_valve_position()
|
|
}
|
|
|
|
async def open(self, **kwargs):
|
|
"""打开电磁阀 - ROS动作接口"""
|
|
return await self.set_valve_position(command="OPEN")
|
|
|
|
async def close(self, **kwargs):
|
|
"""关闭电磁阀 - ROS动作接口"""
|
|
return await self.set_valve_position(command="CLOSED")
|
|
|
|
async def set_state(self, command: Union[bool, str], **kwargs):
|
|
"""
|
|
设置阀门状态 - 兼容 SendCmd 类型
|
|
|
|
Args:
|
|
command: True/False 或 "open"/"close"
|
|
"""
|
|
if isinstance(command, bool):
|
|
cmd_str = "OPEN" if command else "CLOSED"
|
|
elif isinstance(command, str):
|
|
cmd_str = command
|
|
else:
|
|
return {"success": False, "message": "Invalid command type"}
|
|
|
|
return await self.set_valve_position(command=cmd_str)
|
|
|
|
def toggle(self):
|
|
"""切换阀门状态"""
|
|
if self._is_open:
|
|
return self.close()
|
|
else:
|
|
return self.open()
|
|
|
|
def is_closed(self) -> bool:
|
|
"""检查阀门是否关闭"""
|
|
return not self._is_open
|
|
|
|
def get_state(self) -> dict:
|
|
"""获取阀门完整状态"""
|
|
return {
|
|
"device_id": self.device_id,
|
|
"port": self.port,
|
|
"voltage": self.voltage,
|
|
"response_time": self.response_time,
|
|
"is_open": self._is_open,
|
|
"valve_state": self._valve_state,
|
|
"status": self._status,
|
|
"position": self.get_valve_position()
|
|
}
|
|
|
|
async def reset(self):
|
|
"""重置阀门到关闭状态"""
|
|
return await self.close() |