Improve camera status and production startup
This commit is contained in:
+8
-16
@@ -207,16 +207,7 @@ def running_page():
|
||||
def api_status():
|
||||
"""获取系统整体状态"""
|
||||
with gs.lock:
|
||||
# 实际验证机械臂连接(尝试发送一个简单命令)
|
||||
arm_connected = False
|
||||
if gs.arm_client and gs.arm_client._sock:
|
||||
try:
|
||||
# 设置短超时尝试获取角度,验证连接是否有效
|
||||
gs.arm_client._sock.settimeout(2)
|
||||
ok, _ = gs.arm_client.get_angles()
|
||||
arm_connected = ok
|
||||
except:
|
||||
arm_connected = False
|
||||
arm_connected = gs.arm_client.is_connected() if gs.arm_client else False
|
||||
|
||||
# 实际验证 AGV 连接
|
||||
agv_connected = False
|
||||
@@ -239,6 +230,8 @@ def api_status():
|
||||
"camera_opened": gs.camera_opened,
|
||||
"arm_camera_opened": gs.arm_camera_opened,
|
||||
"map_loaded": bool(gs.map_config),
|
||||
"map": gs.map_config,
|
||||
"has_agv_camera": gs.camera_opened,
|
||||
"points_count": len(gs.points_config),
|
||||
"models_count": len(gs.models_config),
|
||||
"mission_rows": gs.mission_config.get("rows", 0),
|
||||
@@ -1111,7 +1104,7 @@ def api_arm_state_off():
|
||||
@app.route("/api/camera/preview")
|
||||
def api_camera_preview():
|
||||
"""MJPEG 视频流"""
|
||||
if not gs.qr_scanner or not gs.qr_scanner._cap:
|
||||
if not gs.qr_scanner or not gs.camera_opened:
|
||||
return "camera not opened", 400
|
||||
|
||||
import time as _time
|
||||
@@ -1137,7 +1130,7 @@ def api_camera_preview():
|
||||
@app.route("/api/camera/capture")
|
||||
def api_camera_capture():
|
||||
"""拍摄一张照片"""
|
||||
if not gs.qr_scanner or not gs.qr_scanner._cap:
|
||||
if not gs.qr_scanner or not gs.camera_opened:
|
||||
return jsonify({"ok": False, "error": "摄像头未打开"}), 400
|
||||
import cv2
|
||||
frame = gs.qr_scanner.read_frame()
|
||||
@@ -2107,7 +2100,7 @@ def api_camera_refresh():
|
||||
"""AGV 摄像头单帧 JPEG(polling 模式)"""
|
||||
if not gs.qr_scanner:
|
||||
return jsonify({"error": "scanner not initialized"}), 400
|
||||
if not gs.qr_scanner._cap or not gs.qr_scanner._cap.isOpened():
|
||||
if not gs.camera_opened:
|
||||
return jsonify({"error": "camera not opened"}), 400
|
||||
import cv2
|
||||
frame = gs.qr_scanner.read_frame()
|
||||
@@ -2126,8 +2119,8 @@ def api_camera_refresh():
|
||||
def api_camera_capabilities():
|
||||
"""返回摄像头能力信息,前端据此决定如何展示"""
|
||||
return jsonify({
|
||||
"has_agv_camera": False, # Orbbec 深度相机不提供可用的彩色画面
|
||||
"has_arm_camera": True,
|
||||
"has_agv_camera": bool(gs.camera_opened),
|
||||
"has_arm_camera": bool(gs.arm_camera_opened),
|
||||
})
|
||||
# ========== 启动 ==========
|
||||
if __name__ == "__main__":
|
||||
@@ -2155,4 +2148,3 @@ if __name__ == "__main__":
|
||||
debug=SERVER_CONFIG["debug"],
|
||||
threaded=True
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user