完善扫描成果与比对资料管理,精简业务菜单和任务工作台,更新批量导入模板。 适配机械臂新协议、坐标系管理及目标位姿组件,增加扫描参数字典和角色自动分配。 修复试运行终止状态与过期扫描任务资源释放,补充回归测试、迁移脚本及接口文档。
68 lines
5.5 KiB
Java
68 lines
5.5 KiB
Java
package com.cmvr.arm;
|
||
import com.alibaba.fastjson2.*;
|
||
import com.cmvr.common.exception.GlobalException;
|
||
import java.nio.charset.StandardCharsets;
|
||
import java.util.*;
|
||
public final class ArmTeachingParameters {
|
||
private ArmTeachingParameters(){}
|
||
public static void validate(ArmTeachingOperation op,ArmTeachingRequest p) {
|
||
if(op==null||p==null)throw new GlobalException("机械臂操作参数不能为空");
|
||
if(p.getRobotId()==null||p.getRobotId().isBlank()||p.getDeviceId()==null||p.getDeviceId().isBlank())throw new GlobalException("请选择机器人和机械臂设备");
|
||
timeout(op,p.getTimeoutMs());
|
||
if(op.coordinate())ArmUserCoordinates.validate(op,p);
|
||
if(op==ArmTeachingOperation.START_TRAJECTORY_RECORDING||op==ArmTeachingOperation.MOVE_TO_TRAJECTORY_START||op==ArmTeachingOperation.REPLAY_RECORDED_TRAJECTORY)file(p.getFileName());
|
||
if(op==ArmTeachingOperation.START_TRAJECTORY_RECORDING)range(p.getSamplingFrequencyHz(),1,100,"samplingFrequencyHz(Hz)",true);
|
||
if(op==ArmTeachingOperation.MOVE_TO_TRAJECTORY_START||op==ArmTeachingOperation.REPLAY_RECORDED_TRAJECTORY) {
|
||
range(p.getSpeedRatio(),0.1,1,"speedRatio",true);
|
||
for(Double number:List.of(value(p.getMaxVelocity()),value(p.getMaxAcceleration()),value(p.getMaxJerk())))
|
||
if(!Double.isFinite(number)||number<0)throw new GlobalException("速度、加速度和加加速度限值必须为有限非负数;0使用服务端默认值");
|
||
}
|
||
}
|
||
private static double value(Double value){return value==null?0:value;}
|
||
public static long timeout(ArmTeachingOperation op,Long timeout) {
|
||
long result=timeout==null?op.defaultTimeout():timeout;
|
||
if(result<100||result>21600000)throw new GlobalException("timeoutMs 必须为100至21600000的整数毫秒,回放超时需覆盖整条轨迹");
|
||
return op==ArmTeachingOperation.REPLAY_RECORDED_TRAJECTORY||op==ArmTeachingOperation.MOVE_TO_TRAJECTORY_START?result:Math.max(30000,result);
|
||
}
|
||
public static String file(String name) {
|
||
if(name==null||name.isBlank()||!name.equals(name.trim())||name.startsWith(".")||name.contains("..")
|
||
||name.getBytes(StandardCharsets.UTF_8).length>120||name.chars().anyMatch(c->c<32||c==127||"/\\:*?\"<>|".indexOf(c)>=0))
|
||
throw new GlobalException("轨迹文件名须为不超过120个UTF-8字节的文件名,不能包含路径、..或保留字符");
|
||
return name;
|
||
}
|
||
private static void range(Double value,double min,double max,String label,boolean allowZero) {
|
||
if(value==null)return;
|
||
if(!Double.isFinite(value)||!(allowZero&&value==0)&&!(value>=min&&value<=max))throw new GlobalException(label+"必须为"+min+"至"+max+",0使用默认值");
|
||
}
|
||
public static ArmTeachingRequest fromInputs(ArmTeachingOperation op,JSONObject input) {
|
||
if(input==null)throw new GlobalException("机械臂参数必须为对象");
|
||
if(input.containsKey("fileName")&&!(input.get("fileName") instanceof String))throw new GlobalException("fileName必须为文件名字符串");
|
||
Set<String> numeric=Set.of("samplingFrequencyHz","speedRatio","maxVelocity","maxAcceleration","maxJerk","timeoutMs");
|
||
for(String name:numeric)if(input.containsKey(name)) {
|
||
Object value=input.get(name);
|
||
if(!(value instanceof Number n)||!Double.isFinite(n.doubleValue())||name.equals("timeoutMs")&&n.doubleValue()!=Math.rint(n.doubleValue()))throw new GlobalException(name+"必须为有效数值,超时为整数毫秒");
|
||
}
|
||
if(input.containsKey("expectedRevision")&&!(input.get("expectedRevision") instanceof String))throw new GlobalException("expectedRevision请使用十进制字符串,避免64位精度丢失");
|
||
var request=input.to(ArmTeachingRequest.class);validate(op,request);return request;
|
||
}
|
||
public static void validateLiterals(ArmTeachingOperation op,JSONArray params) {
|
||
JSONObject literals=JSONObject.of("robotId","validation","deviceId","validation");
|
||
Set<String> names=new HashSet<>(),dynamic=new HashSet<>();
|
||
if(params!=null)for(int i=0;i<params.size();i++) {
|
||
var param=params.getJSONObject(i);String name=param.getString("name");
|
||
if(name==null||!names.add(name))throw new GlobalException("机械臂参数名称为空或重复");
|
||
if("input".equals(param.getString("type")))literals.put(name,param.get("input"));
|
||
else if("quote".equals(param.getString("type"))) {
|
||
var path=param.getJSONArray("quote");
|
||
if(path==null||path.size()<3||path.stream().anyMatch(v->!(v instanceof String s)||s.isBlank())||!Set.of("input","output").contains(param.getString("quoteType")))throw new GlobalException(name+"的引用不完整");
|
||
dynamic.add(name);
|
||
}else throw new GlobalException(name+"的参数来源无效");
|
||
}
|
||
if(dynamic.contains("fileName"))literals.put("fileName","runtime.csv");
|
||
if(dynamic.contains("name"))literals.put("name","runtime-coordinate");
|
||
if(dynamic.contains("expectedRevision"))literals.put("expectedRevision","1");
|
||
if(dynamic.contains("coordinate"))literals.put("coordinate",JSONObject.of("name","runtime-coordinate","calibrationVersion",2,"tcpOffset",List.of(0,0,0,0,0,0),"calibrationPoints",List.of(JSONObject.of("baseTcpPose",JSONObject.of("x",0,"y",0,"z",0,"rx",0,"ry",0,"rz",0)),JSONObject.of("baseTcpPose",JSONObject.of("x",1,"y",0,"z",0,"rx",0,"ry",0,"rz",0)),JSONObject.of("baseTcpPose",JSONObject.of("x",0,"y",1,"z",0,"rx",0,"ry",0,"rz",0)))));
|
||
fromInputs(op,literals);
|
||
}
|
||
}
|