修复位置和返回问题
This commit is contained in:
+36
-60
@@ -894,77 +894,53 @@ def api_mission_poses_delete(machine_id, side, pose_id):
|
||||
@app.route("/api/mission/generate_sequence", methods=["GET"])
|
||||
def api_mission_generate_sequence():
|
||||
"""根据网格配置和机器配置生成拍摄序列(蛇形)"""
|
||||
rows = gs.mission_config.get("rows", 2)
|
||||
cols = gs.mission_config.get("cols", 3)
|
||||
rows = int(gs.mission_config.get("rows", 2))
|
||||
cols = int(gs.mission_config.get("cols", 3))
|
||||
grid = gs.mission_config.get("grid", [])
|
||||
machines = gs.machines_config
|
||||
|
||||
if (not grid or all(not any(row) if isinstance(row, list) else True for row in grid)) and machines:
|
||||
grid = [[False] * cols for _ in range(rows)]
|
||||
for m in machines:
|
||||
r = int(m.get("row", 0))
|
||||
c = int(m.get("col", 0))
|
||||
if 0 <= r < rows and 0 <= c < cols:
|
||||
grid[r][c] = True
|
||||
|
||||
def get_machine(row, col):
|
||||
for m in machines:
|
||||
if m.get("row") == row and m.get("col") == col:
|
||||
return m
|
||||
return None
|
||||
|
||||
# 蛇形序列:行0从左到右正面→右到左背面,行1从右到左背面→左到右正面...交替
|
||||
# 点位蛇形序列:同一点位同时有上一行背面和下一行正面时,先背面再正面。
|
||||
sequence = []
|
||||
for r in range(rows):
|
||||
# 检查该行是否有机器
|
||||
has_any = any(grid[r][c] for c in range(cols)) if r < len(grid) else False
|
||||
if not has_any:
|
||||
continue
|
||||
|
||||
if r % 2 == 0: # 偶数行:正面从左到右,背面从右到左
|
||||
# 正面:从左到右
|
||||
for c in range(cols):
|
||||
if r < len(grid) and c < len(grid[r]) and grid[r][c]:
|
||||
m = get_machine(r, c)
|
||||
if m and m.get("front"):
|
||||
sequence.append({
|
||||
"machine_id": m["id"],
|
||||
"row": r, "col": c,
|
||||
"side": "front",
|
||||
"row_dir": "lr", # 正面时该行的方向
|
||||
"row_dir_back": "rl" # 背面时该行的方向
|
||||
})
|
||||
# 背面:从右到左
|
||||
for c in range(cols - 1, -1, -1):
|
||||
if r < len(grid) and c < len(grid[r]) and grid[r][c]:
|
||||
m = get_machine(r, c)
|
||||
if m and m.get("back"):
|
||||
sequence.append({
|
||||
"machine_id": m["id"],
|
||||
"row": r, "col": c,
|
||||
"side": "back",
|
||||
"row_dir": "lr",
|
||||
"row_dir_back": "rl"
|
||||
})
|
||||
else: # 奇数行:正面从右到左,背面从左到右(方向反转)
|
||||
# 背面:从左到右(此行的背面在下一行的前面位置,但这里按用户描述:背面先行)
|
||||
for c in range(cols):
|
||||
if r < len(grid) and c < len(grid[r]) and grid[r][c]:
|
||||
m = get_machine(r, c)
|
||||
if m and m.get("back"):
|
||||
sequence.append({
|
||||
"machine_id": m["id"],
|
||||
"row": r, "col": c,
|
||||
"side": "back",
|
||||
"row_dir": "rl",
|
||||
"row_dir_back": "lr"
|
||||
})
|
||||
# 正面:从右到左
|
||||
for c in range(cols - 1, -1, -1):
|
||||
if r < len(grid) and c < len(grid[r]) and grid[r][c]:
|
||||
m = get_machine(r, c)
|
||||
if m and m.get("front"):
|
||||
sequence.append({
|
||||
"machine_id": m["id"],
|
||||
"row": r, "col": c,
|
||||
"side": "front",
|
||||
"row_dir": "rl",
|
||||
"row_dir_back": "lr"
|
||||
})
|
||||
for pr in range(rows + 1):
|
||||
cols_iter = range(cols) if pr % 2 == 0 else range(cols - 1, -1, -1)
|
||||
row_dir = "lr" if pr % 2 == 0 else "rl"
|
||||
for c in cols_iter:
|
||||
if pr > 0 and pr - 1 < len(grid) and c < len(grid[pr - 1]) and grid[pr - 1][c]:
|
||||
m = get_machine(pr - 1, c)
|
||||
if m and m.get("back"):
|
||||
sequence.append({
|
||||
"machine_id": m["id"],
|
||||
"row": pr - 1, "col": c,
|
||||
"point_row": pr,
|
||||
"side": "back",
|
||||
"row_dir": row_dir
|
||||
})
|
||||
if pr < rows and pr < len(grid) and c < len(grid[pr]) and grid[pr][c]:
|
||||
m = get_machine(pr, c)
|
||||
if m and m.get("front"):
|
||||
sequence.append({
|
||||
"machine_id": m["id"],
|
||||
"row": pr, "col": c,
|
||||
"point_row": pr,
|
||||
"side": "front",
|
||||
"row_dir": row_dir
|
||||
})
|
||||
|
||||
return json
|
||||
return jsonify({"ok": True, "sequence": sequence})
|
||||
|
||||
# ========== 点位配置 API(独立于机器)==========
|
||||
@app.route("/api/mission/positions", methods=["GET"])
|
||||
|
||||
Reference in New Issue
Block a user