am-freescan/scripts/frame_scan/build_layered_length_scan.mjs
Codex 549f0d499a feat(扫描): 发布四站独立长度逐层工具Z交替90度方案
四站分别输入长度A和距离2,X边界为正负(A/2+200mm),实际横扫N层。
先扫RX=-2并抬高下限200mm,再扫RX=-1.1并降低上限200mm。
工具自身Z每层正反90度交替,保持换层姿态和实际末点退让。
保留同样本停稳检查、既有安全动作与17/0.5扫描参数,独立发布V1。
2026-11-27 19:40:19 +08:00

72 lines
5.6 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_length_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-length-generator.js', import.meta.url), 'utf8')
const plannerCode = fs.readFileSync(new URL('./layered-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有效高度均为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,上限不变;RX=-1.1上限=整体最高Z-200,下限不变。'
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+200,负端X=-A/2-200。首层从正端开始,后续蛇形。' })
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+200mm),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'))
}
}
let helperCount = 0
for (const n of graph.nodes) {
if (mode(n)) { set(n, 'code', input('code', plannerCode)); helperCount++ }
if (n.properties.name) n.properties.name = n.properties.name.replaceAll('工具Z摆扫', '逐层工具Z交替90°').replaceAll('往复120°', '逐层正反90°').replaceAll('近端衔接', '正X首层衔接')
}
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.type !== 'start') assert.deepEqual(n.properties.nodeParams, 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+200','-A/2-200'], 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))