From 1d4942847be4807fd48e3e6bf2513f6ce8b8fe36 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 27 Nov 2026 14:08:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=89=AB=E6=8F=8F):=20=E5=8F=91=E5=B8=83R?= =?UTF-8?q?X=E8=B4=9F=E4=BA=8C=E4=BC=98=E5=85=88=E7=9A=84=E8=BD=A6?= =?UTF-8?q?=E6=9E=B6RZ=E5=90=8C=E6=AD=A5=E6=91=86=E6=89=AB=E6=96=B9?= =?UTF-8?q?=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增独立副本,每站先RX=-2再RX=-1.1,各采集一遍,共8遍。 取消专门J6换向、单轴恢复和重复扫,避免起点J6作为末点恢复目标的错误规划假设。 保留原XYZ顶点与直线路径,在正常平移段同步完成RZ初始到加120度再回初始的一次往复。 姿态关键帧角差不超过10度,极短换层保持RZ,保留退让、停稳和原安全动作。 独立方案V1已发布,原V8、J6优先V1及历史任务保持。 图构建、引用、几何和角度边界离线验证通过;未运行现场设备,平台无需重启。 --- .../RELEASE-20261127-frame-rz-sweep.md | 33 +++ scripts/frame_scan/build_rz_sweep.mjs | 109 +++++++++ scripts/frame_scan/rz-sweep-planner.js | 220 ++++++++++++++++++ 3 files changed, 362 insertions(+) create mode 100644 deploy/windows11/RELEASE-20261127-frame-rz-sweep.md create mode 100644 scripts/frame_scan/build_rz_sweep.mjs create mode 100644 scripts/frame_scan/rz-sweep-planner.js diff --git a/deploy/windows11/RELEASE-20261127-frame-rz-sweep.md b/deploy/windows11/RELEASE-20261127-frame-rz-sweep.md new file mode 100644 index 0000000..9f478b2 --- /dev/null +++ b/deploy/windows11/RELEASE-20261127-frame-rz-sweep.md @@ -0,0 +1,33 @@ +# 车架独立副本:RX=-2优先,X/Z同步RZ摆扫 + +## 方法与来源 + +- 名称:车架扫描方案-参数化自动路径 - RX-2优先RZ摆扫版。 +- 方法ID:`a3d44bacd1be4a9b97a6315bcca86f50`;流程ID:`5e2bddeeb05fb181296b4721ba6dd9bc`。 +- 用户本次明确指令后已发布独立V1,发布版本ID:`44c3cbcfdd54dd8b84f419138ae2c3f7`。冻结快照与验证草稿一致;未运行现场设备。 +- 原车架J6交错优化版V8(方法`edd56edb527541a88596689a5bfd4789`,流程`ff944df2e4faca6370531faee734cdb9`)和J6优先版V1(方法`92f0d10f5f9b49eeb82161358891393c`,流程`bdd647b867c66d6daf8613443f1b8f82`)均保持。失败任务和历史冻结版本不修改,夹具默认关联不自动切换。 + +## 本次失败原因 + +EX-20261127-0004在日志26289的CODE恢复检查失败,尚未下发恢复运动。转前Q6为+0.4658846303rad,负90°目标为-1.1049116965rad;整片笛卡尔扫描结束后Q6为-2.3547186809rad,随后Y退200mm成功,恢复前为-2.9255809403rad。直接恢复起点Q6需要跨194.32°,触发原大角度恢复保护。实读为IDLE/NORMAL/POSITION、静止、无fault,六轴实际限位为±2π。 + +笛卡尔扫描和退让期间,关节解随位置及姿态变化;起点Q6不能直接作为末点的单轴恢复目标。新副本按用户新策略删除专门的J6换向、恢复和第二遍扫描,不删除旧方案保护,不伪造历史执行成功。 + +## 路径与姿态 + +- 保留原4站LM302/304/306/308,逐站先RX=-2,再RX=-1.1。每个RX区域只完整采集一遍,共8次。 +- XYZ点生成源码保持。RX=-2仍为Z[-150,原最高Z]mm;RX=-1.1仍为[-300,原最高Z-200]mm,原X端点、Y距离公式及分层保持。原8个站初始/退出安全关节动作与4个AGV动作保持。 +- 每片先选原点集的近端方向,再沿原直线边运动。RX固定该组值,RY固定本站原基准,RZ在扫描中从本站初始值逐渐加120°,再回到初始值,整片一次往复。扫描前入场和扫描后退让不计入摆扫进度。 +- 为表达有向的平移/转动,必要时只在原直线边插入共线姿态关键点,保留全部原顶点和转角。相邻RZ差不超过10°,RZ逻辑值保持展开、不逐点wrap。到位检查用四元数等价角误差,允许回读使用等价的±π/2π表示。 +- 原不足2mm换层边不增加RZ变化,将摆角按正常长边累计弧长分配。峰值接近原顶点时吸附至该顶点;每个有RZ变化的生成子段仍需至少约2mm。避免新增极短平移、大姿态变化的运动;不猜测当前RPC将线速度改解释成角速度,也不混传单位。 +- 起点/终点RZ严格回初始,峰值为初始+120°,总角度变化240°且仅一个往复。原200mm退让、实际停稳、新鲜时间、原位跳过证明和逐点零融合保持。 + +## 参数、兼容性及验证 + +扫描速度沿用长边80、短边100mm/s,扫描加速度默认80mm/s²可调,非采集入场/退让150mm/s;扫描仪默认亮度17、点间距0.5保持。 + +维护源码为`scripts/frame_scan/build_rz_sweep.mjs`和`rz-sweep-planner.js`,只离线生成,不自动保存、发布或执行设备。只使用现有MoveL等平台组件,无新依赖、私有配置或数据库迁移;本次方案发布无需重启平台。 + +离线检查:真实图构建器接受315节点图;483处引用的字段、作用域和先后顺序有效;8个采集对、RX顺序、原点生成器及安全动作逐项通过。144组独立几何/姿态模拟覆盖最小高度、1/6/100层、大Z范围、跨±π初始RZ;另504组边界组合及12项拒绝测试通过。校验全部原顶点、共线且有序细分、短段角度、单次0→120→0、速度保持、等价姿态回读及退让。 + +当前协议没有独立只读逆解或整条轨迹可达预检接口,离线检查不能证明新增RZ姿态的真实全路径可达、线缆与遮挡或点云质量。正式发布后,应使用新任务选该方案并低速逐段核对;已有失败任务的冻结方案不自动改变。 diff --git a/scripts/frame_scan/build_rz_sweep.mjs b/scripts/frame_scan/build_rz_sweep.mjs new file mode 100644 index 0000000..0369335 --- /dev/null +++ b/scripts/frame_scan/build_rz_sweep.mjs @@ -0,0 +1,109 @@ +import fs from 'node:fs' +import crypto from 'node:crypto' +import assert from 'node:assert/strict' + +// Offline derivative only. Source methods, frozen versions and devices are untouched. +const [sourcePath, outputPath, summaryPath] = process.argv.slice(2) +if (!sourcePath || !outputPath) throw new Error('Usage: node build_rz_sweep.mjs [summary.json]') +const snapshot = JSON.parse(fs.readFileSync(sourcePath, 'utf8').replace(/^\uFEFF/, '')) +const sourceText = snapshot.published?.flowData || snapshot.flowData || JSON.stringify(snapshot) +const original = JSON.parse(sourceText), graph = structuredClone(original) +const byId = new Map(graph.nodes.map(node => [node.id, node])), 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 another source revision before generating this derivative') +assert.equal(order.length, 374) +const params = node => node.properties.nodeParams || [] +const mode = node => params(node).find(parameter => parameter.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, 'output', ...path], quoteType: 'output', required: true, disabled: 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 helper = fs.readFileSync(new URL('./rz-sweep-planner.js', import.meta.url), 'utf8') +const start = order[0], pathGenerator = order[1] +const options = { id: crypto.randomUUID().replaceAll('-', ''), type: 'code', x: 0, y: 0, properties: { + name: '扫描加速度(默认80mm/s²)', action: 'CODE', nodeParams: [ + { name: 'scan_acceleration_mm', type: 'quote', input: '', quote: [start.id, 'input', 'scan_acceleration_mm'], quoteType: 'input', required: true, disabled: true }, + input('code', 'function handler(params){var v=params.scan_acceleration_mm;if(typeof v!=="number"||!isFinite(v)||v<=0)throw new Error("扫描加速度必须为正数");return {scanAcceleration:v/1000};}') + ], outputType: 'json', outputParams: [{ name: 'result', type: 'object', required: true, children: [{ name: 'scanAcceleration', type: 'number', required: true, children: [] }] }] +} } +graph.nodes.push(options); byId.set(options.id, options) +const stationIndices = order.flatMap((node, index) => node.properties.action === 'AGV_MOVE_TO_STATION' ? [index] : []) +assert.equal(stationIndices.length, 4) +const main = [start, options, ...order.slice(1, stationIndices[0])], groups = [] +for (let stationIndex = 0; stationIndex < 4; stationIndex++) { + const begin = stationIndices[stationIndex], station = order[begin].properties.name + const end = stationIndex < 3 ? stationIndices[stationIndex + 1] : order.findIndex((node, index) => index > begin && node.properties.action === 'SCANNER_MESH') + const section = order.slice(begin, end), rotations = section.filter(node => mode(node) === 'rx_target') + assert.equal(rotations.length, 2) + const firstRotationIndex = order.indexOf(rotations[0]), prefix = order.slice(begin, firstRotationIndex) + const initialOffset = prefix.find(node => mode(node) === 'offset_initial') + const safety = section.at(-1) + assert(initialOffset && safety.properties.action === 'ARM_MOVE_TO_J') + prefix.forEach(node => { node.properties.name = node.properties.name.replace('准备RX=-1.1', '准备RX=-2') }) + main.push(...prefix) + let previousOffset = initialOffset, previousRead = prefix.at(-1) + for (const rx of [-2, -1.1]) { + const rotation = rotations.find(node => params(node).find(parameter => parameter.name === 'rx')?.input === rx) + assert(rotation) + const rotationIndex = order.indexOf(rotation) + const scanIndex = order.findIndex((node, index) => index > rotationIndex && mode(node) === 'rx_scan') + const turnIndex = order.findIndex((node, index) => index > rotationIndex && mode(node) === 'j6_target') + assert(scanIndex > rotationIndex && turnIndex > scanIndex) + const preparation = order.slice(scanIndex - 5, scanIndex), scanBlock = order.slice(scanIndex, scanIndex + 6) + const withdrawal = order.slice(scanIndex + 6, turnIndex), scan = order[scanIndex] + assert.equal(preparation.length, 5); assert.equal(withdrawal.length, 4) + assert.equal(preparation[2].properties.action, 'ARM_GET_ROBOT_STATE') + assert.equal(preparation[4].properties.action, 'ARM_GET_ROBOT_STATE') + assert.equal(scanBlock.at(-1).properties.action, 'SCANNER_STOP') + rotation.properties.nodeParams = [input('mode', 'rx_target'), quote('state', previousRead, 'state'), quote('offset', previousOffset, 'result'), quote('reference', initialOffset, 'result'), input('rx', rx), input('code', helper)] + rotation.properties.name = station + ' RX=' + rx + ' 在退让处设置本组原姿态' + scan.properties.nodeParams = params(scan).filter(parameter => !['settleRequired', 'settleDeadlineMs'].includes(parameter.name)) + set(scan, 'mode', input('mode', 'scan')) + const label = station + ' RX=' + rx + ' X/Z运动同步RZ往复120°单遍' + for (const node of [...preparation, ...scanBlock]) node.properties.name = node.properties.name.replace('未转J6完整路径', 'RZ摆扫路径').replace('未转J6完整扫描', 'RZ摆扫单遍') + scan.properties.name = label + withdrawal.forEach(node => { node.properties.name = node.properties.name.replace('J6换向', 'RZ摆扫结束') }) + main.push(rotation, order[rotationIndex + 1], ...preparation, ...scanBlock, ...withdrawal) + previousOffset = withdrawal[1]; previousRead = withdrawal[3] + groups.push({ station, rx, rotation: rotation.id, scan: scan.id, originalReference: initialOffset.id, withdrawal: previousOffset.id }) + } + main.push(safety) +} +main.push(...order.slice(order.findIndex(node => node.properties.action === 'SCANNER_MESH'))) +const retained = new Set() +function visit(node) { if (retained.has(node.id)) return; retained.add(node.id); for (const id of node.children || []) visit(byId.get(id)) } +main.forEach(visit) +graph.nodes = graph.nodes.filter(node => retained.has(node.id)) +const mainIds = new Set(main.map(node => node.id)) +graph.edges = graph.edges.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: crypto.randomUUID().replaceAll('-', ''), type: 'bezier', sourceNodeId: node.id, targetNodeId: main[index + 1].id, sourceAnchorId: node.id + '_1', targetAnchorId: main[index + 1].id + '_3' }))) +start.properties.inputParams.push({ name: 'scan_acceleration_mm', type: 'number', children: [], input: 80, required: true, desc: '扫描加速度(mm/s²),默认80,可输入正数;扫描速度仍长边80、短边100。' }) +start.properties.inputParams.find(parameter => parameter.name === 'scan_layers').desc = '每站先RX=-2再RX=-1.1,每个RX完整扫描一遍;X/Z运动中RZ初始→+120°→初始,整片一次往复,不专门转J6或重复扫描。' +pathGenerator.properties.name = '保留原两组RX的完整XYZ点集(各一遍,RX=-2优先)' +pathGenerator.properties.desc = '原点生成代码不改;保留X/Y/Z范围与分层,近端选起点后沿原直线段同步分配一次RZ往复。' +for (const node of graph.nodes) { + if (mode(node)) { + assert(['offset_initial', 'rx_target', 'scan', 'offset'].includes(mode(node)), 'Dedicated J6 logic must not survive') + 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('RZ摆扫单遍') && !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, 8) +assert.equal(graph.nodes.filter(node => node.properties.action === 'SCANNER_STOP').length, 8) +assert.equal(graph.nodes.filter(node => node.properties.action === 'ARM_MOVE_TO_J').length, 8) +assert.equal(JSON.stringify(original), JSON.stringify(JSON.parse(sourceText))) +fs.writeFileSync(outputPath, JSON.stringify(graph, null, 2)) +const summary = { nodes: graph.nodes.length, edges: graph.edges.length, groups, captures: 8, rzOffsetsDeg: [0, 120, 0], dedicatedJ6Turns: 0, 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/rz-sweep-planner.js b/scripts/frame_scan/rz-sweep-planner.js new file mode 100644 index 0000000..83845a5 --- /dev/null +++ b/scripts/frame_scan/rz-sweep-planner.js @@ -0,0 +1,220 @@ +// Pure planning and feedback checks for the independent RZ-sweep flow. +// Absolute Base/TCP poses use metres/radians. This code sends no device command. +function handler(params) { + var MIN_EDGE = 0.002, EPS = 1e-10, MAX_POINTS = 4096; + var AMPLITUDE = 2 * Math.PI / 3, MAX_ANGLE_STEP = Math.PI / 18; + function fail(message) { throw new Error(message); } + function finite(value) { return typeof value === 'number' && isFinite(value); } + function joints(value) { + if (typeof value === 'string') { + try { value = JSON.parse(value); } catch (error) { fail('关节目标不是有效数组'); } + } + if (!Array.isArray(value) || value.length !== 6) fail('实际关节角必须为六个数值'); + for (var i = 0; i < 6; i++) if (!finite(value[i])) fail('关节角数值无效'); + return value; + } + 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 distance(a, b) { + var x = a.x - b.x, y = a.y - b.y, z = a.z - b.z; + return Math.sqrt(x * x + y * y + z * z); + } + function quaternion(p) { + var x = p.rx / 2, y = p.ry / 2, z = p.rz / 2; + var 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]; + } + function angle(a, b) { + 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]); + } + return 4 * Math.asin(Math.min(1, Math.sqrt(Math.min(minus, plus)) / 2)); + } + function state(s) { + if (!s || s.connected !== true || s.poweredOn !== true || s.brakeReleased !== true || + s.protectiveStopped !== false || s.emergencyStopped !== false || s.fault !== false || + s.safetyMode !== 'ARM_SAFETY_MODE_NORMAL' || s.controlMode !== 'ARM_CONTROL_MODE_POSITION') + fail('机械臂连接、上电、制动或安全状态未确认正常'); + if (!finite(s.timestamp) || Math.abs(Date.now() / 1000 - s.timestamp) > 10) fail('机械臂实际回读状态已过期'); + if (s.moving !== false || s.programRunning !== false || s.robotMode !== 'ARM_ROBOT_MODE_IDLE') fail('机械臂尚未确认停稳'); + var q = joints(s.actualJointState && s.actualJointState.position); + var v = s.actualJointState.velocity, t = s.actualTcpVelocity; + if (!Array.isArray(v) || v.length !== 6 || !t) fail('停稳复核缺少关节或TCP速度'); + var keys = ['vx', 'vy', 'vz', 'wx', 'wy', 'wz']; + for (var i = 0; i < 6; i++) { + if (!finite(v[i]) || Math.abs(v[i]) > 0.001) fail('机械臂关节尚未连续停稳'); + if (!finite(t[keys[i]]) || Math.abs(t[keys[i]]) > 0.0001) fail('机械臂末端尚未连续停稳'); + } + requiredPose(s.actualTcpPose, '实际回读'); + return s.actualTcpPose; + } + function continuous() { + var before = params.previousState, after = params.state; + var a = state(before), b = state(after), dt = after.timestamp - before.timestamp; + if (dt < 0.2 || dt > 2) fail('连续停稳复核的两帧间隔必须为0.2至2秒'); + if (distance(a, b) > 0.00002 || angle(a, b) > 0.0001) fail('连续回读的TCP位姿仍在漂移'); + var qa = joints(before.actualJointState.position), qb = joints(after.actualJointState.position); + for (var i = 0; i < 6; i++) if (Math.abs(qb[i] - qa[i]) / dt > 0.001) fail('连续关节回读尚未停稳'); + } + 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 }; } + function poseMatch(actual, target) { + requiredPose(target, '规划目标'); + if (distance(actual, target) > 0.003 || angle(actual, target) > 0.015) fail('未到指定扫描末点、退让位置或姿态,停止后续动作'); + } + function jointMatch(actual, target) { + actual = joints(actual); target = joints(target); + for (var i = 0; i < 6; i++) if (Math.abs(actual[i] - target[i]) > 0.015) fail('未到原初始关节目标'); + } + function stamp(reference, now) { + if (!reference || !finite(reference.stamp) || now < reference.stamp) fail('实际回读时间与本阶段准备记录不一致'); + } + function confirmedMoves(target, actual) { + if (distance(actual, target) > 0.00005 || angle(actual, target) > 0.0001) return [target]; + continuous(); + if (distance(params.previousState.actualTcpPose, target) > 0.00005 || angle(params.previousState.actualTcpPose, target) > 0.0001) + fail('重复衔接点缺少连续到位回读,停止发送空移动'); + return []; + } + function pointList(points, original) { + var limit = original ? 202 : MAX_POINTS; + if (!Array.isArray(points) || points.length < 2 || points.length > limit || (original && points.length % 2 !== 0)) + fail(original ? '原扫描条带必须为2至202个偶数点' : '扫描点集必须为2至4096个点'); + for (var i = 0; i < points.length; i++) { + var p = requiredPose(points[i], '扫描点'); + if (!finite(p.velocity) || !(p.velocity > 0) || p.y < 0.456 || p.z < -0.3 - EPS) fail('扫描点速度或XYZ范围无效'); + if (original && i % 2 === 1 && (Math.abs(p.y - points[i - 1].y) > EPS || Math.abs(p.z - points[i - 1].z) > EPS)) + fail('原横扫条带两端不在同一Y/Z'); + if (i && distance(points[i - 1], p) <= 1e-12) fail('原扫描路径存在零距离重复点'); + } + return points; + } + function copy(p) { + var result = {}; + for (var key in p) if (Object.prototype.hasOwnProperty.call(p, key)) result[key] = p[key]; + return result; + } + function ordered(points, actual) { + var candidates = [], best = null, bestCost = Infinity; + for (var flip = 0; flip < 2; flip++) { + var list = []; + for (var i = 0; i < points.length; i++) list.push(points[flip ? (i % 2 === 0 ? i + 1 : i - 1) : i]); + candidates.push(list); candidates.push(list.slice(0).reverse()); + } + for (var i = 0; i < candidates.length; i++) { + var first = candidates[i][0], x = first.x - actual.x, z = first.z - actual.z, cost = x * x + z * z; + if (cost < bestCost) { bestCost = cost; best = candidates[i]; } + } + return best; + } + function sweep(input, orientation) { + var cumulative = [0], lengths = [], total = 0; + for (var i = 1; i < input.length; i++) { + var length = distance(input[i - 1], input[i]); + lengths.push(length); + if (length >= MIN_EDGE) total += length; + cumulative.push(total); + } + if (!(total > 2 * MIN_EDGE)) fail('有效扫描路径过短,不能在保持XYZ路径的同时完成RZ往复'); + var peak = total / 2, closest = MIN_EDGE; + // A nearby original interior vertex is the peak; short edges there become a plateau. + for (var i = 1; i < cumulative.length - 1; i++) { + var delta = Math.abs(cumulative[i] - total / 2); + if (cumulative[i] > 0 && cumulative[i] < total && delta < closest) { closest = delta; peak = cumulative[i]; } + } + function offset(w) { + if (w <= 0 || w >= total) return 0; + if (w === peak) return AMPLITUDE; + return w < peak ? AMPLITUDE * w / peak : AMPLITUDE * (total - w) / (total - peak); + } + function at(p, w) { + var target = copy(p); + target.rx = orientation.rx; target.ry = orientation.ry; target.rz = orientation.rz + offset(w); + return target; + } + var result = [at(input[0], 0)]; + for (var edge = 0; edge < lengths.length; edge++) { + var a = input[edge], b = input[edge + 1], start = cumulative[edge], end = cumulative[edge + 1]; + var cuts = [0]; + if (start < peak && peak < end) cuts.push((peak - start) / (end - start)); + cuts.push(1); + for (var part = 1; part < cuts.length; part++) { + var from = cuts[part - 1], to = cuts[part]; + var startW = start + (end - start) * from, endW = start + (end - start) * to; + var change = Math.abs(offset(endW) - offset(startW)); + var steps = Math.max(1, Math.ceil(change / MAX_ANGLE_STEP - 1e-10)); + if (change > EPS && lengths[edge] * (to - from) / steps < MIN_EDGE - EPS) + fail('RZ关键帧间距不足2mm,不能安全表达本次摆扫'); + for (var step = 1; step <= steps; step++) { + var t = step === steps ? to : from + (to - from) * step / steps; + var point = copy(b); + if (t !== 1) { + point.x = a.x + (b.x - a.x) * t; + point.y = a.y + (b.y - a.y) * t; + point.z = a.z + (b.z - a.z) * t; + } + result.push(at(point, t === 1 ? end : start + (end - start) * t)); + if (result.length > MAX_POINTS) fail('RZ摆扫细分点超过4096个'); + } + } + } + var maximum = 0, variation = 0, descending = false; + for (var i = 0; i < result.length; i++) { + var value = result[i].rz - orientation.rz; + if (value < -EPS || value > AMPLITUDE + EPS) fail('RZ摆角超出本次往复范围'); + maximum = Math.max(maximum, value); + if (i) { + var difference = result[i].rz - result[i - 1].rz; + if (Math.abs(difference) > MAX_ANGLE_STEP + EPS) fail('相邻RZ关键帧超过10度'); + if (Math.abs(difference) > EPS && distance(result[i - 1], result[i]) < MIN_EDGE - EPS) fail('RZ变化段XYZ间距不足2mm'); + if (difference < -EPS) descending = true; + if (descending && difference > EPS) fail('RZ摆扫出现额外往复'); + variation += Math.abs(difference); + } + } + if (Math.abs(result[0].rz - orientation.rz) > EPS || Math.abs(result[result.length - 1].rz - orientation.rz) > EPS || + Math.abs(maximum - AMPLITUDE) > EPS || Math.abs(variation - 2 * AMPLITUDE) > EPS) fail('RZ摆扫未完成初始到120度再回初始的一次往复'); + return result; + } + var actual = state(params.state), now = params.state.timestamp; + if (params.mode === 'offset_initial') { + jointMatch(params.state.actualJointState.position, params.initialJoints); + var initialRetreat = pose(actual, 0.15); initialRetreat.y -= 0.2; + return { retreatPose: initialRetreat, stamp: now }; + } + if (params.mode === 'rx_target') { + stamp(params.offset, now); stamp(params.reference, now); + poseMatch(actual, requiredPose(params.offset.retreatPose, '当前退让位置')); + var reference = requiredPose(params.reference.retreatPose, '本站最初姿态基准'); + if (params.rx !== -2 && params.rx !== -1.1) fail('RX目标必须为-2或-1.1rad'); + var target = pose(actual, 0.06); target.rx = params.rx; target.ry = reference.ry; target.rz = reference.rz; + return { targetPose: target, stamp: now }; + } + if (params.mode === 'scan') { + continuous(); stamp(params.rotation, now); + var rotation = requiredPose(params.rotation.targetPose, '本组原RX姿态'); + poseMatch(actual, rotation); + var original = pointList(params.points, true), lo = params.minZMm / 1000, hi = params.maxZMm / 1000; + if (!finite(lo) || !finite(hi) || hi < lo || (rotation.rx !== -2 && rotation.rx !== -1.1) || + Math.abs(lo - (rotation.rx === -2 ? -0.15 : -0.3)) > EPS) fail('RX扫描Z范围无效'); + for (var i = 0; i < original.length; i++) + if (Math.abs(original[i].rx - rotation.rx) > EPS || original[i].z < lo - EPS || original[i].z > hi + EPS) + fail('原扫描点超出本组RX或Z范围'); + var points = sweep(ordered(original, actual), rotation); + var 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, actual), entry: entry, count: points.length, stamp: now }; + } + if (params.mode === 'offset') { + var completed = pointList(params.completedPoints, false), last = completed[completed.length - 1]; + poseMatch(actual, last); + var retreat = pose(last, 0.15); retreat.y -= 0.2; + retreat.rx = actual.rx; retreat.ry = actual.ry; retreat.rz = actual.rz; + return { retreatPose: retreat, stamp: now }; + } + fail('RZ摆扫规划模式无效'); +}