75 lines
3.8 KiB
JavaScript
75 lines
3.8 KiB
JavaScript
// E15: review the ABB work station (no new geometry) on top of E14.
|
||
import fs from "node:fs";
|
||
import path from "node:path";
|
||
import { createSceneRunner } from "../../../carrier-course/lib/scene.mjs";
|
||
import { saveCheckpoint } from "../../../carrier-course/lib/ui-actions.mjs";
|
||
import { openLineReference, selectReferenceModel, spec } from "../../lib/ui.mjs";
|
||
import { checkLineCheckpoint } from "../../lib/line-precision.mjs";
|
||
|
||
export async function run({ page, rec, script, stillsDir, rawDir, webRoot }) {
|
||
const scene = createSceneRunner({ rec, page, script });
|
||
const shot = name => rec.shot(stillsDir, name);
|
||
const log = [];
|
||
const logStep = entry => {
|
||
log.push({ at: new Date().toISOString(), ...entry });
|
||
fs.writeFileSync(path.join(rawDir, "live-log.json"), `${JSON.stringify(log, null, 2)}\n`);
|
||
};
|
||
const course = JSON.parse(fs.readFileSync(path.join(webRoot, "tools", "line-course", "course.json"), "utf8"));
|
||
const episode = course.episodes.find(item => item.id === "E15");
|
||
const expectedNames = episode.checkpointObjects;
|
||
|
||
await scene("S00", async () => { await shot("S00-title"); });
|
||
|
||
await scene("S01", async () => {
|
||
for (let attempt = 0; attempt < 120; attempt++) {
|
||
const labels = await page.locator(".fc-tree-text").allTextContents();
|
||
if (labels.filter(label => expectedNames.includes(label)).length >= expectedNames.length) break;
|
||
await page.waitForTimeout(500);
|
||
}
|
||
const labels = await page.locator(".fc-tree-text").allTextContents();
|
||
logStep({ step: "checkpoint", objects: labels.length });
|
||
if (labels.filter(label => expectedNames.includes(label)).length < expectedNames.length)
|
||
throw new Error(`E14 checkpoint incomplete: ${labels.length} labels`);
|
||
await shot("S01-checkpoint");
|
||
});
|
||
|
||
await scene("S02", async () => {
|
||
const panel = await openLineReference(page);
|
||
const robot = await selectReferenceModel(panel, page, "ABB IRB 120 机器人", /0\.22 × 0\.69 × 0\.70/);
|
||
const light = await selectReferenceModel(panel, page, "三色警示灯", /0\.05 × 0\.04 × 0\.47/);
|
||
const tool = await selectReferenceModel(panel, page, "工具坐标系", /0\.07 × 0\.07 × 0\.07/);
|
||
logStep({ step: "reference", robot, light, tool });
|
||
await shot("S02-reference");
|
||
});
|
||
|
||
await scene("S03", async () => {
|
||
// Orbit the main viewport to inspect the robot from a second angle.
|
||
const view = page.locator('[aria-label="Imported native 3D view"]').first();
|
||
const box = await view.boundingBox();
|
||
if (box) {
|
||
const x = box.x + box.width / 2; const y = box.y + box.height / 2;
|
||
await page.mouse.move(x, y); await page.mouse.down();
|
||
await page.mouse.move(x - 140, y - 40, { steps: 18 }); await page.mouse.up();
|
||
await page.waitForTimeout(500);
|
||
}
|
||
logStep({ step: "review", robot: spec().models.find(model => model.name === "ABB_IRB_120").overallDims });
|
||
await shot("S03-robot");
|
||
});
|
||
|
||
await scene("S04", async () => {
|
||
const saved = await saveCheckpoint({ page, rec, webRoot, episode: "E15", rawDir,
|
||
checkpointDir: path.join(webRoot, "tools", "line-course", "checkpoints"),
|
||
expectedLabels: expectedNames });
|
||
logStep({ step: "checkpoint", ...saved });
|
||
const checkpoint = path.join(webRoot, "tools", "line-course", "checkpoints", "E15.FCStd");
|
||
const precision = await checkLineCheckpoint(checkpoint, expectedNames);
|
||
fs.writeFileSync(path.join(rawDir, "E15-precision.json"), `${JSON.stringify(precision, null, 2)}\n`);
|
||
if (!precision.ok) throw new Error(`precision failed: ${JSON.stringify({ extra: precision.extra,
|
||
models: precision.models.filter(item => !item.ok) })}`);
|
||
fs.writeFileSync(path.join(rawDir, "E15-state.json"), `${JSON.stringify({
|
||
schema: "freecad-web-line-course/E15/state/v1", generatedAt: new Date().toISOString(), precision, log,
|
||
}, null, 2)}\n`);
|
||
await shot("S04-recap");
|
||
});
|
||
}
|