From cc7183dff4e7f8ce5c7429e39ef4a702ce8d8ac4 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 27 Nov 2026 13:37:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=89=AB=E6=8F=8F):=20=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E8=BD=A6=E6=9E=B6J6=E4=BC=98=E5=85=88=E5=A4=8D=E6=89=AB?= =?UTF-8?q?=E6=8F=90=E9=80=9F=E7=8B=AC=E7=AB=8B=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 从原J6交错优化版V8复制新方案,原方案及历史任务保留。 每组RX先按原方向仅J6负90度完整扫描,再恢复本组J6和原RPY复扫原XYZ点集。 扫描速度保持长边80、短边100毫米每秒;扫描加速度默认80可调,非采集入场150毫米每秒。 保留200毫米退让、连续停稳、真实关节限位和原位跳过检查。 新增独立维护生成器、规划源码和中文发布说明;独立方案V1已发布,平台无需重启。 离线图、引用、原点集与边界检查通过;未下发现场设备动作。 --- .../RELEASE-20261127-frame-j6-first.md | 33 +++ scripts/frame_scan/build_j6_first.mjs | 163 +++++++++++++ scripts/frame_scan/j6-first-planner.js | 215 ++++++++++++++++++ 3 files changed, 411 insertions(+) create mode 100644 deploy/windows11/RELEASE-20261127-frame-j6-first.md create mode 100644 scripts/frame_scan/build_j6_first.mjs create mode 100644 scripts/frame_scan/j6-first-planner.js diff --git a/deploy/windows11/RELEASE-20261127-frame-j6-first.md b/deploy/windows11/RELEASE-20261127-frame-j6-first.md new file mode 100644 index 0000000..91ac987 --- /dev/null +++ b/deploy/windows11/RELEASE-20261127-frame-j6-first.md @@ -0,0 +1,33 @@ +# 车架独立副本:先J6换向,再恢复原姿态复扫 + +## 方案身份与范围 + +- 名称:车架扫描方案-参数化自动路径 - J6优先复扫提速版。 +- 方法ID:`92f0d10f5f9b49eeb82161358891393c`。 +- 独立流程ID:`bdd647b867c66d6daf8613443f1b8f82`。 +- 来源:方法 `edd56edb527541a88596689a5bfd4789`、流程 `ff944df2e4faca6370531faee734cdb9` 的发布V8(`aa96410688d7a57881f62e2d27b7cbfe`)。原方案、原发布版本、已有任务冻结快照和夹具默认关联保留。 +- 用户本次明确指令后已发布独立V1,发布版本ID:`97ea2d7aad7215d5ea9e5663e170fbe4`。发布冻结快照与审核草稿一致,原方案仍为V8。未执行现场设备。 + +## 扫描顺序 + +原4站LM302/304/306/308,每站RX=-1.1、-2共8组,每组仍完整扫描两遍。保持原坐标、分层、范围、采集点与RX基准,不增加独立顶面路径。 + +每组先在原退让位置设置本组RX,连续确认停稳,读取实测关节及本次真实六轴限位,仅将J6按原方向减90°。第一遍按实际转后姿态和原XYZ集合选择近端进入;完成后按本遍规划末点退Y200mm,再仅恢复本组转前J6。恢复后保留当前XYZ,复用既有退让Y,并在退让平面复核/必要校正本组原RPY,然后按原XYZ集合完整复扫。最后退让,切下组RX或回原安全位换站。 + +J6恢复后当前前五轴保持实测值,因此不能假定TCP已恢复原RPY或原退让XYZ。副本显式保存原RPY基准,使用恢复后的新实读规划第二遍;不引用尚未执行的原姿态扫描末点。无角度自动折返、运动重发或坐标系替换。 + +## 提速参数 + +- 扫描速度仍为长边80、短边100mm/s,可输入正数;没有新增速度上限。 +- 新增扫描加速度输入 `scan_acceleration_mm`,默认80mm/s²,原方案为40mm/s²;可按现场稳定性和点云质量调整为正数。所有16个采集循环使用此值,逐点零融合保持。 +- 不采集的进入首点速度从扫描速度改为150mm/s,与原有退让/衔接速度一致。开始采集仍在进入首点完成之后,采集点速度不变。 +- 保留原端点/行序的近端选择、已经实际到位时跳过空移动。保留200mm退让、250ms两帧间隔、连续停稳门及120秒业务期限,不把期限当固定等待删除。 +- 不对实际总耗时作承诺。J6换向、恢复、原RPY必要校正及扫描处理仍有开销;加速度变化属于新的动态工况,需要现场检查。 + +## 维护与验证 + +`scripts/frame_scan/build_j6_first.mjs` 只从来源发布快照离线生成副本;`j6-first-planner.js` 为副本独立规划源码。原 `phase-planner.js` 和原方案不修改。 + +真实平台图构建器通过956节点图检查;独立检查覆盖1255处引用、子图与分支、8组顺序、16对采集、原点生成器及安全动作保持。纯函数验证包含1/6/100层下24组模拟、实际恢复点变化、J6限位、过期/异常状态拒绝及原位跳过;没有运行机械臂、AGV或扫描仪。验证不证明真实整条轨迹可达或点云质量。 + +只使用现有平台组件,无新依赖、私有配置或数据库迁移,本次方案发布无需重启平台。发布已核对草稿修订与原版本;现场运行须重新确认实物装夹并检查J6方向、限位、非采集入场与80mm/s²加速工况。已有任务及夹具默认方案不会自动改用副本,应在扫描准备中选择此新方案。 diff --git a/scripts/frame_scan/build_j6_first.mjs b/scripts/frame_scan/build_j6_first.mjs new file mode 100644 index 0000000..c0c6ddf --- /dev/null +++ b/scripts/frame_scan/build_j6_first.mjs @@ -0,0 +1,163 @@ +import fs from 'node:fs' +import crypto from 'node:crypto' +import assert from 'node:assert/strict' + +// Offline derivative. Never edits, publishes or executes its source flow. +const [sourcePath, outputPath, summaryPath] = process.argv.slice(2) +if (!sourcePath || !outputPath) throw new Error('Usage: node build_j6_first.mjs [summary.json]') +const snapshot = JSON.parse(fs.readFileSync(sourcePath, 'utf8').replace(/^\uFEFF/, '')) +const original = JSON.parse(snapshot.published?.flowData || snapshot.flowData || JSON.stringify(snapshot)) +const graph = structuredClone(original), byId = new Map(graph.nodes.map(node => [node.id, node])) +const order = [] +for (let node = graph.nodes.find(node => node.type === 'start'); node;) { + assert(!order.includes(node), 'Source main chain has a cycle'); order.push(node) + const edges = graph.edges.filter(edge => edge.sourceNodeId === node.id) + assert(edges.length <= 1, 'Unexpected main branch') + node = edges.length ? byId.get(edges[0].targetNodeId) : null +} +assert.equal(graph.nodes.length, 698, 'Review source layout before generating another revision') +assert.equal(order.length, 374) +const uid = () => crypto.randomUUID().replaceAll('-', '') +const params = node => node.properties.nodeParams || [] +const mode = node => params(node).find(field => field.name === 'mode')?.input +const input = (name, value) => ({ name, type: 'input', input: value, required: true, disabled: true }) +const quote = (name, node, ...path) => ({ name, type: 'quote', input: '', quote: [node.id || node, 'output', ...path], quoteType: 'output', required: true, disabled: true }) +const field = (name, type, children = []) => ({ name, type, children, required: true }) +const set = (node, name, value) => { + const index = params(node).findIndex(parameter => parameter.name === name) + if (index < 0) node.properties.nodeParams.push(value); else node.properties.nodeParams[index] = value +} +const add = node => { graph.nodes.push(node); byId.set(node.id, node); return node } +const newEdges = [] +function closure(roots) { + const nodes = new Set() + function visit(node) { if (nodes.has(node)) return; nodes.add(node); for (const id of node.children || []) visit(byId.get(id)) } + roots.forEach(visit); return [...nodes] +} +function cloneBlock(roots) { + const nodes = closure(roots), ids = new Map(nodes.map(node => [node.id, uid()])) + const replace = value => { + let text = JSON.stringify(value) + for (const [before, after] of ids) text = text.replaceAll(before, after) + return JSON.parse(text) + } + for (const node of nodes) add(replace(node)) + for (const edge of graph.edges.filter(edge => ids.has(edge.sourceNodeId) && ids.has(edge.targetNodeId))) newEdges.push({ ...replace(edge), id: uid() }) + return roots.map(node => byId.get(ids.get(node.id))) +} +function settle(preparation, label) { + assert.equal(preparation.length, 5) + assert.deepEqual(preparation.map(node => node.type), ['code', 'loop', 'serviceNode', 'sleep', 'serviceNode']) + const copy = cloneBlock(preparation) + copy.forEach((node, index) => { node.properties.name = label + [' 开始连续停稳', ' 连续停稳门(120秒)', ' 首帧', ' 回读间隔(250ms)', ' 第二帧'][index] }) + return { nodes: copy, first: copy[2], last: copy[4] } +} +function codeCopy(template, name, operation, parameters) { + const node = cloneBlock([template])[0] + node.properties.name = name + node.properties.nodeParams = [input('mode', operation), ...parameters, params(template).find(field => field.name === 'code')] + return node +} +const helper = fs.readFileSync(new URL('./j6-first-planner.js', import.meta.url), 'utf8') +const plannerTemplate = graph.nodes.find(node => mode(node) === 'offset_after_restore') +assert(plannerTemplate) +const poseFields = ['x', 'y', 'z', 'rx', 'ry', 'rz', 'velocity'].map(name => field(name, 'number')) +const options = add({ id: uid(), type: 'code', x: 0, y: 0, properties: { + name: '扫描加速度(默认80mm/s²;扫描速度仍80/100)', action: 'CODE', nodeParams: [ + { name: 'scan_acceleration_mm', type: 'quote', input: '', quote: [order[0].id, 'input', 'scan_acceleration_mm'], quoteType: 'input', required: true, disabled: true }, + input('code', 'function handler(params) { var value=params.scan_acceleration_mm; if(typeof value!=="number"||!isFinite(value)||value<=0)throw new Error("扫描加速度必须为正数"); return {scanAcceleration:value/1000}; }') + ], outputType: 'json', outputParams: [field('result', 'object', [field('scanAcceleration', 'number')])] +} }) +// A new run reads the controller's real limits; no hard-coded ranges or angle wrapping. +const info = add({ id: uid(), type: 'serviceNode', x: 0, y: 0, properties: { + name: '读取本次六轴真实关节限位', action: 'ARM_GET_ARM_INFO', nodeType: 'EDGE', + executionTarget: structuredClone(order.find(node => node.properties.action === 'ARM_MOVE_TO_J').properties.executionTarget), + nodeParams: [input('timeoutMs', 120000)], outputType: 'json', outputParams: [field('jointLimits', 'array', [field('jointName', 'string'), field('positionLimitsAvailable', 'boolean'), field('lower', 'number'), field('upper', 'number')])] +} }) +const groups = [], replacements = new Map() +for (const [groupIndex, rotation] of order.filter(node => mode(node) === 'rx_target').entries()) { + const start = order.indexOf(rotation), baseIndex = order.findIndex((node, index) => index > start && mode(node) === 'rx_scan') + const turnIndex = order.findIndex((node, index) => index > start && mode(node) === 'j6_target') + const turnedIndex = order.findIndex((node, index) => index > start && mode(node) === 'j6_scan') + const restoreIndex = order.findIndex((node, index) => index > start && mode(node) === 'j6_restore') + const verifyIndex = order.findIndex((node, index) => index > restoreIndex && mode(node) === 'verify_restore') + const nextRotation = order.findIndex((node, index) => index > start && mode(node) === 'rx_target') + const last = groupIndex % 2 === 0 ? nextRotation - 1 : verifyIndex + const label = rotation.properties.name.split(' 在退让处')[0] + const base = order[baseIndex], turn = order[turnIndex], turned = order[turnedIndex], restore = order[restoreIndex], verify = order[verifyIndex] + const firstPreparation = order.slice(baseIndex - 5, baseIndex) + const baseCapture = order.slice(baseIndex, baseIndex + 6), turnWithdrawal = order.slice(baseIndex + 6, turnIndex) + const turnedPreparation = order.slice(turnedIndex - 5, turnedIndex), turnedCapture = order.slice(turnedIndex, turnedIndex + 6) + const restoreWithdrawal = order.slice(turnedIndex + 6, restoreIndex) + assert.equal(turnWithdrawal.length, 4); assert.equal(restoreWithdrawal.length, 4) + assert.equal(baseCapture.at(-1).properties.action, 'SCANNER_STOP'); assert.equal(turnedCapture.at(-1).properties.action, 'SCANNER_STOP') + const first = settle(firstPreparation, label + ' 首遍J6换向前') + set(turn, 'mode', input('mode', 'j6_first')) + turn.properties.nodeParams = params(turn).filter(parameter => parameter.name !== 'offset') + set(turn, 'state', quote('state', first.last, 'state')); set(turn, 'previousState', quote('previousState', first.first, 'state')) + set(turn, 'rotation', quote('rotation', rotation, 'result')); set(turn, 'jointLimits', quote('jointLimits', info, 'jointLimits')) + turn.properties.name = label + ' 首遍仅J6-90°(沿用原方向)' + turnWithdrawal.forEach(node => { node.properties.name = node.properties.name.replace('J6换向', '原姿态复扫结束') }) + set(restore, 'jointLimits', quote('jointLimits', info, 'jointLimits')) + const afterRestore = settle(firstPreparation, label + ' J6恢复后') + set(verify, 'state', quote('state', afterRestore.last, 'state')) + const correction = codeCopy(plannerTemplate, label + ' 复用既有退让Y,不重复退让', 'offset_after_restore', [quote('state', afterRestore.last, 'state'), quote('previousState', afterRestore.first, 'state'), quote('restore', restore, 'result'), quote('offset', restoreWithdrawal[1], 'result')]) + const originalCorrectionLoop = order.find(node => node.type === 'loop' && params(node).some(parameter => parameter.name === 'loopNum' && parameter.quote?.[0] === plannerTemplate.id)) + assert(originalCorrectionLoop) + const correctionLoop = cloneBlock([originalCorrectionLoop])[0] + correctionLoop.properties.name = label + ' 已到退让Y则跳过' + set(correctionLoop, 'loopNum', quote('loopNum', correction, 'result', 'retreatMoves')) + const correctionRead = cloneBlock(firstPreparation.slice(2)) + correctionRead[0].properties.name = label + ' 原姿态校正前首帧' + correctionRead[2].properties.name = label + ' 原姿态校正前第二帧' + const orientation = codeCopy(plannerTemplate, label + ' 在退让平面恢复本组原RPY', 'base_orientation', [quote('state', correctionRead[2], 'state'), quote('previousState', correctionRead[0], 'state'), quote('offset', correction, 'result'), quote('rotation', rotation, 'result')]) + const result = orientation.properties.outputParams.find(parameter => parameter.name === 'result') + result.children.push(field('orientationMoves', 'array', poseFields)) + const orientationLoop = cloneBlock([originalCorrectionLoop])[0] + orientationLoop.properties.name = label + ' 原RPY已恢复则跳过校正' + set(orientationLoop, 'loopNum', quote('loopNum', orientation, 'result', 'orientationMoves')) + set(base, 'rotation', quote('rotation', orientation, 'result')) + base.properties.name = label + ' 恢复原姿态后完整复扫路径' + for (const node of closure([...firstPreparation, ...baseCapture])) node.properties.name = node.properties.name.replaceAll('未转J6', '恢复原姿态') + // Preserve the original route, scope, capture count and J6 restoration. Only swap passes. + const nodes = [rotation, order[start + 1], ...first.nodes, turn, order[turnIndex + 1], ...turnedPreparation, ...turnedCapture, + ...restoreWithdrawal, restore, order[restoreIndex + 1], ...afterRestore.nodes, verify, correction, correctionLoop, + ...correctionRead, orientation, orientationLoop, ...firstPreparation, ...baseCapture, ...turnWithdrawal] + replacements.set(start, { last, nodes }) + // The following RX starts at this newly completed base pass, never a future/old result. + if (groupIndex % 2 === 0) { + set(order[nextRotation], 'state', quote('state', turnWithdrawal[3], 'state')) + set(order[nextRotation], 'offset', quote('offset', turnWithdrawal[1], 'result')) + } + groups.push({ label, rx: params(rotation).find(parameter => parameter.name === 'rx').input, first: turned.id, second: base.id, turn: turn.id, restore: restore.id, originalRotation: rotation.id, finalWithdrawal: turnWithdrawal[1].id }) +} +assert.equal(groups.length, 8) +const main = [] +for (let index = 0; index < order.length;) { + if (replacements.has(index)) { const block = replacements.get(index); main.push(...block.nodes); index = block.last + 1 } + else { main.push(order[index]); if (index === 0) main.push(options); if (index === 11) main.push(info); index++ } +} +const start = main[0] +start.properties.inputParams.push({ name: 'scan_acceleration_mm', type: 'number', children: [], desc: '扫描加速度(mm/s²),默认80;原方案40,可按现场质量与稳定性调整为正数。', input: 80, required: true }) +start.properties.inputParams.find(parameter => parameter.name === 'scan_layers').desc = '每组RX完整扫两遍:先仅J6-90°扫描,再恢复原J6及原RPY完整复扫;不拆奇偶层。' +order[1].properties.name = '两组RX各完整两遍(先J6-90°,恢复后原姿态复扫)' +order[1].properties.desc = '保持原两组RX、XYZ范围与完整分层;每组先J6-90°扫一遍,再恢复本组原J6及原RPY完整复扫。仅调整两遍顺序,不拆分奇偶层。' +const retained = new Set(closure(main).map(node => node.id)), mainIds = new Set(main.map(node => node.id)) +graph.nodes = graph.nodes.filter(node => retained.has(node.id)) +graph.edges = [...graph.edges, ...newEdges].filter(edge => retained.has(edge.sourceNodeId) && retained.has(edge.targetNodeId) && !mainIds.has(edge.sourceNodeId) && !mainIds.has(edge.targetNodeId)) +graph.edges.push(...main.slice(0, -1).map((node, index) => ({ id: uid(), type: 'bezier', sourceNodeId: node.id, targetNodeId: main[index + 1].id, sourceAnchorId: node.id + '_1', targetAnchorId: main[index + 1].id + '_3' }))) +for (const node of graph.nodes) { + if (mode(node)) set(node, 'code', input('code', helper)) + if (node.properties.action === 'ARM_MOVE_TO_POINT' && node.properties.parentId) { + const parent = byId.get(node.properties.parentId) + if (parent?.properties.name.includes('完整扫描') && !parent.properties.name.includes('衔接')) set(node, 'acceleration', quote('acceleration', options, 'result', 'scanAcceleration')) + } +} +main.forEach((node, index) => { node.x = index * 320; node.y = 220 }) +assert.equal(graph.nodes.filter(node => node.properties.action === 'SCANNER_START').length, 16) +assert.equal(graph.nodes.filter(node => node.properties.action === 'SCANNER_STOP').length, 16) +assert.equal(JSON.stringify(original), JSON.stringify(JSON.parse(snapshot.published?.flowData || snapshot.flowData || JSON.stringify(snapshot)))) +fs.writeFileSync(outputPath, JSON.stringify(graph, null, 2)) +const summary = { nodes: graph.nodes.length, edges: graph.edges.length, groups, scanAccelerationMm: 80, travelEntrySpeedMm: 150, scanSpeedsUnchanged: true, sourceUntouched: true, deviceCommandsSent: 0 } +if (summaryPath) fs.writeFileSync(summaryPath, JSON.stringify(summary, null, 2)) +console.log(JSON.stringify({ ...summary, groups: groups.length })) diff --git a/scripts/frame_scan/j6-first-planner.js b/scripts/frame_scan/j6-first-planner.js new file mode 100644 index 0000000..fff134d --- /dev/null +++ b/scripts/frame_scan/j6-first-planner.js @@ -0,0 +1,215 @@ +// Independent J6-first variant. No device command is submitted by this code. +// All poses are absolute Base TCP poses in metres/radians. +function handler(params) { + function finite(v) { return typeof v==='number' && isFinite(v); } + function fail(message) { throw new Error(message); } + function joints(v) { + if(typeof v==='string')v=JSON.parse(v); + if(!Array.isArray(v)||v.length!==6)throw new Error('实际关节角必须为六个数值'); + for(var i=0;i<6;i++)if(!finite(v[i]))throw new Error('关节角无效'); + return v; + } + function state(s) { + if(!s||s.connected!==true||s.poweredOn!==true||s.brakeReleased!==true||s.moving!==false||s.programRunning!==false||s.protectiveStopped!==false||s.emergencyStopped!==false||s.fault!==false)throw new Error('机械臂未确认连接、上电和安全停稳'); + if(!finite(s.timestamp)||Math.abs(Date.now()/1000-s.timestamp)>10)throw new Error('末点换姿态的实际回读状态已过期'); + joints(s.actualJointState&&s.actualJointState.position); + var p=s.actualTcpPose; + if(!p)throw new Error('缺少实际TCP位姿'); + var keys=['x','y','z','rx','ry','rz']; + for(var i=0;i0.00005*0.00005)return false; + function quaternion(p) { + var x=p.rx/2,y=p.ry/2,z=p.rz/2,cx=Math.cos(x),sx=Math.sin(x),cy=Math.cos(y),sy=Math.sin(y),cz=Math.cos(z),sz=Math.sin(z); + return [sx*cy*cz-cx*sy*sz,cx*sy*cz+sx*cy*sz,cx*cy*sz-sx*sy*cz,cx*cy*cz+sx*sy*sz]; + } + var qa=quaternion(a),qb=quaternion(b),minus=0,plus=0; + for(var i=0;i<4;i++){minus+=(qa[i]-qb[i])*(qa[i]-qb[i]);plus+=(qa[i]+qb[i])*(qa[i]+qb[i]);} + var angle=4*Math.asin(Math.min(1,Math.sqrt(Math.min(minus,plus))/2)); + return angle<=0.0001; + } + function confirmedMoves(target,current) { + if(!samePose(current,target))return [target]; + var previous=state(params.previousState),before=params.previousState,after=params.state; + var dt=after.timestamp-before.timestamp,dx=previous.x-current.x,dy=previous.y-current.y,dz=previous.z-current.z; + if(dt<0.2||dt>2||!samePose(previous,target)||!samePose(previous,current)||dx*dx+dy*dy+dz*dz>0.00002*0.00002)throw new Error('重复衔接点缺少连续到位回读,停止发送空移动'); + var snapshots=[before,after]; + for(var k=0;k<2;k++) { + var s=snapshots[k],v=s.actualJointState.velocity,t=s.actualTcpVelocity; + if(s.robotMode!=='ARM_ROBOT_MODE_IDLE'||s.safetyMode!=='ARM_SAFETY_MODE_NORMAL'||s.controlMode!=='ARM_CONTROL_MODE_POSITION'||!Array.isArray(v)||v.length!==6||!t)throw new Error('重复衔接点尚未确认位置控制与安全停稳'); + for(var i=0;i<6;i++)if(!finite(v[i])||Math.abs(v[i])>0.001)throw new Error('重复衔接点的关节尚未停稳'); + var keys=['vx','vy','vz','wx','wy','wz']; + for(var i=0;i0.0001)throw new Error('重复衔接点的末端尚未停稳'); + } + var q1=joints(before.actualJointState.position),q2=joints(after.actualJointState.position); + for(var i=0;i<6;i++)if(Math.abs(q1[i]-q2[i])/dt>0.001)throw new Error('重复衔接点的关节回读不稳定'); + return []; + } + function poseMatch(a,b) { + var keys=['x','y','z','rx','ry','rz']; + for(var i=0;i=3)difference=Math.atan2(Math.sin(difference),Math.cos(difference)); + if(Math.abs(difference)>(i<3?0.003:0.015))throw new Error('未到指定末点、退让位置或姿态,停止后续动作'); + } + } + function jointMatch(a,b) {a=joints(a);b=joints(b);for(var i=0;i<6;i++)if(Math.abs(a[i]-b[i])>0.015)throw new Error('J6或其他关节未按目标到位');} + function checkLimits(target, original, limits, names) { + if (typeof limits === 'string') { + try { limits = JSON.parse(limits); } catch (error) { fail('运行时关节限位不是有效数组'); } + } + if (!Array.isArray(limits) || limits.length !== 6) fail('缺少六轴运行时真实关节限位,禁止J6换向'); + var named = false; + for (var i = 0; i < 6; i++) if (limits[i] && limits[i].jointName) named = true; + if (named && (!Array.isArray(names) || names.length !== 6)) fail('关节限位带名称,但实际关节名称不完整'); + for (var i = 0; i < 6; i++) { + var limit = limits[i]; + if (named) { + var found = null, count = 0; + if (typeof names[i] !== 'string' || !names[i]) fail('实际关节名称无效'); + for (var j = 0; j < 6; j++) if (limits[j] && limits[j].jointName === names[i]) { found = limits[j]; count++; } + if (count !== 1) fail('运行时关节限位名称缺失或重复:' + names[i]); + for (var j = 0; j < i; j++) if (names[j] === names[i]) fail('实际关节名称重复'); + limit = found; + } + if (!limit || limit.positionLimitsAvailable === false || !finite(limit.lower) || !finite(limit.upper) || limit.lower >= limit.upper) + fail('J' + (i + 1) + '运行时位置限位不可用'); + if (original[i] < limit.lower || original[i] > limit.upper || target[i] < limit.lower || target[i] > limit.upper) + fail('J' + (i + 1) + '目标超出运行时真实关节限位;禁止自动折返或包裹角度'); + } + } + function requiredPose(value, label) { + var keys=['x','y','z','rx','ry','rz']; + if(!value)fail(label+'缺少完整TCP位姿'); + for(var i=0;i202||v.length%2!==0)throw new Error('扫描条带点集无效'); + for(var i=0;i0))throw new Error('扫描点超出本轮坐标约束或速度无效'); + if(i%2===1&&(Math.abs(p.y-v[i-1].y)>1e-10||Math.abs(p.z-v[i-1].z)>1e-10))throw new Error('横扫条带两端不在同一Y/Z'); + } + return v; + } + // Only reorder the original rows/endpoints; never interpolate new scan coordinates. + function ordered(input,current,orientation) { + input=pointList(input); + var candidates=[],best=null,bestCost=1e100; + for(var flip=0;flip<2;flip++) { + var list=[]; + for(var i=0;i1e-10)||(rx===-1.1&&Math.abs(lo+0.3)>1e-10))throw new Error('RX扫描Z范围无效'); + for(var i=0;ihi+1e-10)throw new Error('RX路径超出指定扫描区间'); + return scanPlan(points,actual,params.rotation.targetPose); + } + if(params.mode==='j6_first') { + confirmedMoves(actual,actual); + stamp(params.rotation,now); + poseMatch(actual,requiredPose(params.rotation.targetPose,'本组原RX姿态')); + var firstOriginal=joints(q).slice(0),firstTarget=firstOriginal.slice(0); + firstTarget[5]-=Math.PI/2; + checkLimits(firstTarget,firstOriginal,params.jointLimits,params.state.actualJointState.name); + return {target:JSON.stringify(firstTarget),originalJoints:JSON.stringify(firstOriginal),stamp:now}; + } + if(params.mode==='base_orientation') { + confirmedMoves(actual,actual); + stamp(params.offset,now);stamp(params.rotation,now); + poseMatch(actual,requiredPose(params.offset.retreatPose,'本组恢复后退让位置')); + var reference=requiredPose(params.rotation.targetPose,'本组原RX姿态'),baseTarget=pose(actual,0.06); + baseTarget.rx=reference.rx;baseTarget.ry=reference.ry;baseTarget.rz=reference.rz; + return {targetPose:baseTarget,stamp:now,orientationMoves:confirmedMoves(baseTarget,actual)}; + } + if(params.mode==='j6_target') { + stamp(params.offset,now);poseMatch(actual,params.offset.retreatPose); + var original=joints(q).slice(0),target=q.slice(0);target[5]-=Math.PI/2; + return {target:JSON.stringify(target),originalJoints:JSON.stringify(original),stamp:now}; + } + if(params.mode==='j6_scan') { + stamp(params.turn,now);jointMatch(q,params.turn.target); + var list=pointList(params.points),lo=params.minZMm/1000,hi=params.maxZMm/1000; + if(!finite(lo)||!finite(hi)||hihi+1e-10)throw new Error('J6换向扫描超出本组RX范围'); + return scanPlan(params.points,actual,actual); + } + if(params.mode==='j6_restore') { + stamp(params.offset,now);stamp(params.turn,now);poseMatch(actual,params.offset.retreatPose); + var original=joints(params.turn.originalJoints),turned=joints(params.turn.target),target=q.slice(0); + if(Math.abs(q[5]-turned[5])>Math.PI||Math.abs(q[5]-original[5])>Math.PI)throw new Error('J6偏离本次换向分支,禁止跨越大角度恢复'); + target[5]=original[5]; + if(params.jointLimits!==undefined)checkLimits(target,joints(q),params.jointLimits,params.state.actualJointState.name); + return {target:JSON.stringify(target),stamp:now}; + } + if(params.mode==='verify_restore') { + stamp(params.restore,now);jointMatch(q,params.restore.target); + return {restored:true}; + } + throw new Error('末点换姿态规划模式无效'); +}