45 lines
3.1 KiB
JavaScript
45 lines
3.1 KiB
JavaScript
import { ARM_DEFAULT_WAIT_MS } from './armTimeouts.mjs'
|
||
// Labels describe the SDK contract. Never convert or rewrite saved positions or live feedback here.
|
||
const jointActions = new Set(['ARM_MOVE_TO_J', 'ARM_MOVE_J'])
|
||
const linearActions = new Set(['ARM_MOVE_TO_POINT', 'ARM_MOVE_L'])
|
||
export function armMotionParamLabel(action, name) {
|
||
const joint = jointActions.has(action)
|
||
const jointPose = action === 'ARM_MOVE_J_POSE'
|
||
if (!joint && !jointPose && !linearActions.has(action)) return ''
|
||
if (joint && ['target', 'positions'].includes(name)) return '关节位置(rad,数组)'
|
||
if (!joint && ['x', 'y', 'z'].includes(name)) return `${name.toUpperCase()}(m)`
|
||
if (!joint && ['rx', 'ry', 'rz'].includes(name)) return `${name.toUpperCase()}(rad)`
|
||
if (name === 'velocity') return `速度(${joint || jointPose ? 'rad/s' : 'm/s'})`
|
||
if (name === 'acceleration') return `加速度(${joint || jointPose ? 'rad/s²' : 'm/s²'})`
|
||
if (name === 'blendRadius') return '融合半径(m)'
|
||
if (name === 'jointVelocityLimits') return '各关节速度上限(rad/s,数组)'
|
||
return ''
|
||
}
|
||
// Velocity and acceleration have different dimensions and must be checked independently.
|
||
export function armMotionScalarError(action, param) {
|
||
if (param?.type === 'quote' || !['velocity', 'acceleration'].includes(param?.name)) return ''
|
||
const label = armMotionParamLabel(action, param.name)
|
||
if (!label) return ''
|
||
const raw = param.input
|
||
const value = Number(raw)
|
||
if (raw === '' || raw == null || typeof raw === 'boolean' || !Number.isFinite(value) || value <= 0)
|
||
return `${label}必须为大于0的有效数值`
|
||
if (Number.isFinite(param.min) && value < param.min) return `${label}不能小于${param.min}`
|
||
if (Number.isFinite(param.max) && value > param.max) return `${label}不能大于${param.max}`
|
||
return ''
|
||
}
|
||
export const withArmMotionUnits = (action, params = []) => {
|
||
const source = ['ARM_MOVE_TO_J', 'ARM_MOVE_TO_POINT'].includes(action) && !params.some(p => p.name === 'timeoutMs')
|
||
? [...params, {name:'timeoutMs',label:'等待超时(毫秒)',type:'input',componentType:'number',input:ARM_DEFAULT_WAIT_MS,min:100,max:21600000,step:1000,required:true,disabled:true}] : params
|
||
return source.map(param => {
|
||
const label = armMotionParamLabel(action, param.name)
|
||
return label ? { ...param, label, ...(param.name === 'velocity' ? { forceSelect: false } : {}) } : param
|
||
})
|
||
}
|
||
export function armMotionUnitHint(action) {
|
||
if (action === 'ARM_MOVE_J_POSE') return '末端位姿MoveJ:XYZ为所选坐标系下绝对TCP位置(m),RX/RY/RZ为绝对姿态(rad,RzRyRx);速度rad/s,加速度rad/s²。边端逆解后执行关节运动,途中路径不保证直线。'
|
||
if (jointActions.has(action)) return 'SDK 单位:关节位置为 rad,速度为 rad/s,加速度为 rad/s²。示教器角度换算:1° = π/180 rad,90° ≈ 1.570796 rad。读取当前位置按 SDK 原值回填。'
|
||
if (linearActions.has(action)) return 'SDK 单位:X/Y/Z 为 m,RX/RY/RZ 为 rad,速度为 m/s,加速度为 m/s²。示教器单位换算:1 mm = 0.001 m,90° ≈ 1.570796 rad。读取当前位置按 SDK 原值回填。'
|
||
return ''
|
||
}
|