am-freescan/scripts/frame_scan/build_layered_y50_scan.mjs
Codex ae84b872f8 feat(扫描): 发布Y退50低位副本并统一点间距默认0.7
独立副本采用RX=-2范围最低加200、最高加100,RX=-1.1最低减100、最高减300。
四站逐层工具Z正反90度,切换姿态Y退50毫米,X端余量100毫米。
13个已发布方案及任务、新扫描组件默认点间距统一0.7,激光亮度保持原值。
保留旧路径、显式任务参数和冻结版本,补充迁移保护、既有回归及中文发布记录。
2026-11-27 21:08:11 +08:00

92 lines
7.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import fs from 'node:fs'
import assert from 'node:assert/strict'
// Offline independent derivative. Saving requires a NEW method/flow identity.
// This program does not publish, move equipment, or modify the source snapshot.
const [sourcePath, outputPath, summaryPath] = process.argv.slice(2)
if (!sourcePath || !outputPath) throw new Error('Usage: node build_layered_y50_scan.mjs <V3-snapshot.json> <flow.json> [summary.json]')
const source = JSON.parse(fs.readFileSync(sourcePath, 'utf8').replace(/^\uFEFF/, ''))
assert.equal(source.published.id, '89e71764f2ec94c5c212fd00cce15947', 'Review another source before deriving a graph')
const original = JSON.parse(source.published.flowData), graph = structuredClone(original)
assert.equal(graph.nodes.length, 291)
const params = n => n.properties.nodeParams || []
const mode = n => params(n).find(p => p.name === 'mode')?.input
const input = (name, value) => ({ name, type: 'input', input: value, required: true, disabled: true })
const field = (name, type) => ({ name, type, children: [], required: true })
function set(n, name, value) {
const index = params(n).findIndex(p => p.name === name)
if (index < 0) n.properties.nodeParams.push(value)
else n.properties.nodeParams[index] = value
}
const start = graph.nodes.find(n => n.type === 'start')
const generator = graph.nodes.find(n => params(n).some(p => p.name === 'LM302_param2_mm') && params(n).some(p => p.name === 'scan_layers'))
assert(start && generator)
const generatorCode = fs.readFileSync(new URL('./layered-y50-length-generator.js', import.meta.url), 'utf8')
const plannerCode = fs.readFileSync(new URL('./layered-y50-tool-z-planner.js', import.meta.url), 'utf8')
assert(plannerCode.includes('// LAYERED_TOOL_Z'))
const startFields = new Map(start.properties.inputParams.map(p => [p.name, p]))
startFields.get('scan_height_mm').desc = '参考高度H(mm);参考最高Z=输入最低Z+H。RX=-2有效高度H-100,RX=-1.1有效高度H-200;需H>200且两组相邻层均至少2mm。'
startFields.get('scan_layers').desc = '每个RX实际横扫层数N,2至100整数,包含该组最低和最高层;第一层工具Z正转90°,第二层反转90°,逐层交替。'
startFields.get('scan_start_z_mm').desc = '输入参考最低Z(mm,默认-222,不低于-300);RX=-2下限=此值+200,上限=参考最高Z+100;RX=-1.1下限=此值-100,上限=参考最高Z-300。默认输入时RX=-1.1最低为-322mm,须确认实际可达。'
const orderedFields = ['long_scan_speed', 'short_scan_speed', 'fixtureFrameworkUrls', 'scan_start_z_mm', 'scan_height_mm', 'scan_layers'].map(name => startFields.get(name))
for (const station of ['LM302', 'LM304', 'LM306', 'LM308']) {
const name = station + '_length_mm'
orderedFields.push({ name, type: 'number', children: [], required: true, desc: station + ' 长度A(mm,正数);以机械臂Base X=0为中心,正端X=A/2+100,负端X=-A/2-100。首层从正端开始,后续蛇形。' })
orderedFields.push(startFields.get(station + '_param2_mm'))
set(generator, name, { name, type: 'quote', input: '', quote: [start.id, 'input', name], quoteType: 'input', required: true, disabled: true })
}
orderedFields.push(startFields.get('scan_acceleration_mm'))
assert(orderedFields.every(Boolean))
start.properties.inputParams = orderedFields
start.properties.name = '四站独立长度、距离2与实际层数'
set(generator, 'code', input('code', generatorCode))
generator.properties.name = '四站中心对称X与两组RX高度范围(每组实际N层)'
generator.properties.desc = '各站X边界±(A/2+100mm),Base X=0须现场对准样品中心。Y=距离2-232mm;RX=-2先扫,RX=-1.1再扫;N是横扫层数,保留最低和最高层。'
for (const station of generator.properties.outputParams.find(p => p.name === 'result').children) {
for (const name of ['lengthMm', 'xFirstMm', 'xLastMm', 'yMm', 'layerCount', 'layerStepMm', 'rx2StepMm', 'rx11StepMm', 'overallMinZMm', 'overallMaxZMm', 'scanHeightMm']) {
assert(!station.children.some(p => p.name === name))
station.children.push(field(name, 'number'))
}
station.children.find(p => p.name === 'layerStepMm').desc = '两组中较小的层距;各组实际层距分别为rx2StepMm和rx11StepMm。'
station.children.find(p => p.name === 'overallMinZMm').desc = '输入参考最低Z;RX=-1.1实际下限比此值低100mm。'
}
let helperCount = 0
for (const n of graph.nodes) {
if (mode(n)) { set(n, 'code', input('code', plannerCode)); helperCount++ }
if (n.properties.action === 'SCANNER_PARAMETERS') {
const request = params(n).find(p => p.name === 'requestJson')
assert.equal(request?.type, 'input')
const body = JSON.parse(request.input)
assert.deepEqual(Object.keys(body).sort(), ['brightness', 'pointDistance'])
request.input = JSON.stringify({ ...body, pointDistance: 0.7 }, null, 2)
}
if (n.properties.name) n.properties.name = n.properties.name.replaceAll('工具Z摆扫', '逐层工具Z交替90°').replaceAll('往复120°', '逐层正反90°').replaceAll('近端衔接', '正X首层衔接').replaceAll('Y退200mm', 'Y退50mm').replaceAll('Y-200mm', 'Y-50mm')
}
assert.equal(helperCount, 28)
assert.equal(graph.nodes.filter(n => n.properties.action === 'SCANNER_START').length, 8)
assert.equal(graph.nodes.filter(n => n.properties.action === 'SCANNER_STOP').length, 8)
assert.equal(graph.nodes.filter(n => params(n).some(p => p.name === 'resultNodeId')).length, 8)
assert.equal(graph.nodes.filter(n => n.properties.action === 'ARM_MOVE_TO_J').length, 8, 'Only original initial/safety joint movements may remain')
// Preserve all RPC settings, strict loop exports, scanner defaults, and graph topology.
assert.deepEqual(graph.edges, original.edges)
for (let i = 0; i < graph.nodes.length; i++) {
const n = graph.nodes[i], before = original.nodes[i]
assert.equal(n.id, before.id)
if (n.properties.action !== 'CODE' && n.properties.action !== 'SCANNER_PARAMETERS' && n.type !== 'start') assert.deepEqual(n.properties.nodeParams, before.properties.nodeParams)
if (n.properties.action === 'SCANNER_PARAMETERS') {
const check = structuredClone(n.properties.nodeParams)
const old = params(before).find(p => p.name === 'requestJson')
const body = JSON.parse(params(n).find(p => p.name === 'requestJson').input)
assert.equal(body.pointDistance, 0.7)
delete body.pointDistance
const prior = JSON.parse(old.input); delete prior.pointDistance
assert.deepEqual(body, prior, 'Keep the original brightness')
check.find(p => p.name === 'requestJson').input = old.input
assert.deepEqual(check, before.properties.nodeParams)
}
}
fs.writeFileSync(outputPath, JSON.stringify(graph, null, 2))
const summary = { nodes: graph.nodes.length, sourceVersion: 3, captures: 8, stations: ['LM302','LM304','LM306','LM308'], rxOrder: [-2,-1.1], lengthInputs: 4, actualRowCountInput: 'scan_layers', xBoundaries: ['A/2+100','-A/2-100'], retreatYMm: -50, rx2MinOffsetMm: 200, rx2MaxOffsetMm: 100, rx11MinOffsetMm: -100, rx11MaxOffsetMm: -300, rowToolAnglesDeg: [[0,90],[90,0]], toolAxis: 'local Z', requiresNewMethodIdentity: true, published: false, deviceCommandsSent: 0 }
if (summaryPath) fs.writeFileSync(summaryPath, JSON.stringify(summary, null, 2))
console.log(JSON.stringify(summary))