feat(扫描): 发布车架J6优先复扫提速独立方案
从原J6交错优化版V8复制新方案,原方案及历史任务保留。 每组RX先按原方向仅J6负90度完整扫描,再恢复本组J6和原RPY复扫原XYZ点集。 扫描速度保持长边80、短边100毫米每秒;扫描加速度默认80可调,非采集入场150毫米每秒。 保留200毫米退让、连续停稳、真实关节限位和原位跳过检查。 新增独立维护生成器、规划源码和中文发布说明;独立方案V1已发布,平台无需重启。 离线图、引用、原点集与边界检查通过;未下发现场设备动作。
This commit is contained in:
parent
be3a35724b
commit
cc7183dff4
33
deploy/windows11/RELEASE-20261127-frame-j6-first.md
Normal file
33
deploy/windows11/RELEASE-20261127-frame-j6-first.md
Normal file
@ -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²加速工况。已有任务及夹具默认方案不会自动改用副本,应在扫描准备中选择此新方案。
|
||||
163
scripts/frame_scan/build_j6_first.mjs
Normal file
163
scripts/frame_scan/build_j6_first.mjs
Normal file
@ -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 <source-snapshot.json> <flow.json> [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<object>', [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 }))
|
||||
215
scripts/frame_scan/j6-first-planner.js
Normal file
215
scripts/frame_scan/j6-first-planner.js
Normal file
@ -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;i<keys.length;i++)if(!finite(p[keys[i]]))throw new Error('实际TCP位姿无效');
|
||||
return p;
|
||||
}
|
||||
function pose(p,speed) {return {x:p.x,y:p.y,z:p.z,rx:p.rx,ry:p.ry,rz:p.rz,velocity:speed};}
|
||||
// Only suppress a redundant approach, before submission, after two real stationary readbacks.
|
||||
// Same tolerance as ArmShortMoveCompletion: 0.05mm / 0.0001rad.
|
||||
// The two actual readbacks must still be stationary and drift by at most 0.02mm.
|
||||
function samePose(a,b) {
|
||||
var dx=a.x-b.x,dy=a.y-b.y,dz=a.z-b.z;
|
||||
if(dx*dx+dy*dy+dz*dz>0.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;i<keys.length;i++)if(!finite(t[keys[i]])||Math.abs(t[keys[i]])>0.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<keys.length;i++) {
|
||||
var difference=a[keys[i]]-b[keys[i]];
|
||||
if(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;i<keys.length;i++)if(!finite(value[keys[i]]))fail(label+'的TCP位姿数值无效');
|
||||
return value;
|
||||
}
|
||||
function stamp(reference,current) {if(!reference||!finite(reference.stamp)||current<reference.stamp)throw new Error('动作回读时间与本阶段准备记录不一致');}
|
||||
function pointList(v) {
|
||||
if(!Array.isArray(v)||v.length<2||v.length>202||v.length%2!==0)throw new Error('扫描条带点集无效');
|
||||
for(var i=0;i<v.length;i++) {
|
||||
var p=v[i],keys=['x','y','z','rx','ry','rz','velocity'];
|
||||
if(!p)throw new Error('扫描点为空');
|
||||
for(var j=0;j<keys.length;j++)if(!finite(p[keys[j]]))throw new Error('扫描点数值无效');
|
||||
if(p.y<0.456||p.z< -0.3-1e-10||!(p.velocity>0))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;i<input.length;i++) {
|
||||
var p=pose(input[i],input[i].velocity);
|
||||
if(flip)p.x=input[i%2===0?i+1:i-1].x;
|
||||
p.rx=orientation.rx;p.ry=orientation.ry;p.rz=orientation.rz;
|
||||
list.push(p);
|
||||
}
|
||||
candidates.push(list);candidates.push(list.slice(0).reverse());
|
||||
}
|
||||
for(var c=0;c<candidates.length;c++) {
|
||||
var first=candidates[c][0],dx=first.x-current.x,dz=first.z-current.z,cost=dx*dx+dz*dz;
|
||||
if(cost<bestCost){bestCost=cost;best=candidates[c];}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
function scanPlan(input,current,orientation) {
|
||||
// Entry is outside acquisition; the saved scan-point speeds remain unchanged.
|
||||
var points=ordered(input,current,orientation),entry=pose(points[0],0.15),hover=pose(points[0],0.15);
|
||||
hover.y-=0.2;
|
||||
return {points:points,scanPoints:points.slice(1),hover:hover,hoverMoves:confirmedMoves(hover,current),entry:entry,count:points.length};
|
||||
}
|
||||
var actual=state(params.state),q=params.state.actualJointState.position,now=params.state.timestamp;
|
||||
if(params.mode==='offset_initial') {
|
||||
jointMatch(q,params.initialJoints);
|
||||
var initialRetreat=pose(actual,0.15);initialRetreat.y-=0.2;
|
||||
return {retreatPose:initialRetreat,stamp:now};
|
||||
}
|
||||
if(params.mode==='offset_after_restore') {
|
||||
stamp(params.restore,now);stamp(params.offset,now);jointMatch(q,params.restore.target);
|
||||
var withdrawn=pose(actual,0.15);
|
||||
// Restore can shift the TCP; return to the previous withdrawn Y, do not subtract 200mm twice.
|
||||
withdrawn.y=params.offset.retreatPose.y;
|
||||
return {retreatPose:withdrawn,retreatMoves:confirmedMoves(withdrawn,actual),stamp:now};
|
||||
}
|
||||
if(params.mode==='offset') {
|
||||
var completed=pointList(params.completedPoints);
|
||||
poseMatch(actual,completed[completed.length-1]);
|
||||
// Anchor the withdrawal to the completed planned endpoint. Actual feedback is
|
||||
// checked above; its micrometre tracking error must not move the next anchor.
|
||||
var retreat=pose(completed[completed.length-1],0.15);retreat.y-=0.2;
|
||||
retreat.rx=actual.rx;retreat.ry=actual.ry;retreat.rz=actual.rz;
|
||||
return {retreatPose:retreat,stamp:now};
|
||||
}
|
||||
if(params.mode==='rx_target') {
|
||||
stamp(params.offset,now);poseMatch(actual,params.offset.retreatPose);
|
||||
if(params.rx!==-2&¶ms.rx!==-1.1)throw new Error('RX目标必须为-2或-1.1rad');
|
||||
var target=pose(actual,0.06);target.rx=params.rx;
|
||||
if(params.referenceRotation) {
|
||||
stamp(params.referenceRotation,now);
|
||||
var reference=params.referenceRotation.targetPose;
|
||||
if(!reference||!finite(reference.ry)||!finite(reference.rz))throw new Error('缺少未转J6的原姿态基准');
|
||||
target.ry=reference.ry;target.rz=reference.rz;
|
||||
}
|
||||
return {targetPose:target,stamp:now};
|
||||
}
|
||||
if(params.mode==='rx_scan') {
|
||||
stamp(params.rotation,now);poseMatch(actual,params.rotation.targetPose);
|
||||
var points=pointList(params.points),rx=params.rotation.targetPose.rx,lo=params.minZMm/1000,hi=params.maxZMm/1000;
|
||||
if(!finite(lo)||!finite(hi)||hi<lo||(rx===-2&&Math.abs(lo+0.15)>1e-10)||(rx===-1.1&&Math.abs(lo+0.3)>1e-10))throw new Error('RX扫描Z范围无效');
|
||||
for(var i=0;i<points.length;i++)if(points[i].rx!==rx||points[i].z<lo-1e-10||points[i].z>hi+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)||hi<lo)throw new Error('J6换向扫描Z范围无效');
|
||||
for(var i=0;i<list.length;i++)if(list[i].z<lo-1e-10||list[i].z>hi+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('末点换姿态规划模式无效');
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user