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>
172 lines
6.1 KiB
Python
172 lines
6.1 KiB
Python
"""
|
||
Web页面模块
|
||
|
||
提供系统Web界面的页面定义
|
||
"""
|
||
|
||
import json
|
||
import os
|
||
import sys
|
||
from pathlib import Path
|
||
from typing import Dict
|
||
|
||
from fastapi import APIRouter, HTTPException
|
||
from fastapi.responses import HTMLResponse, JSONResponse
|
||
from jinja2 import Environment, FileSystemLoader
|
||
|
||
from unilabos.config.config import BasicConfig
|
||
from unilabos.registry.registry import lab_registry
|
||
from unilabos.ros.msgs.message_converter import msg_converter_manager
|
||
from unilabos.utils.log import error
|
||
from unilabos.utils.type_check import TypeEncoder
|
||
from unilabos.app.web.utils.device_utils import get_registry_info
|
||
from unilabos.app.web.utils.host_utils import get_host_node_info
|
||
from unilabos.app.web.utils.ros_utils import get_ros_node_info, update_ros_node_info
|
||
|
||
# 设置Jinja2模板环境
|
||
template_dir = Path(__file__).parent / "templates"
|
||
env = Environment(loader=FileSystemLoader(template_dir))
|
||
|
||
|
||
def setup_web_pages(router: APIRouter) -> None:
|
||
"""
|
||
设置Web页面路由
|
||
|
||
Args:
|
||
router: FastAPI路由器实例
|
||
"""
|
||
# 在web服务启动时,尝试初始化ROS节点信息
|
||
update_ros_node_info()
|
||
|
||
@router.get("/", response_class=HTMLResponse, summary="Home Page")
|
||
async def home_page() -> str:
|
||
"""
|
||
首页,显示所有可用的API路由
|
||
|
||
Returns:
|
||
HTMLResponse: 渲染后的HTML页面
|
||
"""
|
||
try:
|
||
# 收集所有路由
|
||
routes = []
|
||
for route in router.routes:
|
||
if hasattr(route, "methods") and hasattr(route, "path"):
|
||
for method in list(getattr(route, "methods", [])):
|
||
path = getattr(route, "path", "")
|
||
# 只显示GET方法的路由作为链接
|
||
if method == "GET":
|
||
name = getattr(route, "name", "") or path
|
||
summary = getattr(route, "summary", "") or name
|
||
routes.append({"method": method, "path": path, "name": name, "summary": summary})
|
||
|
||
# 使用模板渲染页面
|
||
template = env.get_template("home.html")
|
||
html = template.render(routes=routes)
|
||
|
||
return html
|
||
except Exception as e:
|
||
error(f"生成主页时出错: {str(e)}")
|
||
raise HTTPException(status_code=500, detail=f"Error generating home page: {str(e)}")
|
||
|
||
@router.get("/status", response_class=HTMLResponse, summary="System Status")
|
||
async def status_page() -> str:
|
||
"""
|
||
状态页面,显示系统状态信息
|
||
|
||
Returns:
|
||
HTMLResponse: 渲染后的HTML页面
|
||
"""
|
||
try:
|
||
# 准备设备数据
|
||
devices = []
|
||
resources = []
|
||
modules = {"names": [], "classes": [], "displayed_count": 0, "total_count": 0}
|
||
|
||
# 获取在线设备信息
|
||
ros_node_info = get_ros_node_info()
|
||
# 获取主机节点信息
|
||
host_node_info = get_host_node_info()
|
||
# 获取Registry路径信息
|
||
registry_info = get_registry_info()
|
||
|
||
# 获取已加载的设备
|
||
if lab_registry:
|
||
devices = json.loads(json.dumps(lab_registry.obtain_registry_device_info(), ensure_ascii=False, cls=TypeEncoder))
|
||
# 资源类型
|
||
for resource_id, resource_info in lab_registry.resource_type_registry.items():
|
||
resources.append(
|
||
{
|
||
"id": resource_id,
|
||
"name": resource_info.get("name", "未命名"),
|
||
"file_path": resource_info.get("file_path", ""),
|
||
}
|
||
)
|
||
|
||
# 获取导入的模块
|
||
if msg_converter_manager:
|
||
modules["names"] = msg_converter_manager.list_modules()
|
||
all_classes = [i for i in msg_converter_manager.list_classes() if "." in i]
|
||
modules["total_count"] = len(all_classes)
|
||
modules["classes"] = all_classes
|
||
|
||
# 使用模板渲染页面
|
||
template = env.get_template("status.html")
|
||
html = template.render(
|
||
devices=devices,
|
||
resources=resources,
|
||
modules=modules,
|
||
is_host_mode=BasicConfig.is_host_mode,
|
||
registry_info=registry_info,
|
||
ros_node_info=ros_node_info,
|
||
host_node_info=host_node_info,
|
||
)
|
||
|
||
return html
|
||
except Exception as e:
|
||
error(f"生成状态页面时出错: {str(e)}")
|
||
raise HTTPException(status_code=500, detail=f"Error generating status page: {str(e)}")
|
||
|
||
@router.get("/open-folder", response_class=JSONResponse, summary="Open Local Folder")
|
||
async def open_folder(path: str = "") -> Dict[str, str]:
|
||
"""
|
||
打开本地文件夹
|
||
|
||
Args:
|
||
path: 要打开的文件夹路径
|
||
|
||
Returns:
|
||
JSONResponse: 操作结果
|
||
|
||
Raises:
|
||
HTTPException: 如果路径为空或不存在
|
||
"""
|
||
if not path:
|
||
return {"status": "error", "message": "Path is empty"}
|
||
|
||
try:
|
||
# 规范化路径
|
||
norm_path = os.path.normpath(path)
|
||
|
||
# 如果是文件路径,获取其目录
|
||
if os.path.isfile(norm_path):
|
||
norm_path = os.path.dirname(norm_path)
|
||
|
||
# 检查路径是否存在
|
||
if not os.path.exists(norm_path):
|
||
return {"status": "error", "message": f"Path does not exist: {norm_path}"}
|
||
|
||
# Windows
|
||
if os.name == "nt":
|
||
os.startfile(norm_path)
|
||
# macOS
|
||
elif sys.platform == "darwin":
|
||
os.system(f'open "{norm_path}"')
|
||
# Linux
|
||
else:
|
||
os.system(f'xdg-open "{norm_path}"')
|
||
|
||
return {"status": "success", "message": f"Opened folder: {norm_path}"}
|
||
except Exception as e:
|
||
error(f"打开文件夹时出错: {str(e)}")
|
||
return {"status": "error", "message": f"Failed to open folder: {str(e)}"}
|