起点X改为A/2+100,负端X改为-A/2-100,并同步参数说明。 仅发布独立逐层工具Z方案V2,保留V1历史。 核对1776个点的非X字段及完整图差异,Z、层数、姿态、速度和安全动作不变。
72 lines
5.6 KiB
JavaScript
72 lines
5.6 KiB
JavaScript
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+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'))
|
||
}
|
||
}
|
||
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+100','-A/2-100'], 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))
|