纠正上一版直接累加基座Euler RZ的坐标轴理解,使用基准姿态右乘局部Z轴旋转。 保持每站RX负二优先、8次单遍采集、原Base XYZ路径和速度,工具自转0到120度再回0。 新增独立工具轴规划与更新器,处理等价Euler分支和奇异表示,以矩阵和四元数校验工具轴及姿态间隔。 同一独立方案已发布V2并标明工具Z名称,原V1冻结图和历史任务保留,平台无需重启。 独立Rodrigues、几何和平台图验证通过,未下发现场设备动作。
46 lines
3.7 KiB
JavaScript
46 lines
3.7 KiB
JavaScript
import fs from 'node:fs'
|
||
import assert from 'node:assert/strict'
|
||
|
||
// Offline correction of a reviewed derivative. Never publishes or executes a device.
|
||
const [sourcePath, outputPath, summaryPath] = process.argv.slice(2)
|
||
if (!sourcePath || !outputPath) throw new Error('Usage: node build_tool_z_sweep.mjs <published-snapshot.json> <flow.json> [summary.json]')
|
||
const snapshot = JSON.parse(fs.readFileSync(sourcePath, 'utf8').replace(/^\uFEFF/, ''))
|
||
const sourceText = snapshot.published?.flowData || snapshot.flowData || JSON.stringify(snapshot)
|
||
const before = JSON.parse(sourceText), graph = structuredClone(before)
|
||
const previousHelper = fs.readFileSync(new URL('./rz-sweep-planner.js', import.meta.url), 'utf8')
|
||
const helper = fs.readFileSync(new URL('./tool-z-sweep-planner.js', import.meta.url), 'utf8')
|
||
assert(helper.includes('// TOOL_Z_RIGHT_MULTIPLY'), 'The tool-local rotation implementation is required')
|
||
assert.equal(graph.nodes.length, 315, 'Review the derivative layout before applying the tool-axis correction')
|
||
let changedPlanners = 0
|
||
for (const node of graph.nodes) {
|
||
const mode = node.properties.nodeParams?.find(parameter => parameter.name === 'mode')?.input
|
||
if (mode) {
|
||
assert(['offset_initial', 'rx_target', 'scan', 'offset'].includes(mode), 'Unexpected planner mode')
|
||
const code = node.properties.nodeParams.find(parameter => parameter.name === 'code')
|
||
assert.equal(code?.input.replaceAll('\r\n', '\n'), previousHelper.replaceAll('\r\n', '\n'), 'Source is not the reviewed Base-RZ V1 helper')
|
||
code.input = helper; changedPlanners++
|
||
}
|
||
node.properties.name = node.properties.name.replaceAll('RZ摆扫', '工具Z摆扫').replaceAll('同步RZ往复', '同步工具Z往复').replaceAll('未转J6完整扫描', '工具Z摆扫单遍')
|
||
}
|
||
assert.equal(changedPlanners, 28)
|
||
const start = graph.nodes.find(node => node.type === 'start')
|
||
start.properties.inputParams.find(parameter => parameter.name === 'scan_layers').desc = '每站先RX=-2再RX=-1.1,每个RX区域单遍;X/Z按原路径平移,绕本组初始末端工具自身Z轴自转0→120°→0,整片一次往复,不专门转J6或重复扫描。'
|
||
const pathGenerator = graph.nodes.find(node => node.properties.name.startsWith('保留原两组RX的完整XYZ点集'))
|
||
assert(pathGenerator)
|
||
pathGenerator.properties.desc = '原XYZ点生成不改。先设置本组RX基准,再在原平移路径中绕末端工具自身Z轴往复;基座RPY可随姿态换算联动。'
|
||
// Besides code and descriptive metadata, all topology, inputs, XYZ sources, targets and timings are identical.
|
||
const restore = structuredClone(graph)
|
||
for (let index = 0; index < restore.nodes.length; index++) {
|
||
const old = before.nodes[index], current = restore.nodes[index]
|
||
current.properties.name = old.properties.name
|
||
if (Object.hasOwn(old.properties, 'desc')) current.properties.desc = old.properties.desc
|
||
if (current.type === 'start') current.properties.inputParams = structuredClone(old.properties.inputParams)
|
||
const mode = current.properties.nodeParams?.find(parameter => parameter.name === 'mode')?.input
|
||
if (mode) current.properties.nodeParams.find(parameter => parameter.name === 'code').input = old.properties.nodeParams.find(parameter => parameter.name === 'code').input
|
||
}
|
||
assert.deepEqual(restore, before)
|
||
fs.writeFileSync(outputPath, JSON.stringify(graph, null, 2))
|
||
const summary = { nodes: graph.nodes.length, changedPlanners, toolLocalAxis: 'Z', rotationComposition: 'R_reference * Rz(theta)', cycleDegrees: [0, 120, 0], captures: graph.nodes.filter(node => node.properties.action === 'SCANNER_START').length, xyzAndTopologyPreserved: true, deviceCommandsSent: 0 }
|
||
if (summaryPath) fs.writeFileSync(summaryPath, JSON.stringify(summary, null, 2))
|
||
console.log(JSON.stringify(summary))
|