feat(touch): 完善头颈组件和触控执行报告
This commit is contained in:
parent
73bee6283b
commit
c1bc29c9fe
@ -56,8 +56,9 @@ public class TiProjectController extends BaseController {
|
||||
@ApiOperation("编辑项目")
|
||||
@PreAuthorize("@ss.hasPermi('ti:project:edit')")
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody TiProject tiProject) {
|
||||
return toAjax(tiProjectService.updateTiProject(tiProject));
|
||||
public AjaxResult edit(@RequestBody TiProject tiProject,
|
||||
@RequestParam(defaultValue = "false") boolean clearVehicleConfig) {
|
||||
return toAjax(tiProjectService.updateTiProject(tiProject, clearVehicleConfig));
|
||||
}
|
||||
|
||||
@ApiOperation("删除项目")
|
||||
@ -69,8 +70,17 @@ public class TiProjectController extends BaseController {
|
||||
|
||||
@ApiOperation("查询项目执行时运行参数")
|
||||
@GetMapping("/queryExecuteRunParams")
|
||||
public AjaxResult queryExecuteRunParams(@RequestParam("projectId") String projectId) {
|
||||
return AjaxResult.ok(tiProjectService.queryExecuteRunParams(projectId));
|
||||
public AjaxResult queryExecuteRunParams(@RequestParam("projectId") String projectId,
|
||||
@RequestParam(value = "instId", required = false) String instId) {
|
||||
return AjaxResult.ok(instId == null ? tiProjectService.queryExecuteRunParams(projectId)
|
||||
: tiProjectService.queryExecutionItems(projectId, instId));
|
||||
}
|
||||
|
||||
@ApiOperation("查询可用于触控项目的已发布检测项")
|
||||
@PreAuthorize("@ss.hasPermi('ti:project:list')")
|
||||
@GetMapping("/detectionItems")
|
||||
public AjaxResult detectionItems() {
|
||||
return AjaxResult.ok(tiProjectService.listExecutableDetectionItems());
|
||||
}
|
||||
|
||||
@ApiOperation("检查触控项目、录像和工作流是否具备执行条件")
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
package com.cmvr.edge.client.model;
|
||||
|
||||
/** Edge inventories report both devices as arm devices. */
|
||||
public final class NeckDeviceIds {
|
||||
private NeckDeviceIds() {
|
||||
}
|
||||
|
||||
public static boolean isNeck(String deviceId) {
|
||||
return "neck_arm".equals(deviceId) || "xiaozhao_head".equals(deviceId);
|
||||
}
|
||||
|
||||
public static boolean matchesRequiredId(String requiredId, String actualId) {
|
||||
return isNeck(requiredId) ? isNeck(actualId) : requiredId.equals(actualId);
|
||||
}
|
||||
}
|
||||
@ -57,9 +57,9 @@ public interface EdgeArmService {
|
||||
* 控制机械臂通过关节空间插值运动到目标关节位置
|
||||
*
|
||||
* @param edgeCommonVO 边缘通用参数
|
||||
* @param target 目标关节位置数组(6个关节角度,单位:弧度)
|
||||
* @param velocity 运动速度(单位:m/s,可选)
|
||||
* @param acceleration 加速度(单位:m/s²,可选)
|
||||
* @param target 按目标设备关节顺序排列的目标位置(rad)
|
||||
* @param velocity 关节运动速度(rad/s,可选)
|
||||
* @param acceleration 关节运动加速度(rad/s²,可选)
|
||||
* @param blendRadius 融合半径(单位:m,可选)
|
||||
* @param jointVelocityLimits 关节速度限制数组(可选)
|
||||
* @param asynchronous 是否异步执行(可选)
|
||||
@ -151,6 +151,10 @@ public interface EdgeArmService {
|
||||
*/
|
||||
ArmCommand.JointResponse getJointState(EdgeCommonVO edgeCommonVO);
|
||||
|
||||
ArmCommand.GetArmInfo.Response getArmInfo(EdgeCommonVO device);
|
||||
|
||||
ArmCommand.GetRobotState.Response getRobotState(EdgeCommonVO device);
|
||||
|
||||
/**
|
||||
* 获取末端位姿(命令码:getPose)
|
||||
* 获取机械臂末端执行器相对于基座的笛卡尔位姿
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.cmvr.edge.client.service;
|
||||
|
||||
import cmvr.api.HeadJointCommandOuterClass.*;
|
||||
import java.util.Map;
|
||||
import com.cmvr.edge.client.model.EdgeCommonVO;
|
||||
import com.cmvr.edge.client.model.biohead.EdgeFacialExpressionVO;
|
||||
|
||||
@ -7,6 +9,13 @@ import com.cmvr.edge.client.model.biohead.EdgeFacialExpressionVO;
|
||||
* 边缘系统 生物头部机器人服务
|
||||
*/
|
||||
public interface EdgeBioHeadService {
|
||||
void controlHeadJoints(EdgeCommonVO device, HeadJointCommand.Request.Builder command);
|
||||
|
||||
Map<String, Object> getHeadJointState(EdgeCommonVO device);
|
||||
|
||||
void setHeadExpression(EdgeCommonVO device, SetHeadExpressionCommand.Request.Builder command);
|
||||
|
||||
Map<String, Object> playHeadExpression(EdgeCommonVO device, PlayHeadExpressionCommand.Request.Builder command);
|
||||
|
||||
/**
|
||||
* 设置面部表情
|
||||
|
||||
@ -284,6 +284,24 @@ public class EdgeArmServiceImpl implements EdgeArmService {
|
||||
return executeGrpcCall(() -> stub.getJointState(request));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArmCommand.GetArmInfo.Response getArmInfo(EdgeCommonVO device) {
|
||||
ArmServiceGrpc.ArmServiceBlockingStub stub = blockingStub(device.getRobotId());
|
||||
ArmCommand.GetArmInfo.Request request = ArmCommand.GetArmInfo.Request.newBuilder()
|
||||
.setHeader(EdgeCommonUtil.buildRequest(device.getDeviceId()))
|
||||
.build();
|
||||
return executeGrpcCall(() -> stub.getArmInfo(request));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArmCommand.GetRobotState.Response getRobotState(EdgeCommonVO device) {
|
||||
ArmServiceGrpc.ArmServiceBlockingStub stub = blockingStub(device.getRobotId());
|
||||
ArmCommand.GetRobotState.Request request = ArmCommand.GetRobotState.Request.newBuilder()
|
||||
.setHeader(EdgeCommonUtil.buildRequest(device.getDeviceId()))
|
||||
.build();
|
||||
return executeGrpcCall(() -> stub.getRobotState(request));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArmCommand.GetPose.Response getPose(EdgeCommonVO edgeCommonVO, String baseLink, String eeLink) {
|
||||
ArmServiceGrpc.ArmServiceBlockingStub stub = grpcServiceManager.getGrpcClient(
|
||||
|
||||
@ -3,6 +3,7 @@ package com.cmvr.edge.client.service.impl;
|
||||
import cmvr.api.BioHeadServiceGrpc;
|
||||
import cmvr.api.BioheadCommand;
|
||||
import cmvr.api.Common;
|
||||
import cmvr.api.HeadJointCommandOuterClass.*;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.cmvr.common.exception.GlobalException;
|
||||
import com.cmvr.edge.client.manage.GrpcServiceManager;
|
||||
@ -14,6 +15,11 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@ -21,6 +27,68 @@ public class EdgeBioHeadServiceImpl implements EdgeBioHeadService {
|
||||
|
||||
private final GrpcServiceManager grpcServiceManager;
|
||||
|
||||
private BioHeadServiceGrpc.BioHeadServiceBlockingStub headStub(EdgeCommonVO device) {
|
||||
return grpcServiceManager.getGrpcClient(device.getRobotId(),
|
||||
BioHeadServiceGrpc.BioHeadServiceBlockingStub.class).withDeadlineAfter(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private void requireAcknowledgement(boolean hasHeader, Common.CommandHeader.Feedback header) {
|
||||
if (!hasHeader || !header.getSuccess()) {
|
||||
throw new GlobalException(header.getErrorMessage().isEmpty() ? "头部设备未确认操作" : header.getErrorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void controlHeadJoints(EdgeCommonVO device, HeadJointCommand.Request.Builder command) {
|
||||
HeadJointCommand.Feedback feedback = headStub(device).controlHeadJoints(
|
||||
command.setHeader(EdgeCommonUtil.buildRequest(device.getDeviceId())).build());
|
||||
requireAcknowledgement(feedback.hasHeader(), feedback.getHeader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getHeadJointState(EdgeCommonVO device) {
|
||||
GetHeadJointStateCommand.Feedback state = headStub(device).getHeadJointState(
|
||||
GetHeadJointStateCommand.Request.newBuilder()
|
||||
.setHeader(EdgeCommonUtil.buildRequest(device.getDeviceId())).build());
|
||||
requireAcknowledgement(state.hasHeader(), state.getHeader());
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("connected", state.getConnected());
|
||||
result.put("jointInfo", state.getJointInfoList().stream().map(joint -> Map.of(
|
||||
"id", joint.getId(), "minPositionRad", joint.getMinPositionRad(),
|
||||
"maxPositionRad", joint.getMaxPositionRad(), "homePositionRad", joint.getHomePositionRad()
|
||||
)).collect(Collectors.toList()));
|
||||
result.put("targets", state.getTargetsList().stream().map(target -> Map.of(
|
||||
"id", target.getId(), "targetPositionRad", target.getTargetPositionRad(), "targetValid", target.getTargetValid()
|
||||
)).collect(Collectors.toList()));
|
||||
result.put("lastCommandOutcome", state.getLastCommandOutcome().name());
|
||||
result.put("lastError", state.getLastError());
|
||||
result.put("positionFeedbackAvailable", state.getPositionFeedbackAvailable());
|
||||
result.put("expressions", state.getExpressionsList().stream().map(expression -> Map.of(
|
||||
"expressionId", expression.getExpressionId(), "expressionName", expression.getExpressionName(),
|
||||
"targets", expression.getTargetsList().stream().map(target -> Map.of(
|
||||
"id", target.getId(), "positionRad", target.getPositionRad()
|
||||
)).collect(Collectors.toList())
|
||||
)).collect(Collectors.toList()));
|
||||
result.put("expressionBaselineReady", state.getExpressionBaselineReady());
|
||||
result.put("hardwareEmergencyStopAvailable", state.getHardwareEmergencyStopAvailable());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeadExpression(EdgeCommonVO device, SetHeadExpressionCommand.Request.Builder command) {
|
||||
SetHeadExpressionCommand.Feedback feedback = headStub(device).setHeadExpression(
|
||||
command.setHeader(EdgeCommonUtil.buildRequest(device.getDeviceId())).build());
|
||||
requireAcknowledgement(feedback.hasHeader(), feedback.getHeader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> playHeadExpression(EdgeCommonVO device, PlayHeadExpressionCommand.Request.Builder command) {
|
||||
PlayHeadExpressionCommand.Feedback feedback = headStub(device).playHeadExpression(
|
||||
command.setHeader(EdgeCommonUtil.buildRequest(device.getDeviceId())).build());
|
||||
requireAcknowledgement(feedback.hasHeader(), feedback.getHeader());
|
||||
return Map.of("expressionId", feedback.getExpressionId(), "expressionName", feedback.getExpressionName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String setExpression(EdgeFacialExpressionVO facialExpressionVo) {
|
||||
String robotId = facialExpressionVo.getRobotId();
|
||||
|
||||
@ -77,3 +77,13 @@ changes, update the committed snapshot and revision together, then run a clean
|
||||
build. The repository URL, lookup branch, and revision can be overridden
|
||||
explicitly with `-Dcmvr.es.repository=...`, `-Dcmvr.es.proto.branch=...`, and
|
||||
`-Dcmvr.es.proto.revision=...`.
|
||||
|
||||
The head-specific snapshot (`head_joint_command.proto` and `biohead_service.proto`)
|
||||
was synchronized separately from CMVR-ES `dev` at
|
||||
`55736f58fffe3a51a986d65540855f2470076a27`. The baseline revision above applies to
|
||||
the broader snapshot; the existing `biohead_command.proto` is unchanged at the
|
||||
head-specific revision.
|
||||
|
||||
The neck device `xiaozhao_head` uses `ArmService`. Its `arm_service.proto` and
|
||||
`arm_command.proto` were copied from the same CMVR-ES `dev` revision. The
|
||||
`common.proto` dependency already matches that revision.
|
||||
|
||||
@ -16,6 +16,38 @@ enum ArmFrameType {
|
||||
ARM_FRAME_USER = 3;
|
||||
}
|
||||
|
||||
enum ArmRobotMode {
|
||||
ARM_ROBOT_MODE_UNKNOWN = 0;
|
||||
ARM_ROBOT_MODE_DISCONNECTED = 1;
|
||||
ARM_ROBOT_MODE_POWER_OFF = 2;
|
||||
ARM_ROBOT_MODE_IDLE = 3;
|
||||
ARM_ROBOT_MODE_RUNNING = 4;
|
||||
ARM_ROBOT_MODE_PAUSED = 5;
|
||||
ARM_ROBOT_MODE_STOPPED = 6;
|
||||
ARM_ROBOT_MODE_FAULT = 7;
|
||||
}
|
||||
|
||||
enum ArmSafetyMode {
|
||||
ARM_SAFETY_MODE_UNKNOWN = 0;
|
||||
ARM_SAFETY_MODE_NORMAL = 1;
|
||||
ARM_SAFETY_MODE_REDUCED = 2;
|
||||
ARM_SAFETY_MODE_PROTECTIVE_STOP = 3;
|
||||
ARM_SAFETY_MODE_EMERGENCY_STOP = 4;
|
||||
ARM_SAFETY_MODE_SAFEGUARD_STOP = 5;
|
||||
ARM_SAFETY_MODE_SYSTEM_EMERGENCY_STOP = 6;
|
||||
ARM_SAFETY_MODE_FAULT = 7;
|
||||
}
|
||||
|
||||
enum ArmControlMode {
|
||||
ARM_CONTROL_MODE_NONE = 0;
|
||||
ARM_CONTROL_MODE_MANUAL = 1;
|
||||
ARM_CONTROL_MODE_POSITION = 2;
|
||||
ARM_CONTROL_MODE_VELOCITY = 3;
|
||||
ARM_CONTROL_MODE_TORQUE = 4;
|
||||
ARM_CONTROL_MODE_SERVO = 5;
|
||||
ARM_CONTROL_MODE_FREEDRIVE = 6;
|
||||
}
|
||||
|
||||
// 关节位置命令;数组顺序必须与机械臂关节顺序一致。
|
||||
message JointPositionCommand {
|
||||
// 各关节目标角度,单位:rad。
|
||||
@ -76,6 +108,15 @@ message CartesianVelocity {
|
||||
double wz = 6;
|
||||
}
|
||||
|
||||
message CartesianWrench {
|
||||
double fx = 1;
|
||||
double fy = 2;
|
||||
double fz = 3;
|
||||
double tx = 4;
|
||||
double ty = 5;
|
||||
double tz = 6;
|
||||
}
|
||||
|
||||
// 4x4 齐次变换矩阵;前三列为无量纲旋转矩阵,第四列前三项为平移量(m)。
|
||||
message TransformMatrix4x4 {
|
||||
// 第一行:m00~m02 无单位,m03 单位为 m。
|
||||
@ -108,12 +149,61 @@ message MoveJ {
|
||||
}
|
||||
|
||||
// TCP 笛卡尔直线运动命令。
|
||||
// 服务端持久化记录。名称仅用于服务端查找,不是示教器命名坐标系。
|
||||
message CoordinateCalibrationPoint {
|
||||
// Actual TCP pose in Base, m/rad. Three points: origin, +X, XY plane (+Y).
|
||||
CartesianPose base_tcp_pose = 1;
|
||||
}
|
||||
message UserCoordinateSystem {
|
||||
// 内置记录标识:__builtin_base__(基座)、__builtin_tool__(工具)。
|
||||
// List/Get 默认提供,revision 固定为 1;禁止 Create/Update/Delete。
|
||||
// 内置记录的 user_pose/tcp_offset 全零仅作协议占位,不是实际 TCP 回读。
|
||||
// Apply 保留当前 TCP 偏移。基座模式使用Base绝对目标;工具模式固定
|
||||
// Apply时的实际TCP为参考,后续MoveL使用相对该固定参考的绝对目标,不累加。
|
||||
string name = 1;
|
||||
// 服务端 SDK 三点标定结果 T_base_user,[x,y,z,rx,ry,rz],m/rad,RzRyRx。
|
||||
// Create/Update 不采用客户端提供的该字段,只采用 calibration_points 重新计算。
|
||||
repeated double user_pose = 2;
|
||||
// T_flange_tcp,维度、单位及姿态约定同上。
|
||||
repeated double tcp_offset = 3;
|
||||
// 由服务端分配,创建后单调递增;客户端不能自行设置版本。
|
||||
uint64 revision = 4;
|
||||
// Required for custom Create/Update; user_pose is computed by server, never trusted as input.
|
||||
repeated CoordinateCalibrationPoint calibration_points = 5;
|
||||
uint32 calibration_version = 6;
|
||||
}
|
||||
message UserCoordinateSystemCommand {
|
||||
message Request {
|
||||
CommandHeader.Request header = 1;
|
||||
// Create/Update 使用 coordinate;名称不变,修改名称请新建后删除原记录。
|
||||
UserCoordinateSystem coordinate = 2;
|
||||
// Get/Delete/Apply 使用 name;List 不需要名称。
|
||||
string name = 3;
|
||||
// Update/Delete 必须等于当前版本;Apply 为 0 时使用最新版本。
|
||||
uint64 expected_revision = 4;
|
||||
}
|
||||
message Response {
|
||||
CommandHeader.Feedback header = 1;
|
||||
// Create/Get/Update/Delete/Apply 返回处理的记录。
|
||||
UserCoordinateSystem coordinate = 2;
|
||||
// List 返回所有记录;查询和 CRUD 不设置控制器、不运动。
|
||||
repeated UserCoordinateSystem coordinates = 3;
|
||||
// Apply 成功后实际回读的 TCP。工件坐标没有完整回读接口,SDK成功码并非持久化证明。
|
||||
repeated double actual_tcp_offset = 4;
|
||||
bool work_object_acknowledged = 5;
|
||||
// 本服务本次运行中最后成功应用的记录;不是 SDK 工件坐标实时回读。
|
||||
string last_applied_name = 6;
|
||||
uint64 last_applied_revision = 7;
|
||||
bool application_known = 8;
|
||||
}
|
||||
}
|
||||
message MoveL {
|
||||
// MoveL 请求。
|
||||
message Request {
|
||||
// 通用请求头,包含目标设备 ID 和请求时间戳。
|
||||
CommandHeader.Request header = 1;
|
||||
// TCP 目标位姿;位置单位为 m,姿态单位为 rad。
|
||||
// 所选坐标系下的完整绝对TCP目标位姿:位置m、姿态rad(RzRyRx)。
|
||||
// XYZ/RX/RY/RZ均为目标值,不是增量。重复同一目标不会累加移动。
|
||||
CartesianPose target = 2;
|
||||
// 运动参数;速度/加速度/加加速度单位分别为 m/s、m/s^2、m/s^3。
|
||||
MotionOptions options = 3;
|
||||
@ -123,6 +213,22 @@ message MoveL {
|
||||
optional string base_frame = 5;
|
||||
// 可选 TCP 坐标系名称,无单位;不传或为空时使用驱动配置的默认 TCP 坐标系。
|
||||
optional string tcp_frame = 6;
|
||||
// AUBO explicit host-managed user frame T_base_user, [x,y,z,rx,ry,rz], m/rad.
|
||||
// Both vectors must contain six finite values; cannot combine with named frames.
|
||||
// Compatibility path: configures SDK setWorkObjectData, not pendant persistence.
|
||||
// Prefer server CRUD + ApplyUserCoordinateSystem for named managed records.
|
||||
repeated double user_frame_pose = 7;
|
||||
// T_flange_tcp, [x,y,z,rx,ry,rz], m/rad. Required together with user_frame_pose.
|
||||
repeated double tcp_offset = 8;
|
||||
// 校验当前已应用的服务端坐标系名称,不自动切换;请先调用 ApplyUserCoordinateSystem。
|
||||
// 不传时沿用服务端当前已应用记录;不能与显式位姿或命名世界坐标系同时传入。
|
||||
string user_coordinate_name = 9;
|
||||
// 所选记录的版本号,非零时拒绝执行已被修改的记录。
|
||||
uint64 user_coordinate_revision = 10;
|
||||
// Deprecated increment mode. Must be false or omitted; true returns UNIMPLEMENTED.
|
||||
// Check get_active_tcp_offset.coordinate_api_version >= 4 and
|
||||
// movel_target_mode == "absolute_selected_frame" before using this contract.
|
||||
bool coordinate_relative_translation = 11 [deprecated = true];
|
||||
}
|
||||
|
||||
// MoveL 执行结果。
|
||||
@ -210,6 +316,57 @@ message ServoJ {
|
||||
}
|
||||
}
|
||||
|
||||
// 开始记录实际关节轨迹,CSV 保存在服务端程序目录 data/trajectories/<device_id>。
|
||||
message StartTrajectoryRecording {
|
||||
message Request {
|
||||
// 通用请求头,包含目标设备 ID 和请求时间戳。
|
||||
CommandHeader.Request header = 1;
|
||||
// 不含目录的文件名;不覆盖已有文件,自动补充 .csv。
|
||||
string file_name = 2;
|
||||
// 实际关节采样频率 Hz;0 使用 100,支持 1~100。
|
||||
double sampling_frequency_hz = 3;
|
||||
}
|
||||
|
||||
message Response {
|
||||
// 通用响应头,包含成功标志、错误信息和响应时间戳。
|
||||
CommandHeader.Feedback header = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 已完成且通过校验的 CSV;不包含录制中的 .partial 文件。
|
||||
message RecordedTrajectory {
|
||||
string file_name = 1;
|
||||
uint64 samples = 2;
|
||||
double duration_s = 3;
|
||||
double sampling_frequency_hz = 4;
|
||||
}
|
||||
message ListRecordedTrajectories {
|
||||
message Request { CommandHeader.Request header = 1; }
|
||||
message Response {
|
||||
CommandHeader.Feedback header = 1;
|
||||
repeated RecordedTrajectory trajectories = 2;
|
||||
string directory = 3;
|
||||
bool recording = 4;
|
||||
string recording_file = 5;
|
||||
uint64 recorded_samples = 6;
|
||||
string recording_error = 7;
|
||||
}
|
||||
}
|
||||
message ReplayRecordedTrajectory {
|
||||
message Request {
|
||||
CommandHeader.Request header = 1;
|
||||
string file_name = 2;
|
||||
// 0 使用原速;支持 0.1~1,只允许降速。
|
||||
double speed_ratio = 3;
|
||||
// 平滑限值;0 使用默认值 0.3 rad/s、0.5 rad/s²、2 rad/s³。
|
||||
// 回放经 BSplineSmoother 重新定时,可能偏离原始中间点;首尾保持不变。
|
||||
double max_velocity = 4;
|
||||
double max_acceleration = 5;
|
||||
double max_jerk = 6;
|
||||
}
|
||||
message Response { CommandHeader.Feedback header = 1; }
|
||||
}
|
||||
|
||||
// 机械臂关节状态。
|
||||
message JointState {
|
||||
// 关节名称列表,无单位;与 position、velocity、effort 按索引对应。
|
||||
@ -222,6 +379,8 @@ message JointState {
|
||||
repeated double effort = 4;
|
||||
// 状态采样的 Unix 时间戳,单位:s。
|
||||
double timestamp = 5;
|
||||
// 电机实际电流,单位:mA。
|
||||
repeated double current = 6;
|
||||
}
|
||||
|
||||
// 查询关节状态的请求。
|
||||
@ -238,13 +397,79 @@ message JointResponse {
|
||||
JointState state = 2;
|
||||
}
|
||||
|
||||
// 机械臂静态能力与 SDK 自动识别信息。
|
||||
// Per-joint position limits, matched by name; radians. Missing/invalid limits are not zero limits.
|
||||
message ArmJointLimit {
|
||||
string joint_name = 1;
|
||||
bool position_limits_available = 2;
|
||||
double lower = 3;
|
||||
double upper = 4;
|
||||
// aubo_sdk: controller readback; driver_model: driver model/configuration/URDF, not hardware readback.
|
||||
string source = 5;
|
||||
}
|
||||
message GetArmInfo {
|
||||
message Request {
|
||||
CommandHeader.Request header = 1;
|
||||
}
|
||||
|
||||
message Response {
|
||||
CommandHeader.Feedback header = 1;
|
||||
string device_id = 2;
|
||||
string manufacturer = 3;
|
||||
string model = 4;
|
||||
string subtype = 5;
|
||||
uint32 dof = 6;
|
||||
repeated string joint_names = 7;
|
||||
string default_base_frame = 8;
|
||||
string default_tcp_frame = 9;
|
||||
string description_id = 10;
|
||||
bool detected_from_sdk = 11;
|
||||
string driver_type = 12;
|
||||
repeated ArmJointLimit joint_limits = 13;
|
||||
}
|
||||
}
|
||||
|
||||
message RobotState {
|
||||
double timestamp = 1;
|
||||
ArmRobotMode robot_mode = 2;
|
||||
ArmSafetyMode safety_mode = 3;
|
||||
ArmControlMode control_mode = 4;
|
||||
bool connected = 5;
|
||||
bool powered_on = 6;
|
||||
bool brake_released = 7;
|
||||
bool moving = 8;
|
||||
bool program_running = 9;
|
||||
bool protective_stopped = 10;
|
||||
bool emergency_stopped = 11;
|
||||
bool fault = 12;
|
||||
double speed_scaling = 13;
|
||||
JointState actual_joint_state = 14;
|
||||
JointState target_joint_state = 15;
|
||||
CartesianPose actual_tcp_pose = 16;
|
||||
CartesianVelocity actual_tcp_velocity = 17;
|
||||
CartesianWrench actual_tcp_wrench = 18;
|
||||
}
|
||||
|
||||
message GetRobotState {
|
||||
message Request {
|
||||
CommandHeader.Request header = 1;
|
||||
}
|
||||
|
||||
message Response {
|
||||
CommandHeader.Feedback header = 1;
|
||||
RobotState state = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// 查询 TCP 位姿。
|
||||
message GetPose {
|
||||
// 位姿查询请求。
|
||||
message Request {
|
||||
// 通用请求头,包含目标设备 ID 和请求时间戳。
|
||||
CommandHeader.Request header = 1;
|
||||
// 参考坐标系名称,无单位;为空时使用驱动默认基准坐标系。
|
||||
// 参考坐标系名称。遨博支持空/base/__builtin_base__(基座)、已保存的自定义坐标系名称,
|
||||
// 以及 __builtin_tool__(必须先 Apply,使用 Apply 时冻结的工具参考系)。
|
||||
// 自定义系按服务端当前保存的定义转换实际反馈;查询不切换当前应用,不触发运动。
|
||||
string base_link = 2;
|
||||
// 末端坐标系名称,无单位;为空时使用驱动默认 TCP 坐标系。
|
||||
string ee_link = 3;
|
||||
@ -256,6 +481,11 @@ message GetPose {
|
||||
CommandHeader.Feedback header = 1;
|
||||
// TCP 位姿;位置单位为 m,姿态单位为 rad。
|
||||
CartesianPose pose = 2;
|
||||
// 实际返回位姿的参考坐标系:base 或请求的已保存坐标系名称。
|
||||
// SDK 原生反馈始终在 Base 下;请求自定义系时由服务端使用 SDK Math 转换。
|
||||
string reference_frame = 3;
|
||||
// 实际返回的末端:tcp 为当前工具中心点,flange 为法兰。
|
||||
string end_frame = 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ service ArmService {
|
||||
rpc clearFault(CommandHeader.Request) returns (CommandHeader.Feedback);
|
||||
// 执行关节空间点到点运动;目标角度单位为 rad。
|
||||
rpc moveJ(MoveJ.Request) returns (MoveJ.Response);
|
||||
// 执行 TCP 笛卡尔直线运动;位置单位为 m,姿态单位为 rad。
|
||||
// 执行所选坐标系下的绝对TCP目标直线运动,位置m、姿态rad;不接受增量目标。
|
||||
rpc moveL(MoveL.Request) returns (MoveL.Response);
|
||||
// 查询可用基准坐标系名称;返回名称列表,无单位。
|
||||
rpc ListBaseFrame(ListFrame.Request) returns (ListFrame.Response);
|
||||
@ -29,8 +29,12 @@ service ArmService {
|
||||
rpc servoJ(ServoJ.Request) returns (ServoJ.Response);
|
||||
// 停止当前机械臂运动;不包含数值参数,无单位。
|
||||
rpc stopMotion(CommandHeader.Request) returns (CommandHeader.Feedback);
|
||||
// 查询机械臂 SDK 自动识别的型号、自由度、关节名及默认坐标系。
|
||||
rpc GetArmInfo(GetArmInfo.Request) returns (GetArmInfo.Response);
|
||||
// 读取关节状态;角度 rad、角速度 rad/s、力矩 N·m。
|
||||
rpc getJointState(JointRequest) returns (JointResponse);
|
||||
// 一次性读取完整机械臂运行状态、关节状态及 TCP 位姿。
|
||||
rpc getRobotState(GetRobotState.Request) returns (GetRobotState.Response);
|
||||
// 读取 TCP 位姿;位置单位为 m,姿态单位为 rad。
|
||||
rpc getPose(GetPose.Request) returns (GetPose.Response);
|
||||
// 对指定关节执行零位标定;关节名称无单位。
|
||||
@ -41,4 +45,32 @@ service ArmService {
|
||||
rpc computeForwardKinematics(ComputeForwardKinematics.Request) returns (ComputeForwardKinematics.Response);
|
||||
// 执行机械臂厂商扩展 JSON 命令;当前用于 AUBO 控制柜 Standard DI/DO。
|
||||
rpc ExecuteJsonCommand(JsonDeviceCommand.Request) returns (JsonDeviceCommand.Feedback);
|
||||
// 进入拖动示教模式;仅支持具备该能力的机械臂。
|
||||
rpc EnterTeachingMode(CommandHeader.Request) returns (CommandHeader.Feedback);
|
||||
// 开始记录实际关节轨迹到服务端 CSV。
|
||||
rpc StartTrajectoryRecording(StartTrajectoryRecording.Request) returns (StartTrajectoryRecording.Response);
|
||||
// 完成示教:停止轨迹记录并退出拖动示教模式。
|
||||
rpc CompleteTeaching(CommandHeader.Request) returns (CommandHeader.Feedback);
|
||||
// 单独停止轨迹记录,不退出拖动示教模式。
|
||||
rpc StopTrajectoryRecording(CommandHeader.Request) returns (CommandHeader.Feedback);
|
||||
// 单独退出拖动示教模式,不停止轨迹记录。
|
||||
rpc ExitTeachingMode(CommandHeader.Request) returns (CommandHeader.Feedback);
|
||||
// 查询 CSV 轨迹及当前录制状态,不启动采样或运动。
|
||||
rpc ListRecordedTrajectories(ListRecordedTrajectories.Request) returns (ListRecordedTrajectories.Response);
|
||||
// 按请求的速度、加速度、加加速度限值平滑运动到轨迹起点;必须退出示教且已使能。
|
||||
rpc MoveToTrajectoryStart(ReplayRecordedTrajectory.Request) returns (ReplayRecordedTrajectory.Response);
|
||||
// 同步回放;必须先到达起点,结束后返回。取消请求会停止运动。
|
||||
rpc ReplayRecordedTrajectory(ReplayRecordedTrajectory.Request) returns (ReplayRecordedTrajectory.Response);
|
||||
// 以下记录保存在服务端程序目录 data/user_coordinates/<device_id>/coordinates.json。
|
||||
// Three-point SDK calibration only; no persistence, TCP write or movement.
|
||||
rpc CalibrateUserCoordinateSystem(UserCoordinateSystemCommand.Request) returns (UserCoordinateSystemCommand.Response);
|
||||
rpc CreateUserCoordinateSystem(UserCoordinateSystemCommand.Request) returns (UserCoordinateSystemCommand.Response);
|
||||
rpc GetUserCoordinateSystem(UserCoordinateSystemCommand.Request) returns (UserCoordinateSystemCommand.Response);
|
||||
rpc ListUserCoordinateSystems(UserCoordinateSystemCommand.Request) returns (UserCoordinateSystemCommand.Response);
|
||||
rpc UpdateUserCoordinateSystem(UserCoordinateSystemCommand.Request) returns (UserCoordinateSystemCommand.Response);
|
||||
rpc DeleteUserCoordinateSystem(UserCoordinateSystemCommand.Request) returns (UserCoordinateSystemCommand.Response);
|
||||
// 实际调用 setWorkObjectData + setTcpOffset,并在服务端记住当前选择。
|
||||
// MoveL 通过 SDK Math 将所选工件系目标转换至 Base;提交前中和原生 WorkObject,避免重复变换。
|
||||
// 不运动、不写示教器命名配置库;SDK 工件系无完整回读,重连/服务重启后应重新应用。
|
||||
rpc ApplyUserCoordinateSystem(UserCoordinateSystemCommand.Request) returns (UserCoordinateSystemCommand.Response);
|
||||
}
|
||||
|
||||
@ -2,9 +2,29 @@ syntax = "proto3";
|
||||
|
||||
package cmvr.api;
|
||||
import "cmvr/api/biohead_command.proto";
|
||||
import "cmvr/api/head_joint_command.proto";
|
||||
|
||||
// 生物头部机器人服务接口
|
||||
service BioHeadService {
|
||||
|
||||
// USB 头部关节控制。
|
||||
rpc ControlHeadJoints(HeadJointCommand.Request)
|
||||
returns (HeadJointCommand.Feedback);
|
||||
|
||||
// 查询 USB 头部的配置、连接和命令目标缓存。
|
||||
rpc GetHeadJointState(GetHeadJointStateCommand.Request)
|
||||
returns (GetHeadJointStateCommand.Feedback);
|
||||
|
||||
|
||||
|
||||
// Complete five-joint expression transition, with per-frame cancellation.
|
||||
rpc SetHeadExpression(SetHeadExpressionCommand.Request)
|
||||
returns (SetHeadExpressionCommand.Feedback);
|
||||
|
||||
// Play one configured preset by exact ID or exact name.
|
||||
rpc PlayHeadExpression(PlayHeadExpressionCommand.Request)
|
||||
returns (PlayHeadExpressionCommand.Feedback);
|
||||
|
||||
// 设置面部表情
|
||||
rpc SetExpression(SetFacialExpression.Request) returns (SetFacialExpression.Feedback){};
|
||||
|
||||
@ -37,11 +57,4 @@ service BioHeadService {
|
||||
|
||||
rpc ExpressionYawn(ExpressionYawn.Request) returns (ExpressionYawn.Feedback){};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,198 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package cmvr.api;
|
||||
|
||||
import "cmvr/api/common.proto";
|
||||
|
||||
// 头部关节运动模式。
|
||||
enum HeadJointMotionMode {
|
||||
HEAD_JOINT_MOTION_IMMEDIATE = 0;
|
||||
HEAD_JOINT_MOTION_S_CURVE = 1;
|
||||
HEAD_JOINT_MOTION_FOLLOW = 2;
|
||||
}
|
||||
|
||||
// 最近一次设备命令的处理结果。
|
||||
enum HeadJointCommandOutcome {
|
||||
HEAD_JOINT_COMMAND_NONE = 0;
|
||||
HEAD_JOINT_COMMAND_ACKNOWLEDGED = 1;
|
||||
HEAD_JOINT_COMMAND_REJECTED = 2;
|
||||
HEAD_JOINT_COMMAND_UNKNOWN = 3;
|
||||
}
|
||||
|
||||
// 一个关节的目标位置。
|
||||
message HeadJointTarget {
|
||||
string id = 1;
|
||||
|
||||
// 单位:rad。
|
||||
// 区分“没有填写目标”和“明确要求移动到 0 rad”。
|
||||
oneof target {
|
||||
double position_rad = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// 从设备配置中取得的关节信息。
|
||||
message HeadJointInfo {
|
||||
string id = 1;
|
||||
double min_position_rad = 2;
|
||||
double max_position_rad = 3;
|
||||
double home_position_rad = 4;
|
||||
}
|
||||
|
||||
// 最近一次获得固件 ACK 的目标缓存。
|
||||
// 这里保存的是命令目标,不是机械位置测量值。
|
||||
message HeadJointTargetState {
|
||||
string id = 1;
|
||||
double target_position_rad = 2;
|
||||
bool target_valid = 3;
|
||||
}
|
||||
|
||||
// 头部关节控制命令。
|
||||
message HeadJointCommand {
|
||||
// 单路或多路目标控制。
|
||||
message Move {
|
||||
// 本次未列出的通道不参与目标下发。
|
||||
// 驱动会拒绝重复的通道 ID。
|
||||
repeated HeadJointTarget targets = 1;
|
||||
}
|
||||
|
||||
// 显式移动到配置中的 home 位置。
|
||||
message Home {}
|
||||
|
||||
// Reopen and probe service 1 without sending any position target.
|
||||
message Reconnect {}
|
||||
|
||||
// Cancel later host-side expression frames; this is not a hardware stop.
|
||||
message CancelExpression {}
|
||||
|
||||
// 设置设备运动模式。
|
||||
message Mode {
|
||||
// 区分未填写和明确选择 IMMEDIATE。
|
||||
oneof value {
|
||||
HeadJointMotionMode mode = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 设置指定关节的运动约束。
|
||||
message Constraints {
|
||||
string id = 1;
|
||||
double max_velocity_rad_s = 2;
|
||||
double max_acceleration_rad_s2 = 3;
|
||||
double max_jerk_rad_s3 = 4;
|
||||
}
|
||||
|
||||
// 设置指定关节的位置增益。
|
||||
message PositionGain {
|
||||
string id = 1;
|
||||
|
||||
// 0 是合法增益,需要与未填写区分。
|
||||
oneof value {
|
||||
double gain = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// 设置设备更新周期,单位:ms。
|
||||
message UpdatePeriod {
|
||||
uint32 period_ms = 1;
|
||||
}
|
||||
|
||||
message Request {
|
||||
CommandHeader.Request header = 1;
|
||||
|
||||
// 一条请求明确执行一项操作。
|
||||
oneof operation {
|
||||
Move move = 2;
|
||||
Home home = 3;
|
||||
Mode mode = 4;
|
||||
Constraints constraints = 5;
|
||||
PositionGain position_gain = 6;
|
||||
UpdatePeriod update_period = 7;
|
||||
Reconnect reconnect = 8;
|
||||
CancelExpression cancel_expression = 9;
|
||||
}
|
||||
}
|
||||
|
||||
message Feedback {
|
||||
// Move/configuration: success means firmware ACK, not mechanical arrival.
|
||||
// Reconnect: success means open + service-1 probe, without automatic motion.
|
||||
// CancelExpression: success means cancellation was requested for later host
|
||||
// frames, not that firmware trajectory/PWM or the mechanism was stopped.
|
||||
// A timed-out write may already have taken effect; do not blindly retry.
|
||||
CommandHeader.Feedback header = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 查询头部驱动的配置和缓存状态。
|
||||
message GetHeadJointStateCommand {
|
||||
message Request {
|
||||
CommandHeader.Request header = 1;
|
||||
}
|
||||
|
||||
message Feedback {
|
||||
// success=true 表示成功取得驱动状态。
|
||||
// 设备连接和命令结果仍需检查下面的对应字段。
|
||||
CommandHeader.Feedback header = 1;
|
||||
|
||||
// 表示串口传输连接状态,不是持续的硬件健康检测。
|
||||
bool connected = 2;
|
||||
|
||||
// 配置中的关节信息,不是从控制板读取的标定。
|
||||
repeated HeadJointInfo joint_info = 3;
|
||||
|
||||
// 最近一次获得 ACK 的目标及其有效性。
|
||||
repeated HeadJointTargetState targets = 4;
|
||||
|
||||
HeadJointCommandOutcome last_command_outcome = 5;
|
||||
string last_error = 6;
|
||||
|
||||
// 当前 eRPC 服务 1 不提供真实关节位置测量反馈。
|
||||
bool position_feedback_available = 7;
|
||||
|
||||
// Presets come from configuration, not measured hardware poses.
|
||||
repeated HeadExpressionInfo expressions = 8;
|
||||
bool expression_baseline_ready = 9;
|
||||
bool hardware_emergency_stop_available = 10;
|
||||
}
|
||||
}
|
||||
// One configured expression, with a stable ID and an exact display name.
|
||||
message HeadExpressionInfo {
|
||||
string expression_id = 1;
|
||||
string expression_name = 2;
|
||||
repeated HeadJointTarget targets = 3;
|
||||
}
|
||||
|
||||
// Synchronously send a complete five-joint expression through a bounded host
|
||||
// transition. Omitted joints and partial expressions are rejected.
|
||||
message SetHeadExpressionCommand {
|
||||
message Request {
|
||||
CommandHeader.Request header = 1;
|
||||
repeated HeadJointTarget targets = 2;
|
||||
// Finite duration in [0.2, 5.0] seconds; 0 or omission is rejected.
|
||||
double transition_duration_s = 3;
|
||||
}
|
||||
message Feedback {
|
||||
// Every transmitted frame, including the final target, was acknowledged.
|
||||
// This is not proof of mechanical arrival; late intermediate frames may be skipped.
|
||||
CommandHeader.Feedback header = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Select one configured expression by exact stable ID or exact name.
|
||||
// Unknown selectors and ambiguous names are rejected without fallback.
|
||||
message PlayHeadExpressionCommand {
|
||||
message Request {
|
||||
CommandHeader.Request header = 1;
|
||||
oneof expression {
|
||||
string expression_id = 2;
|
||||
string expression_name = 3;
|
||||
}
|
||||
// Finite duration in [0.2, 5.0] seconds; 0 or omission is rejected.
|
||||
double transition_duration_s = 4;
|
||||
}
|
||||
message Feedback {
|
||||
// Every transmitted frame, including the final target, was acknowledged.
|
||||
// This is not proof of mechanical arrival; late intermediate frames may be skipped.
|
||||
CommandHeader.Feedback header = 1;
|
||||
string expression_id = 2;
|
||||
string expression_name = 3;
|
||||
}
|
||||
}
|
||||
@ -37,6 +37,12 @@ public class AeViEvaluationVO {
|
||||
@ApiModelProperty(value = "失败数")
|
||||
private Integer failureCount;
|
||||
|
||||
private Integer analysisErrorCount;
|
||||
|
||||
private String detectionItemName;
|
||||
|
||||
private Integer workflowVersionNo;
|
||||
|
||||
@ApiModelProperty(value = "方案ID")
|
||||
private String schemeId;
|
||||
|
||||
@ -95,6 +101,15 @@ public class AeViEvaluationVO {
|
||||
@ApiModelProperty(value = "执行证据截图")
|
||||
private List<String> screenshotUrls;
|
||||
|
||||
private String iteration;
|
||||
|
||||
private String expectedResult;
|
||||
|
||||
private String modelName;
|
||||
|
||||
private List<VideoEvent> videoEvents;
|
||||
}
|
||||
|
||||
public record VideoEvent(String timeRange, String event) {}
|
||||
}
|
||||
|
||||
|
||||
@ -66,12 +66,30 @@ public enum ActionEnum {
|
||||
// 末端运动
|
||||
ARM_MOVE_TO_POINT("EDGE", "ARM_MOVE_TO_POINT", "运动到指定点"),
|
||||
ARM_MOVE_TO_J("EDGE", "ARM_MOVE_TO_J", "关节空间运动"),
|
||||
ARM_NECK_GET_INFO("EDGE", "ARM_NECK_GET_INFO", "查询颈部关节配置"),
|
||||
ARM_NECK_GET_JOINT_STATE("EDGE", "ARM_NECK_GET_JOINT_STATE", "查询颈部关节状态"),
|
||||
ARM_NECK_GET_STATE("EDGE", "ARM_NECK_GET_STATE", "查询颈部运行状态"),
|
||||
ARM_NECK_MOVE_J("EDGE", "ARM_NECK_MOVE_J", "颈部三轴关节运动"),
|
||||
ARM_NECK_STOP("EDGE", "ARM_NECK_STOP", "停止颈部运动"),
|
||||
ARM_NECK_ENABLE("EDGE", "ARM_NECK_ENABLE", "开启颈部使能"),
|
||||
ARM_NECK_DISABLE("EDGE", "ARM_NECK_DISABLE", "关闭颈部使能"),
|
||||
// 开始使能
|
||||
ARM_ENABLE("EDGE", "ARM_ENABLE", "使能"),
|
||||
// 停止使能
|
||||
ARM_DISABLE("EDGE", "ARM_DISABLE", "停止使能"),
|
||||
|
||||
// --------------- 头部 ---------------
|
||||
BIO_HEAD_JOINT_MOVE("EDGE", "BIO_HEAD_JOINT_MOVE", "头部关节运动"),
|
||||
BIO_HEAD_JOINT_HOME("EDGE", "BIO_HEAD_JOINT_HOME", "头部回零"),
|
||||
BIO_HEAD_JOINT_RECONNECT("EDGE", "BIO_HEAD_JOINT_RECONNECT", "头部重新连接"),
|
||||
BIO_HEAD_JOINT_MODE("EDGE", "BIO_HEAD_JOINT_MODE", "头部设置运动模式"),
|
||||
BIO_HEAD_JOINT_CONSTRAINTS("EDGE", "BIO_HEAD_JOINT_CONSTRAINTS", "头部设置关节约束"),
|
||||
BIO_HEAD_JOINT_POSITION_GAIN("EDGE", "BIO_HEAD_JOINT_POSITION_GAIN", "头部设置位置增益"),
|
||||
BIO_HEAD_JOINT_UPDATE_PERIOD("EDGE", "BIO_HEAD_JOINT_UPDATE_PERIOD", "头部设置更新周期"),
|
||||
BIO_HEAD_JOINT_CANCEL_EXPRESSION("EDGE", "BIO_HEAD_JOINT_CANCEL_EXPRESSION", "头部取消后续表情帧"),
|
||||
BIO_HEAD_JOINT_GET_STATE("EDGE", "BIO_HEAD_JOINT_GET_STATE", "头部查询关节状态"),
|
||||
BIO_HEAD_JOINT_SET_EXPRESSION("EDGE", "BIO_HEAD_JOINT_SET_EXPRESSION", "头部设置关节表情"),
|
||||
BIO_HEAD_JOINT_PLAY_EXPRESSION("EDGE", "BIO_HEAD_JOINT_PLAY_EXPRESSION", "头部播放预设表情"),
|
||||
BIO_HEAD_SPEAK_START("EDGE", "BIO_HEAD_SPEAK_START", "开始说话"),
|
||||
BIO_HEAD_SPEAK_STOP("EDGE", "BIO_HEAD_SPEAK_STOP", "停止说话"),
|
||||
BIO_HEAD_SPECIAL_EXPRESSION("EDGE", "BIO_HEAD_SPECIAL_EXPRESSION", "表情,1:高兴,2:惊讶,3:疲惫"),
|
||||
|
||||
@ -47,8 +47,7 @@ public class FlowLoopNodeHandler implements FlowNodeTypeHandler {
|
||||
log.warn("循环节点 {} 没有有效的 loopCount 参数,跳过处理", nodeId);
|
||||
return TaskNodeExecuteResult.success(inputParams);
|
||||
}
|
||||
FlowGraph subGraph = nodeWrapper.getSubGraph();
|
||||
subGraph.setSub(true);
|
||||
FlowGraph loopBody = nodeWrapper.getSubGraph();
|
||||
|
||||
// 循环执行子图
|
||||
for (int i = loopStartNum; i <= loopCount; i++) {
|
||||
@ -57,11 +56,7 @@ public class FlowLoopNodeHandler implements FlowNodeTypeHandler {
|
||||
log.info("任务已结束,退出循环:instId={}, nodeId={}, nextIteration={}", instId, nodeId, i);
|
||||
break;
|
||||
}
|
||||
// 如果子图设置了跳出标志,则结束循环
|
||||
if (subGraph.isBreakLoop()) {
|
||||
log.info("检测到子图设置跳出标志,提前结束循环:instId={}, nodeId={}", instId, nodeId);
|
||||
break;
|
||||
}
|
||||
FlowGraph subGraph = newIterationGraph(loopBody);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
taskThreadRegistry.registerLatch(instId, nodeId, latch);
|
||||
@ -93,6 +88,10 @@ public class FlowLoopNodeHandler implements FlowNodeTypeHandler {
|
||||
} finally {
|
||||
taskThreadRegistry.releaseLatch(instId, nodeId);
|
||||
}
|
||||
if (subGraph.isBreakLoop()) {
|
||||
log.info("检测到子图设置跳出标志,提前结束循环:instId={}, nodeId={}", instId, nodeId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 返回执行结果
|
||||
@ -102,4 +101,15 @@ public class FlowLoopNodeHandler implements FlowNodeTypeHandler {
|
||||
protected FlowItemExecutor getFlowItemExecutor() {
|
||||
return SpringUtils.getBean(FlowItemExecutor.class);
|
||||
}
|
||||
|
||||
private FlowGraph newIterationGraph(FlowGraph loopBody) {
|
||||
// 分支会剪去本轮未命中的路径,下一轮仍需从完整的循环体执行。
|
||||
FlowGraph iteration = new FlowGraph();
|
||||
iteration.setSub(true);
|
||||
iteration.getNodeMap().putAll(loopBody.getNodeMap());
|
||||
iteration.setNodeParamsDefs(loopBody.getNodeParamsDefs());
|
||||
iteration.setStartInputParamsDefs(loopBody.getStartInputParamsDefs());
|
||||
loopBody.getSuccessors().values().forEach(edges -> edges.forEach(iteration::addEdge));
|
||||
return iteration;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.cmvr.common.exception.GlobalException;
|
||||
import com.cmvr.edge.client.model.NeckDeviceIds;
|
||||
import com.cmvr.test.model.vo.ResourceRuntimeAssignmentVO;
|
||||
import com.cmvr.test.model.vo.RobotRuntimeMemberVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -80,6 +81,14 @@ public class FlowRuntimeDefinitionValidator {
|
||||
if (slotRequired && (required || roleAssigned) && StrUtil.isBlank(deviceId)) {
|
||||
throw new GlobalException("设备用途[" + slot.getString("displayName") + "]未分配真实设备");
|
||||
}
|
||||
String requiredDeviceId = slot.getString("requiredDeviceId");
|
||||
if (StrUtil.isNotBlank(deviceId) && StrUtil.isNotBlank(requiredDeviceId)
|
||||
&& !NeckDeviceIds.matchesRequiredId(requiredDeviceId, deviceId)) {
|
||||
String allowedDevice = NeckDeviceIds.isNeck(requiredDeviceId)
|
||||
? "neck_arm 或 xiaozhao_head" : requiredDeviceId;
|
||||
throw new GlobalException("设备用途[" + slot.getString("displayName")
|
||||
+ "]必须使用设备 " + allowedDevice);
|
||||
}
|
||||
validatePhysicalDevice(member, deviceId, slot.getInteger("deviceKind"));
|
||||
if (member != null && StrUtil.isNotBlank(member.getRobotId()) && StrUtil.isNotBlank(deviceId)) {
|
||||
String physicalKey = member.getRobotId() + ":" + deviceId;
|
||||
|
||||
@ -13,6 +13,7 @@ import com.cmvr.test.enums.TaskStatusEnum;
|
||||
import com.cmvr.test.flow.context.TaskContext;
|
||||
import com.cmvr.test.flow.context.TaskInstHolder;
|
||||
import com.cmvr.test.model.domain.TeTaskInst;
|
||||
import com.cmvr.test.model.domain.TeDetectionItemVersion;
|
||||
import com.cmvr.test.model.dto.TeQueryTaskDetailDTO;
|
||||
import com.cmvr.test.model.domain.TeTaskInstFlowVersion;
|
||||
import com.cmvr.test.model.vo.TeTaskExecuteNormalVO;
|
||||
@ -23,6 +24,7 @@ import com.cmvr.test.model.vo.RobotRuntimeMemberVO;
|
||||
import com.cmvr.test.service.ITeTaskInstFlowVersionService;
|
||||
import com.cmvr.test.service.ITeTaskInstService;
|
||||
import com.cmvr.test.service.ITeTaskOrchestrationService;
|
||||
import com.cmvr.test.service.ITeDetectionItemVersionService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -53,6 +55,7 @@ public class FlowTaskRuntimeEntry implements FlowTaskRuntimeService {
|
||||
private final FlowTaskAsyncDispatcher flowTaskAsyncDispatcher;
|
||||
private final ObjectProvider<RobotExecutionTargetResolver> targetResolverProvider;
|
||||
private final FlowRuntimeDefinitionValidator runtimeDefinitionValidator;
|
||||
private final ITeDetectionItemVersionService detectionItemVersionService;
|
||||
|
||||
|
||||
|
||||
@ -193,7 +196,27 @@ public class FlowTaskRuntimeEntry implements FlowTaskRuntimeService {
|
||||
String robotId = target.getRobotId();
|
||||
assertResourcesAvailable(resources);
|
||||
// 查询任务详情(检测项信息)
|
||||
List<TeQueryTaskDetailDTO> details = new ArrayList<>(taskOrchestrationService.queryTaskDetail(taskId));
|
||||
List<TeQueryTaskDetailDTO> details;
|
||||
if (runMode == RunModeEnum.TI_PROJECT && originalVO instanceof TeTaskExecuteProjectVO request
|
||||
&& StrUtil.isNotBlank(request.getItemId())) {
|
||||
TeDetectionItemVersion version = detectionItemVersionService.getVersion(request.getVersionId());
|
||||
if (!StrUtil.equals(request.getItemId(), version.getDetectionItemId())) {
|
||||
throw new GlobalException("检测项与发布版本不匹配");
|
||||
}
|
||||
TeQueryTaskDetailDTO detail = new TeQueryTaskDetailDTO();
|
||||
detail.setDetectItemId(request.getItemId());
|
||||
detail.setVersionId(version.getId());
|
||||
detail.setVersionNo(version.getVersionNo());
|
||||
detail.setFlowData(version.getFlowData());
|
||||
detail.setConfig(version.getConfig());
|
||||
detail.setOrderNum(1);
|
||||
details = new ArrayList<>(List.of(detail));
|
||||
} else {
|
||||
details = new ArrayList<>(taskOrchestrationService.queryTaskDetail(taskId));
|
||||
}
|
||||
if (runMode == RunModeEnum.TI_PROJECT && details.isEmpty()) {
|
||||
throw new GlobalException("请选择要执行的已发布检测项");
|
||||
}
|
||||
details.sort(Comparator.comparing(TeQueryTaskDetailDTO::getOrderNum,
|
||||
Comparator.nullsLast(Integer::compareTo)));
|
||||
TeQueryTaskDetailDTO unpublished = details.stream()
|
||||
|
||||
@ -27,6 +27,8 @@ public final class FlowExecutionModuleCodes {
|
||||
*/
|
||||
public static final String TI = "TI";
|
||||
|
||||
public static final String TI_VIDEO = "TI_VIDEO";
|
||||
|
||||
private FlowExecutionModuleCodes() {
|
||||
// 防止实例化
|
||||
}
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
package com.cmvr.test.flow.runtime.operator.edge;
|
||||
|
||||
import cmvr.api.ArmCommand;
|
||||
import cmvr.api.Common;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.cmvr.common.exception.GlobalException;
|
||||
import com.cmvr.edge.client.model.EdgeCommonVO;
|
||||
import com.cmvr.edge.client.model.NeckDeviceIds;
|
||||
import com.cmvr.edge.client.service.EdgeArmService;
|
||||
import com.cmvr.test.enums.ActionEnum;
|
||||
import com.cmvr.test.flow.runtime.message.TaskNodeExecuteMessage;
|
||||
@ -53,6 +56,9 @@ public class EdgeArmOperateService implements EdgeOperateService {
|
||||
if (action == null) {
|
||||
throw new GlobalException("机械臂动作不能为空");
|
||||
}
|
||||
if (action.name().startsWith("ARM_NECK_")) {
|
||||
return executeNeckAction(action, edgeCommonVO, inputParams);
|
||||
}
|
||||
|
||||
if (action == ActionEnum.ARM_ENABLE) {
|
||||
log.info("开启机械臂使能,设备ID: {}", deviceId);
|
||||
@ -108,6 +114,96 @@ public class EdgeArmOperateService implements EdgeOperateService {
|
||||
return TaskNodeExecuteResult.success();
|
||||
}
|
||||
|
||||
private TaskNodeExecuteResult executeNeckAction(ActionEnum action, EdgeCommonVO device, JSONObject params) {
|
||||
// 颈部和机械臂在边端都注册为 RobotArm,不能只按设备类型判断。
|
||||
if (!NeckDeviceIds.isNeck(device.getDeviceId())) {
|
||||
throw new GlobalException("颈部节点只能使用颈部设备 neck_arm 或 xiaozhao_head");
|
||||
}
|
||||
return switch (action) {
|
||||
case ARM_NECK_GET_INFO -> {
|
||||
ArmCommand.GetArmInfo.Response result = edgeArmService.getArmInfo(device);
|
||||
requireNeckFeedback(result.getHeader());
|
||||
yield TaskNodeExecuteResult.success(JSONObject.of(
|
||||
"deviceId", result.getDeviceId(), "model", result.getModel(),
|
||||
"dof", result.getDof(), "jointNames", result.getJointNamesList(),
|
||||
"jointLimits", result.getJointLimitsList().stream().map(limit -> {
|
||||
JSONObject value = JSONObject.of("jointName", limit.getJointName(),
|
||||
"available", limit.getPositionLimitsAvailable(), "source", limit.getSource());
|
||||
if (limit.getPositionLimitsAvailable()) {
|
||||
value.put("lowerRad", limit.getLower());
|
||||
value.put("upperRad", limit.getUpper());
|
||||
}
|
||||
return value;
|
||||
}).toList()));
|
||||
}
|
||||
case ARM_NECK_GET_JOINT_STATE -> {
|
||||
ArmCommand.JointResponse result = edgeArmService.getJointState(device);
|
||||
requireNeckFeedback(result.getHeader());
|
||||
ArmCommand.JointState state = result.getState();
|
||||
yield TaskNodeExecuteResult.success(JSONObject.of("jointNames", state.getNameList(),
|
||||
"positionRad", state.getPositionList(), "velocityRadS", state.getVelocityList(),
|
||||
"effortNm", state.getEffortList(), "currentMa", state.getCurrentList(),
|
||||
"timestampS", state.getTimestamp()));
|
||||
}
|
||||
case ARM_NECK_GET_STATE -> {
|
||||
ArmCommand.GetRobotState.Response result = edgeArmService.getRobotState(device);
|
||||
requireNeckFeedback(result.getHeader());
|
||||
ArmCommand.RobotState state = result.getState();
|
||||
yield TaskNodeExecuteResult.success(JSONObject.of(
|
||||
"connected", state.getConnected(), "poweredOn", state.getPoweredOn(),
|
||||
"moving", state.getMoving(), "fault", state.getFault(),
|
||||
"protectiveStopped", state.getProtectiveStopped(),
|
||||
"emergencyStopped", state.getEmergencyStopped(),
|
||||
"robotMode", state.getRobotMode().name(), "safetyMode", state.getSafetyMode().name(),
|
||||
"controlMode", state.getControlMode().name()));
|
||||
}
|
||||
case ARM_NECK_MOVE_J -> {
|
||||
double[] target = parseDoubleArray(params.get("target"), "target", true);
|
||||
if (target.length != 3
|
||||
|| !java.util.Arrays.stream(target).allMatch(Double::isFinite)) {
|
||||
throw new GlobalException("颈部目标必须按设备关节顺序填写三个有限弧度值");
|
||||
}
|
||||
Double velocity = optionalPositive(params, "velocity");
|
||||
Double acceleration = optionalPositive(params, "acceleration");
|
||||
requireNeckFeedback(edgeArmService.moveJ(device, target, velocity, acceleration, null, null, false).getHeader());
|
||||
yield TaskNodeExecuteResult.success();
|
||||
}
|
||||
case ARM_NECK_STOP -> neckCommandResult(edgeArmService.stopMotion(device));
|
||||
case ARM_NECK_ENABLE -> neckCommandResult(edgeArmService.torqueOn(device));
|
||||
case ARM_NECK_DISABLE -> neckCommandResult(edgeArmService.torqueOff(device));
|
||||
default -> throw new GlobalException("不支持的颈部操作: " + action);
|
||||
};
|
||||
}
|
||||
|
||||
private static Double optionalPositive(JSONObject params, String key) {
|
||||
Object raw = params.get(key);
|
||||
if (raw == null || raw instanceof String text && text.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
Double number;
|
||||
try {
|
||||
number = params.getDouble(key);
|
||||
} catch (RuntimeException e) {
|
||||
throw new GlobalException(key + " 必须是有限正数");
|
||||
}
|
||||
if (number == null || !Double.isFinite(number) || number <= 0) {
|
||||
throw new GlobalException(key + " 必须是有限正数");
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
private static TaskNodeExecuteResult neckCommandResult(Common.CommandHeader.Feedback feedback) {
|
||||
requireNeckFeedback(feedback);
|
||||
return TaskNodeExecuteResult.success();
|
||||
}
|
||||
|
||||
private static void requireNeckFeedback(Common.CommandHeader.Feedback feedback) {
|
||||
if (!feedback.getSuccess()) {
|
||||
String error = feedback.getErrorMessage();
|
||||
throw new GlobalException(error.isBlank() ? "边端颈部操作失败" : error);
|
||||
}
|
||||
}
|
||||
|
||||
private void executeMoveJ(EdgeCommonVO edgeCommonVO, JSONObject inputParams) {
|
||||
double[] target = parseDoubleArray(inputParams.get("target"), "target", true);
|
||||
double[] jointVelocityLimits = parseDoubleArray(
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.cmvr.test.flow.runtime.operator.edge;
|
||||
|
||||
import cmvr.api.HeadJointCommandOuterClass.*;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.cmvr.common.exception.GlobalException;
|
||||
import com.cmvr.edge.client.model.EdgeCommonVO;
|
||||
@ -11,6 +13,12 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@ -30,6 +38,12 @@ public class EdgeHeadOperateService implements EdgeOperateService {
|
||||
String robotId = message.getRobotId();
|
||||
String deviceId = inputParams.getString("deviceId");
|
||||
|
||||
if (action.name().startsWith("BIO_HEAD_JOINT_")) {
|
||||
EdgeCommonVO device = new EdgeCommonVO();
|
||||
device.setRobotId(robotId);
|
||||
device.setDeviceId(requiredText(inputParams, "deviceId"));
|
||||
return executeJointAction(action, inputParams, device);
|
||||
}
|
||||
switch (action) {
|
||||
case BIO_HEAD_SPEAK_START: {
|
||||
EdgeCommonVO edgeCommonVO = new EdgeCommonVO();
|
||||
@ -57,4 +71,121 @@ public class EdgeHeadOperateService implements EdgeOperateService {
|
||||
return TaskNodeExecuteResult.success();
|
||||
}
|
||||
|
||||
private TaskNodeExecuteResult executeJointAction(ActionEnum action, JSONObject params, EdgeCommonVO device) {
|
||||
HeadJointCommand.Request.Builder command = HeadJointCommand.Request.newBuilder();
|
||||
switch (action) {
|
||||
case BIO_HEAD_JOINT_GET_STATE:
|
||||
return TaskNodeExecuteResult.success(new JSONObject(edgeBioHeadService.getHeadJointState(device)));
|
||||
case BIO_HEAD_JOINT_SET_EXPRESSION:
|
||||
edgeBioHeadService.setHeadExpression(device, SetHeadExpressionCommand.Request.newBuilder()
|
||||
.addAllTargets(targets(params, true)).setTransitionDurationS(duration(params)));
|
||||
return TaskNodeExecuteResult.success();
|
||||
case BIO_HEAD_JOINT_PLAY_EXPRESSION: {
|
||||
String id = params.getString("expressionId");
|
||||
String name = params.getString("expressionName");
|
||||
boolean hasId = id != null && !id.isBlank();
|
||||
boolean hasName = name != null && !name.isBlank();
|
||||
if (hasId == hasName) throw new GlobalException("表情 ID 和表情名称必须且只能填写一个");
|
||||
PlayHeadExpressionCommand.Request.Builder play = PlayHeadExpressionCommand.Request.newBuilder()
|
||||
.setTransitionDurationS(duration(params));
|
||||
if (hasId) play.setExpressionId(id);
|
||||
else play.setExpressionName(name);
|
||||
return TaskNodeExecuteResult.success(new JSONObject(edgeBioHeadService.playHeadExpression(device, play)));
|
||||
}
|
||||
case BIO_HEAD_JOINT_MOVE:
|
||||
command.setMove(HeadJointCommand.Move.newBuilder().addAllTargets(targets(params, false)));
|
||||
break;
|
||||
case BIO_HEAD_JOINT_HOME:
|
||||
command.setHome(HeadJointCommand.Home.getDefaultInstance());
|
||||
break;
|
||||
case BIO_HEAD_JOINT_RECONNECT:
|
||||
command.setReconnect(HeadJointCommand.Reconnect.getDefaultInstance());
|
||||
break;
|
||||
case BIO_HEAD_JOINT_CANCEL_EXPRESSION:
|
||||
command.setCancelExpression(HeadJointCommand.CancelExpression.getDefaultInstance());
|
||||
break;
|
||||
case BIO_HEAD_JOINT_MODE: {
|
||||
double value = finite(params, "mode");
|
||||
if (value < 0 || value > 2 || value != Math.rint(value)) throw new GlobalException("头部运动模式无效");
|
||||
command.setMode(HeadJointCommand.Mode.newBuilder().setMode(HeadJointMotionMode.forNumber((int) value)));
|
||||
break;
|
||||
}
|
||||
case BIO_HEAD_JOINT_CONSTRAINTS:
|
||||
command.setConstraints(HeadJointCommand.Constraints.newBuilder().setId(requiredText(params, "id"))
|
||||
.setMaxVelocityRadS(positive(params, "maxVelocityRadS"))
|
||||
.setMaxAccelerationRadS2(positive(params, "maxAccelerationRadS2"))
|
||||
.setMaxJerkRadS3(positive(params, "maxJerkRadS3")));
|
||||
break;
|
||||
case BIO_HEAD_JOINT_POSITION_GAIN:
|
||||
command.setPositionGain(HeadJointCommand.PositionGain.newBuilder()
|
||||
.setId(requiredText(params, "id")).setGain(finite(params, "gain")));
|
||||
break;
|
||||
case BIO_HEAD_JOINT_UPDATE_PERIOD: {
|
||||
double period = positive(params, "periodMs");
|
||||
if (period != Math.rint(period) || period > 0xffff_ffffL) throw new GlobalException("更新周期必须是 uint32 正整数");
|
||||
command.setUpdatePeriod(HeadJointCommand.UpdatePeriod.newBuilder().setPeriodMs((int) (long) period));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new GlobalException("不支持的头部关节操作: " + action);
|
||||
}
|
||||
edgeBioHeadService.controlHeadJoints(device, command);
|
||||
return TaskNodeExecuteResult.success();
|
||||
}
|
||||
|
||||
private static List<HeadJointTarget> targets(JSONObject params, boolean completeExpression) {
|
||||
Object value = params.get("targets");
|
||||
Object parsed;
|
||||
try {
|
||||
parsed = value instanceof String ? JSON.parse((String) value) : value;
|
||||
} catch (RuntimeException e) {
|
||||
throw new GlobalException("targets 必须是有效的 JSON 数组");
|
||||
}
|
||||
if (!(parsed instanceof List)) throw new GlobalException("targets 必须是关节目标数组");
|
||||
List<?> rows = (List<?>) parsed;
|
||||
if (rows.isEmpty() || (completeExpression && rows.size() != 5)) {
|
||||
throw new GlobalException(completeExpression ? "关节表情必须提供完整的五个关节目标" : "至少需要一个关节目标");
|
||||
}
|
||||
Set<String> ids = new HashSet<>();
|
||||
List<HeadJointTarget> result = new ArrayList<>();
|
||||
for (Object row : rows) {
|
||||
if (!(row instanceof Map<?, ?> raw)) throw new GlobalException("每个关节目标必须是 JSON 对象");
|
||||
JSONObject joint = new JSONObject();
|
||||
for (String key : List.of("id", "positionRad")) joint.put(key, raw.get(key));
|
||||
String id = requiredText(joint, "id");
|
||||
if (!ids.add(id)) throw new GlobalException("关节重复: " + id);
|
||||
result.add(HeadJointTarget.newBuilder().setId(id).setPositionRad(finite(joint, "positionRad")).build());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String requiredText(JSONObject params, String key) {
|
||||
String value = params.getString(key);
|
||||
if (value == null || value.isBlank()) throw new GlobalException(key + " 不能为空");
|
||||
return value;
|
||||
}
|
||||
|
||||
private static double finite(JSONObject params, String key) {
|
||||
Double value;
|
||||
try {
|
||||
value = params.getDouble(key);
|
||||
} catch (RuntimeException e) {
|
||||
throw new GlobalException(key + " 必须是数字");
|
||||
}
|
||||
if (value == null || !Double.isFinite(value)) throw new GlobalException(key + " 必须是有限数字");
|
||||
return value;
|
||||
}
|
||||
|
||||
private static double positive(JSONObject params, String key) {
|
||||
double value = finite(params, key);
|
||||
if (value <= 0) throw new GlobalException(key + " 必须大于零");
|
||||
return value;
|
||||
}
|
||||
|
||||
private static double duration(JSONObject params) {
|
||||
double value = finite(params, "transitionDurationS");
|
||||
if (value < 0.2 || value > 5) throw new GlobalException("表情过渡时长必须为 0.2–5 秒");
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,6 +19,15 @@ public class TeTaskExecuteProjectVO {
|
||||
@NotEmpty(message = "项目ID不能为空")
|
||||
private String projectId;
|
||||
|
||||
@ApiModelProperty("本次执行的检测项 ID")
|
||||
private String itemId;
|
||||
|
||||
@ApiModelProperty("配置参数时使用的工作流发布版本 ID")
|
||||
private String versionId;
|
||||
|
||||
@ApiModelProperty(value = "检测项名称快照,由项目服务端设置", hidden = true)
|
||||
private String itemName;
|
||||
|
||||
@ApiModelProperty("机器人永久唯一ID")
|
||||
private String robotId;
|
||||
|
||||
|
||||
@ -207,6 +207,9 @@ public class FlowActionExecutorService {
|
||||
return edgeHlcService.touch(edgeTouchVO);
|
||||
|
||||
// ==== 机械臂 ====
|
||||
case ARM_NECK_GET_INFO, ARM_NECK_GET_JOINT_STATE, ARM_NECK_GET_STATE,
|
||||
ARM_NECK_MOVE_J, ARM_NECK_STOP, ARM_NECK_ENABLE, ARM_NECK_DISABLE:
|
||||
return resultToString(edgeArmOperateService.execute(buildSingleNodeMessage(action, payload)));
|
||||
case ARM_MOVE_TO_POINT:
|
||||
case ARM_MOVE_TO_J:
|
||||
case ARM_ENABLE:
|
||||
|
||||
@ -65,6 +65,55 @@ public class FlowLoopNodeHandlerTest {
|
||||
assertEquals(List.of(25D, 49.5D), progress);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restoresBranchPathsEachRoundAndHonorsStopLoop() {
|
||||
TaskContextManager manager = new TaskContextManager();
|
||||
TaskInstHolder holder = new TaskInstHolder(null, manager, null, null);
|
||||
TaskContext context = new TaskContext();
|
||||
context.setInstId("branch-loop");
|
||||
holder.register(context);
|
||||
|
||||
FlowGraph body = new FlowGraph();
|
||||
body.addEdge("branch", "pass", "pass-anchor");
|
||||
body.addEdge("branch", "fail", "fail-anchor");
|
||||
List<Integer> executed = new ArrayList<>();
|
||||
FlowItemExecutor executor = new FlowItemExecutor(null, List.of(), null, holder, null, null, null, null) {
|
||||
@Override
|
||||
public void executeSubGraph(FlowGraph graph, TaskNodeExecuteMessage message,
|
||||
Runnable finished, List<Integer> iterations) {
|
||||
try {
|
||||
executed.add(message.getLoopNum());
|
||||
assertEquals(2, graph.getOutgoingEdges("branch").size());
|
||||
if (message.getLoopNum() == 1) {
|
||||
graph.removeEdge(graph.getEdgeByFromAnchorId("fail-anchor"));
|
||||
} else {
|
||||
graph.setStopLoop(true);
|
||||
}
|
||||
} finally {
|
||||
finished.run();
|
||||
}
|
||||
}
|
||||
};
|
||||
FlowLoopNodeHandler handler = new FlowLoopNodeHandler(new TaskThreadRegistry(), holder) {
|
||||
@Override protected FlowItemExecutor getFlowItemExecutor() { return executor; }
|
||||
};
|
||||
FlowNodeWrapper loop = new FlowNodeWrapper();
|
||||
loop.setNodeId("loop");
|
||||
loop.setSubGraph(body);
|
||||
FlowGraph graph = new FlowGraph();
|
||||
graph.getNodeMap().put("loop", loop);
|
||||
TaskNodeExecuteMessage message = new TaskNodeExecuteMessage();
|
||||
message.setInstId("branch-loop");
|
||||
message.setNodeId("loop");
|
||||
message.setGraph(graph);
|
||||
message.setInputParams(new JSONObject().fluentPut("loopNum", 3));
|
||||
|
||||
handler.handle(message);
|
||||
|
||||
assertEquals(List.of(1, 2), executed);
|
||||
assertEquals(2, body.getOutgoingEdges("branch").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stopsRemainingIterationsAfterTaskContextIsRemoved() {
|
||||
TaskContextManager contextManager = new TaskContextManager();
|
||||
|
||||
@ -56,7 +56,7 @@ public class FlowTaskRuntimeEntrySnapshotTest {
|
||||
ITeTaskInstService.class.getClassLoader(),
|
||||
new Class<?>[]{ITeTaskInstService.class},
|
||||
(proxy, method, args) -> "getById".equals(method.getName()) ? source : null);
|
||||
return new FlowTaskRuntimeEntry(null, service, null, null, null, null, null);
|
||||
return new FlowTaskRuntimeEntry(null, service, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
private TeTaskInst source(String config) {
|
||||
|
||||
@ -0,0 +1,64 @@
|
||||
package com.cmvr.test.flow.runtime.operator.edge;
|
||||
|
||||
import cmvr.api.HeadJointCommandOuterClass.HeadJointCommand;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.cmvr.common.exception.GlobalException;
|
||||
import com.cmvr.edge.client.service.EdgeBioHeadService;
|
||||
import com.cmvr.test.enums.ActionEnum;
|
||||
import com.cmvr.test.flow.runtime.message.TaskNodeExecuteMessage;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class EdgeHeadJointOperateServiceTest {
|
||||
private final List<HeadJointCommand.Request> sent = new ArrayList<>();
|
||||
private final EdgeHeadOperateService service = new EdgeHeadOperateService((EdgeBioHeadService)
|
||||
Proxy.newProxyInstance(EdgeBioHeadService.class.getClassLoader(), new Class<?>[]{EdgeBioHeadService.class},
|
||||
(proxy, method, args) -> {
|
||||
assertEquals("controlHeadJoints", method.getName());
|
||||
sent.add(((HeadJointCommand.Request.Builder) args[1]).build());
|
||||
return null;
|
||||
}));
|
||||
|
||||
@Test
|
||||
public void sendsExplicitZeroAndPreservesTheOneof() {
|
||||
execute(ActionEnum.BIO_HEAD_JOINT_MOVE, new JSONObject().fluentPut("targets", "[{\"id\":\"joint1\",\"positionRad\":0}]"));
|
||||
execute(ActionEnum.BIO_HEAD_JOINT_MODE, new JSONObject().fluentPut("mode", 0));
|
||||
assertTrue(sent.get(0).getMove().getTargets(0).hasPositionRad());
|
||||
assertEquals(0, sent.get(0).getMove().getTargets(0).getPositionRad(), 0);
|
||||
assertTrue(sent.get(1).getMode().hasMode());
|
||||
assertEquals(0, sent.get(1).getMode().getModeValue());
|
||||
execute(ActionEnum.BIO_HEAD_JOINT_MOVE, new JSONObject().fluentPut("targets",
|
||||
List.of(Map.of("id", "joint1", "positionRad", 0.25))));
|
||||
assertEquals(0.25, sent.get(2).getMove().getTargets(0).getPositionRad(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refusesMissingOrDuplicateTargetsWithoutSending() {
|
||||
reject("[{\"id\":\"joint1\"}]");
|
||||
reject("[{\"id\":\"joint1\",\"positionRad\":0},{\"id\":\"joint1\",\"positionRad\":1}]");
|
||||
assertTrue(sent.isEmpty());
|
||||
}
|
||||
|
||||
private void reject(String targets) {
|
||||
try {
|
||||
execute(ActionEnum.BIO_HEAD_JOINT_MOVE, new JSONObject().fluentPut("targets", targets));
|
||||
fail("Invalid targets must be rejected");
|
||||
} catch (GlobalException expected) {
|
||||
assertTrue(sent.isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
private void execute(ActionEnum action, JSONObject params) {
|
||||
TaskNodeExecuteMessage message = new TaskNodeExecuteMessage();
|
||||
message.setAction(action);
|
||||
message.setRobotId("robot-1");
|
||||
message.setInputParams(params.fluentPut("deviceId", "head-1"));
|
||||
assertTrue(service.execute(message).isSuccess());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,85 @@
|
||||
package com.cmvr.test.flow.runtime.operator.edge;
|
||||
|
||||
import cmvr.api.ArmCommand;
|
||||
import cmvr.api.Common;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.cmvr.common.exception.GlobalException;
|
||||
import com.cmvr.edge.client.model.EdgeCommonVO;
|
||||
import com.cmvr.edge.client.service.EdgeArmService;
|
||||
import com.cmvr.test.enums.ActionEnum;
|
||||
import com.cmvr.test.flow.runtime.message.TaskNodeExecuteMessage;
|
||||
import com.cmvr.test.flow.runtime.message.TaskNodeExecuteResult;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class EdgeNeckOperateServiceTest {
|
||||
private final List<String> calls = new ArrayList<>();
|
||||
private final Common.CommandHeader.Feedback success = Common.CommandHeader.Feedback.newBuilder()
|
||||
.setSuccess(true).build();
|
||||
private final EdgeArmOperateService service = new EdgeArmOperateService((EdgeArmService)
|
||||
Proxy.newProxyInstance(EdgeArmService.class.getClassLoader(), new Class<?>[]{EdgeArmService.class},
|
||||
(proxy, method, args) -> {
|
||||
calls.add(method.getName());
|
||||
String deviceId = ((EdgeCommonVO) args[0]).getDeviceId();
|
||||
assertTrue(List.of("neck_arm", "xiaozhao_head").contains(deviceId));
|
||||
return switch (method.getName()) {
|
||||
case "moveJ" -> {
|
||||
assertArrayEquals(new double[]{0, 0.1, -0.1}, (double[]) args[1], 0);
|
||||
assertEquals(0.25, args[2]);
|
||||
assertEquals(false, args[6]);
|
||||
yield ArmCommand.MoveJ.Response.newBuilder().setHeader(success).build();
|
||||
}
|
||||
case "getJointState" -> ArmCommand.JointResponse.newBuilder().setHeader(success)
|
||||
.setState(ArmCommand.JointState.newBuilder().addName("neck-joint1")
|
||||
.addPosition(0.1).addCurrent(17)).build();
|
||||
case "stopMotion" -> Common.CommandHeader.Feedback.newBuilder()
|
||||
.setErrorMessage("edge rejected stop").build();
|
||||
default -> throw new AssertionError(method.getName());
|
||||
};
|
||||
}));
|
||||
|
||||
@Test
|
||||
public void dispatchesThreeAxisMotionAndReturnsJointFeedback() {
|
||||
assertTrue(execute(ActionEnum.ARM_NECK_MOVE_J, "neck_arm",
|
||||
JSONObject.of("target", "[0, 0.1, -0.1]", "velocity", 0.25)).isSuccess());
|
||||
JSONObject output = execute(ActionEnum.ARM_NECK_GET_JOINT_STATE, "xiaozhao_head", new JSONObject())
|
||||
.getOutputParams();
|
||||
assertEquals(List.of("neck-joint1"), output.getList("jointNames", String.class));
|
||||
assertEquals(List.of(17.0), output.getList("currentMa", Double.class));
|
||||
assertEquals(List.of("moveJ", "getJointState"), calls);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsAnOrdinaryArmAndInvalidTargetsBeforeDispatch() {
|
||||
assertThrows(GlobalException.class, () -> execute(ActionEnum.ARM_NECK_STOP, "left_tchl_arm", new JSONObject()));
|
||||
assertThrows(GlobalException.class, () -> execute(ActionEnum.ARM_NECK_MOVE_J,
|
||||
"xiaozhao_head", JSONObject.of("target", "[0, 1]")));
|
||||
assertThrows(GlobalException.class, () -> execute(ActionEnum.ARM_NECK_MOVE_J,
|
||||
"xiaozhao_head", JSONObject.of("target", "[0, 0, 0]", "velocity", -0.1)));
|
||||
assertTrue(calls.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reportsEdgeFeedbackFailure() {
|
||||
GlobalException failure = assertThrows(GlobalException.class,
|
||||
() -> execute(ActionEnum.ARM_NECK_STOP, "xiaozhao_head", new JSONObject()));
|
||||
assertEquals("edge rejected stop", failure.getMessage());
|
||||
assertEquals(List.of("stopMotion"), calls);
|
||||
}
|
||||
|
||||
private TaskNodeExecuteResult execute(ActionEnum action, String deviceId, JSONObject params) {
|
||||
TaskNodeExecuteMessage message = new TaskNodeExecuteMessage();
|
||||
message.setAction(action);
|
||||
message.setRobotId("robot-1");
|
||||
message.setInputParams(params.fluentPut("deviceId", deviceId));
|
||||
return service.execute(message);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package com.cmvr.ti.listener;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.cmvr.test.flow.runtime.event.FlowExecutionEvent;
|
||||
import com.cmvr.test.flow.runtime.event.FlowExecutionListener;
|
||||
import com.cmvr.test.flow.runtime.event.FlowExecutionModuleCodes;
|
||||
import com.cmvr.ti.mapper.TiProjectMapper;
|
||||
import com.cmvr.ti.model.domain.TiProject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class TiVideoExecutionListener implements FlowExecutionListener {
|
||||
|
||||
private final TiProjectMapper projectMapper;
|
||||
|
||||
@Override
|
||||
public void onEvent(FlowExecutionEvent event) {
|
||||
switch (event.getEventType()) {
|
||||
case TASK_COMPLETED, TASK_FAILED, TASK_STOPPED -> projectMapper.update(null,
|
||||
Wrappers.<TiProject>lambdaUpdate()
|
||||
.eq(TiProject::getProjectId, event.getTaskId())
|
||||
.set(TiProject::getStatus, "2"));
|
||||
default -> {
|
||||
// The engine stores individual node results.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModuleCode() {
|
||||
return FlowExecutionModuleCodes.TI_VIDEO;
|
||||
}
|
||||
}
|
||||
@ -17,12 +17,16 @@ public interface ITiProjectService extends IService<TiProject> {
|
||||
|
||||
public int insertTiProject(TiProject tiProject);
|
||||
|
||||
public int updateTiProject(TiProject tiProject);
|
||||
int updateTiProject(TiProject tiProject, boolean clearVehicleConfig);
|
||||
|
||||
public int deleteTiProjectByProjectIds(String[] projectIds);
|
||||
|
||||
public List<TeQueryTaskOrchestraItemVO> queryExecuteRunParams(String projectId);
|
||||
|
||||
List<TeQueryTaskOrchestraItemVO> listExecutableDetectionItems();
|
||||
|
||||
List<TeQueryTaskOrchestraItemVO> queryExecutionItems(String projectId, String instId);
|
||||
|
||||
public TiProjectReadinessVO checkExecutionReadiness(String projectId);
|
||||
|
||||
public String executeProject(TeTaskExecuteProjectVO taskExecuteProjectVO);
|
||||
|
||||
@ -42,6 +42,7 @@ import com.cmvr.ti.model.vo.TiProjectReadinessVO;
|
||||
import com.cmvr.ti.service.ITiProjectService;
|
||||
import com.cmvr.ti.service.ITiVehicleFunctionService;
|
||||
import com.cmvr.ti.support.TiEvaluationRecorder;
|
||||
import com.cmvr.ti.support.TiVideoAnalysisReport;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -91,7 +92,11 @@ public class TiProjectServiceImpl extends ServiceImpl<TiProjectMapper, TiProject
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int insertTiProject(TiProject tiProject) {
|
||||
requireProjectFunctions(tiProject);
|
||||
tiProject.setProjectName(requireProjectName(tiProject.getProjectName()));
|
||||
if (StrUtil.isBlank(tiProject.getTestFuncIds())) {
|
||||
tiProject.setTestFuncIds("[]");
|
||||
}
|
||||
validateProjectFunctions(tiProject, false);
|
||||
|
||||
tiProject.setStatus("0");
|
||||
int insert = this.baseMapper.insert(tiProject);
|
||||
@ -104,25 +109,37 @@ public class TiProjectServiceImpl extends ServiceImpl<TiProjectMapper, TiProject
|
||||
|
||||
// 插入编排项
|
||||
TeDetectionItem item = detectionItemService.selectTeDetectionItemBySceneType(FlowSceneTypeEnum.TI_TOUCH.getSceneCode());
|
||||
TeTaskOrchestraVO teTaskOrchestraVO = new TeTaskOrchestraVO();
|
||||
teTaskOrchestraVO.setTaskId(taskConfigInfo.getId());
|
||||
teTaskOrchestraVO.setItemIds(Collections.singletonList(item.getId()));
|
||||
taskOrchestrationService.insertTeTaskOrchestration(teTaskOrchestraVO);
|
||||
if (item != null) {
|
||||
TeTaskOrchestraVO teTaskOrchestraVO = new TeTaskOrchestraVO();
|
||||
teTaskOrchestraVO.setTaskId(taskConfigInfo.getId());
|
||||
teTaskOrchestraVO.setItemIds(Collections.singletonList(item.getId()));
|
||||
taskOrchestrationService.insertTeTaskOrchestration(teTaskOrchestraVO);
|
||||
}
|
||||
return insert;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateTiProject(TiProject tiProject) {
|
||||
public int updateTiProject(TiProject tiProject, boolean clearVehicleConfig) {
|
||||
TiProject current = getById(tiProject.getProjectId());
|
||||
if (current == null) {
|
||||
throw new GlobalException("触控项目不存在:" + tiProject.getProjectId());
|
||||
}
|
||||
if (tiProject.getProjectName() != null) {
|
||||
tiProject.setProjectName(requireProjectName(tiProject.getProjectName()));
|
||||
}
|
||||
if (clearVehicleConfig) {
|
||||
tiProject.setVehicleConfigId(null);
|
||||
tiProject.setTestFuncIds("[]");
|
||||
return this.baseMapper.update(tiProject, Wrappers.<TiProject>lambdaUpdate()
|
||||
.eq(TiProject::getProjectId, tiProject.getProjectId())
|
||||
.set(TiProject::getVehicleConfigId, null));
|
||||
}
|
||||
TiProject candidate = new TiProject();
|
||||
candidate.setVehicleConfigId(tiProject.getVehicleConfigId() == null
|
||||
? current.getVehicleConfigId() : tiProject.getVehicleConfigId());
|
||||
candidate.setTestFuncIds(StrUtil.isBlank(tiProject.getTestFuncIds())
|
||||
? current.getTestFuncIds() : tiProject.getTestFuncIds());
|
||||
requireProjectFunctions(candidate);
|
||||
validateProjectFunctions(candidate, false);
|
||||
return this.baseMapper.updateById(tiProject);
|
||||
}
|
||||
|
||||
@ -137,6 +154,40 @@ public class TiProjectServiceImpl extends ServiceImpl<TiProjectMapper, TiProject
|
||||
return taskOrchestrationService.queryByTaskId(projectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TeQueryTaskOrchestraItemVO> listExecutableDetectionItems() {
|
||||
return detectionItemService.lambdaQuery()
|
||||
.select(TeDetectionItem::getId, TeDetectionItem::getDetectName,
|
||||
TeDetectionItem::getPublishedVersionId, TeDetectionItem::getPublishedVersionNo)
|
||||
.eq(TeDetectionItem::getStatus, "0")
|
||||
.isNotNull(TeDetectionItem::getPublishedVersionId)
|
||||
.ne(TeDetectionItem::getPublishedVersionId, "")
|
||||
.orderByAsc(TeDetectionItem::getDetectName, TeDetectionItem::getId)
|
||||
.list().stream()
|
||||
.map(item -> executionItem(item.getId(), item.getDetectName(),
|
||||
item.getPublishedVersionId(), item.getPublishedVersionNo()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TeQueryTaskOrchestraItemVO> queryExecutionItems(String projectId, String instId) {
|
||||
TeTaskExecuteProjectVO request = TiVideoAnalysisReport.readRequest(requireProjectInstance(projectId, instId));
|
||||
if (request != null) {
|
||||
return List.of(executionItem(request.getItemId(), request.getItemName(), request.getVersionId(), null));
|
||||
}
|
||||
return queryExecuteRunParams(projectId);
|
||||
}
|
||||
|
||||
private TeQueryTaskOrchestraItemVO executionItem(String itemId, String itemName, String versionId, Integer versionNo) {
|
||||
TeQueryTaskOrchestraItemVO item = new TeQueryTaskOrchestraItemVO();
|
||||
item.setItemId(itemId);
|
||||
item.setItemName(itemName);
|
||||
item.setVersionId(versionId);
|
||||
item.setVersionNo(versionNo);
|
||||
item.setOrderNum(1);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TiProjectReadinessVO checkExecutionReadiness(String projectId) {
|
||||
TiProject project = getById(projectId);
|
||||
@ -234,20 +285,51 @@ public class TiProjectServiceImpl extends ServiceImpl<TiProjectMapper, TiProject
|
||||
// }
|
||||
TeTaskExecuteProjectVO normalVO = new TeTaskExecuteProjectVO();
|
||||
normalVO.setProjectId(taskExecuteProjectVO.getProjectId());
|
||||
normalVO.setRunParams(buildProjectRunParams(project, taskExecuteProjectVO.getRunParams()));
|
||||
String itemId = taskExecuteProjectVO.getItemId();
|
||||
boolean selected = StrUtil.isNotBlank(itemId);
|
||||
if (selected) {
|
||||
TeDetectionItem item = detectionItemService.getById(itemId);
|
||||
if (item == null || !"0".equals(item.getStatus()) || StrUtil.isBlank(item.getPublishedVersionId())) {
|
||||
throw new GlobalException("请选择一个启用且已发布的检测项");
|
||||
}
|
||||
if (!StrUtil.equals(item.getPublishedVersionId(), taskExecuteProjectVO.getVersionId())) {
|
||||
throw new GlobalException("检测项发布版本已变更,请重新选择并确认运行参数");
|
||||
}
|
||||
normalVO.setItemId(itemId);
|
||||
normalVO.setItemName(item.getDetectName());
|
||||
normalVO.setVersionId(item.getPublishedVersionId());
|
||||
JSONObject params = taskExecuteProjectVO.getRunParams();
|
||||
if (FlowSceneTypeEnum.TI_TOUCH.getSceneCode().equals(item.getSceneCode())) {
|
||||
validateProjectFunctions(project, true);
|
||||
params = buildProjectRunParams(project, params, List.of(itemId));
|
||||
}
|
||||
normalVO.setRunParams(params);
|
||||
} else {
|
||||
validateProjectFunctions(project, true);
|
||||
normalVO.setRunParams(buildProjectRunParams(project, taskExecuteProjectVO.getRunParams()));
|
||||
}
|
||||
normalVO.setRobotId(taskExecuteProjectVO.getRobotId());
|
||||
normalVO.setRuntimeAssignments(taskExecuteProjectVO.getRuntimeAssignments());
|
||||
normalVO.setRunMode(RunModeEnum.TI_PROJECT);
|
||||
normalVO.setModuleCode(FlowExecutionModuleCodes.TI);
|
||||
updateProjectStatus(taskExecuteProjectVO.getProjectId(), 1);
|
||||
normalVO.setModuleCode(selected ? FlowExecutionModuleCodes.TI_VIDEO : FlowExecutionModuleCodes.TI);
|
||||
boolean started = update(Wrappers.<TiProject>lambdaUpdate()
|
||||
.eq(TiProject::getProjectId, project.getProjectId())
|
||||
.and(query -> query.ne(TiProject::getStatus, "1").or().isNull(TiProject::getStatus))
|
||||
.set(TiProject::getStatus, "1"));
|
||||
if (!started) {
|
||||
throw new GlobalException("该项目正在执行,请等待本次执行结束");
|
||||
}
|
||||
String instId;
|
||||
try {
|
||||
instId = flowTaskRuntimeService.executeProjectTask(normalVO);
|
||||
} catch (RuntimeException exception) {
|
||||
updateProjectStatus(taskExecuteProjectVO.getProjectId(), 0);
|
||||
update(Wrappers.<TiProject>lambdaUpdate().eq(TiProject::getProjectId, project.getProjectId())
|
||||
.set(TiProject::getStatus, project.getStatus()));
|
||||
throw exception;
|
||||
}
|
||||
evaluationRecorder.initialize(taskExecuteProjectVO.getProjectId(), instId);
|
||||
if (!selected) {
|
||||
evaluationRecorder.initialize(taskExecuteProjectVO.getProjectId(), instId);
|
||||
}
|
||||
return instId;
|
||||
}
|
||||
|
||||
@ -295,18 +377,11 @@ public class TiProjectServiceImpl extends ServiceImpl<TiProjectMapper, TiProject
|
||||
throw new GlobalException("触控项目不存在:" + projectId);
|
||||
}
|
||||
|
||||
TeTaskInst taskInst;
|
||||
if (StrUtil.isBlank(instId)) {
|
||||
taskInst = getTeTaskInst(projectId);
|
||||
} else {
|
||||
taskInst = taskInstService.getById(instId);
|
||||
if (taskInst != null && (!StrUtil.equals(projectId, taskInst.getTaskId())
|
||||
|| !StrUtil.equals(RunModeEnum.TI_PROJECT.name(), taskInst.getRunMode()))) {
|
||||
throw new GlobalException("执行实例不属于当前触控项目:" + instId);
|
||||
}
|
||||
}
|
||||
if (taskInst == null) {
|
||||
throw new GlobalException("触控项目尚未执行:" + projectId);
|
||||
TeTaskInst taskInst = requireProjectInstance(projectId, instId);
|
||||
TeTaskExecuteProjectVO request = TiVideoAnalysisReport.readRequest(taskInst);
|
||||
if (request != null) {
|
||||
TeDetectionItemVersion version = detectionItemVersionService.getById(request.getVersionId());
|
||||
return TiVideoAnalysisReport.build(project, taskInst, request, version, taskInstService.detail(taskInst.getId()));
|
||||
}
|
||||
|
||||
List<AeEvaluation> evaluations = aeEvaluationService.queryEvaluation(taskInst.getId());
|
||||
@ -372,13 +447,35 @@ public class TiProjectServiceImpl extends ServiceImpl<TiProjectMapper, TiProject
|
||||
return vo;
|
||||
}
|
||||
|
||||
private List<TiVehicleFunction> requireProjectFunctions(TiProject project) {
|
||||
if (project.getVehicleConfigId() == null) {
|
||||
throw new GlobalException("请选择车型配置");
|
||||
private TeTaskInst requireProjectInstance(String projectId, String instId) {
|
||||
TeTaskInst instance = StrUtil.isBlank(instId) ? getTeTaskInst(projectId) : taskInstService.getById(instId);
|
||||
if (instance == null) {
|
||||
throw new GlobalException(StrUtil.isBlank(instId) ? "触控项目尚未执行:" + projectId : "执行实例不存在:" + instId);
|
||||
}
|
||||
if (!StrUtil.equals(projectId, instance.getTaskId())
|
||||
|| !StrUtil.equals(RunModeEnum.TI_PROJECT.name(), instance.getRunMode())) {
|
||||
throw new GlobalException("执行实例不属于当前触控项目:" + instId);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private String requireProjectName(String name) {
|
||||
if (StrUtil.isBlank(name)) {
|
||||
throw new GlobalException("项目名称不能为空");
|
||||
}
|
||||
return name.trim();
|
||||
}
|
||||
|
||||
private void validateProjectFunctions(TiProject project, boolean required) {
|
||||
List<Long> ids = parseFunctionIds(project.getTestFuncIds());
|
||||
if (project.getVehicleConfigId() == null && (required || !ids.isEmpty())) {
|
||||
throw new GlobalException("请选择车机版本");
|
||||
}
|
||||
if (ids.isEmpty()) {
|
||||
throw new GlobalException("请至少选择一个测试功能");
|
||||
if (required) {
|
||||
throw new GlobalException("此工作流需要选择至少一个车机功能");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (new HashSet<>(ids).size() != ids.size()) {
|
||||
throw new GlobalException("测试功能不能重复");
|
||||
@ -391,7 +488,6 @@ public class TiProjectServiceImpl extends ServiceImpl<TiProjectMapper, TiProject
|
||||
project.getVehicleConfigId(), item.getVehicleConfigId()))) {
|
||||
throw new GlobalException("所选功能必须全部属于项目车型");
|
||||
}
|
||||
return functions;
|
||||
}
|
||||
|
||||
private List<Long> parseFunctionIds(String value) {
|
||||
@ -407,13 +503,19 @@ public class TiProjectServiceImpl extends ServiceImpl<TiProjectMapper, TiProject
|
||||
}
|
||||
|
||||
private JSONObject buildProjectRunParams(TiProject project, JSONObject requested) {
|
||||
List<String> itemIds = taskOrchestrationService.queryByTaskId(project.getProjectId()).stream()
|
||||
.map(TeQueryTaskOrchestraItemVO::getItemId).toList();
|
||||
return buildProjectRunParams(project, requested, itemIds);
|
||||
}
|
||||
|
||||
private JSONObject buildProjectRunParams(TiProject project, JSONObject requested, List<String> itemIds) {
|
||||
JSONObject normalized = new JSONObject();
|
||||
if (requested != null) {
|
||||
normalized.putAll(requested);
|
||||
}
|
||||
JSONArray functionIds = JSON.parseArray(project.getTestFuncIds());
|
||||
for (TeQueryTaskOrchestraItemVO item : taskOrchestrationService.queryByTaskId(project.getProjectId())) {
|
||||
JSONObject itemParams = normalized.getJSONObject(item.getItemId());
|
||||
for (String itemId : itemIds) {
|
||||
JSONObject itemParams = normalized.getJSONObject(itemId);
|
||||
if (itemParams == null) {
|
||||
itemParams = new JSONObject();
|
||||
} else {
|
||||
@ -422,7 +524,7 @@ public class TiProjectServiceImpl extends ServiceImpl<TiProjectMapper, TiProject
|
||||
itemParams.put("funcIds", functionIds);
|
||||
itemParams.put("vehicleConfigId", project.getVehicleConfigId());
|
||||
itemParams.put("projectId", project.getProjectId());
|
||||
normalized.put(item.getItemId(), itemParams);
|
||||
normalized.put(itemId, itemParams);
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
@ -0,0 +1,147 @@
|
||||
package com.cmvr.ti.support;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.cmvr.evaluation.model.vo.AeViEvaluationVO;
|
||||
import com.cmvr.evaluation.model.vo.AeViEvaluationVO.AeItemDetail;
|
||||
import com.cmvr.evaluation.model.vo.AeViEvaluationVO.VideoEvent;
|
||||
import com.cmvr.test.enums.ActionEnum;
|
||||
import com.cmvr.test.enums.TaskStatusEnum;
|
||||
import com.cmvr.test.flow.runtime.event.FlowExecutionModuleCodes;
|
||||
import com.cmvr.test.flow.runtime.operator.FlowMediaParamResolver;
|
||||
import com.cmvr.test.model.domain.TeDetectionItemVersion;
|
||||
import com.cmvr.test.model.domain.TeNodeInst;
|
||||
import com.cmvr.test.model.domain.TeTaskInst;
|
||||
import com.cmvr.test.model.vo.TeTaskExecuteProjectVO;
|
||||
import com.cmvr.ti.model.domain.TiProject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class TiVideoAnalysisReport {
|
||||
|
||||
private static final int PASSED = 2;
|
||||
private static final int NOT_PASSED = 3;
|
||||
private static final int ANALYSIS_ERROR = 5;
|
||||
|
||||
private TiVideoAnalysisReport() {}
|
||||
|
||||
public static TeTaskExecuteProjectVO readRequest(TeTaskInst instance) {
|
||||
JSONObject config = object(instance.getConfig());
|
||||
if (!FlowExecutionModuleCodes.TI_VIDEO.equals(config.getString("moduleCode"))
|
||||
|| StrUtil.isBlank(config.getString("itemId"))) {
|
||||
return null;
|
||||
}
|
||||
return config.toJavaObject(TeTaskExecuteProjectVO.class);
|
||||
}
|
||||
|
||||
public static AeViEvaluationVO build(TiProject project, TeTaskInst instance, TeTaskExecuteProjectVO request,
|
||||
TeDetectionItemVersion version, List<TeNodeInst> logs) {
|
||||
Map<String, String> names = nodeNames(version);
|
||||
List<AeItemDetail> rows = logs.stream()
|
||||
.filter(log -> ActionEnum.VIDEO_ANALYZE.getAction().equals(log.getAction()))
|
||||
.filter(log -> TaskStatusEnum.SUCCESS.name().equals(log.getStatus())
|
||||
|| TaskStatusEnum.FAILED.name().equals(log.getStatus()))
|
||||
.map(log -> toRow(log, names))
|
||||
.toList();
|
||||
int passed = count(rows, PASSED);
|
||||
int notPassed = count(rows, NOT_PASSED);
|
||||
AeViEvaluationVO result = new AeViEvaluationVO();
|
||||
result.setProjectId(project.getProjectId());
|
||||
result.setSchemeId(instance.getId());
|
||||
result.setSchemeName(project.getProjectName());
|
||||
result.setInstId(instance.getId());
|
||||
result.setExecutionStatus(instance.getStatus());
|
||||
result.setStartTime(instance.getCreateTime());
|
||||
result.setEndTime(String.valueOf(TaskStatusEnum.RUNNING.getCode()).equals(instance.getStatus())
|
||||
? null : instance.getUpdateTime());
|
||||
result.setDetectionItemName(request.getItemName());
|
||||
result.setWorkflowVersionNo(version == null ? null : version.getVersionNo());
|
||||
result.setTotalCount(rows.size());
|
||||
result.setSuccessCount(passed);
|
||||
result.setFailureCount(notPassed);
|
||||
result.setAnalysisErrorCount(count(rows, ANALYSIS_ERROR));
|
||||
result.setSuccessRate(passed + notPassed == 0 ? null : passed * 100L / (passed + notPassed));
|
||||
result.setItemDetails(rows);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int count(List<AeItemDetail> rows, int status) {
|
||||
return (int) rows.stream().filter(row -> row.getStatus() == status).count();
|
||||
}
|
||||
|
||||
private static AeItemDetail toRow(TeNodeInst log, Map<String, String> names) {
|
||||
JSONObject input = object(log.getParamsIn());
|
||||
JSONObject output = object(log.getParamsOut());
|
||||
Boolean passed = output.getBoolean("passed");
|
||||
boolean error = !TaskStatusEnum.SUCCESS.name().equals(log.getStatus())
|
||||
|| !"SUCCEEDED".equals(output.getString("analysisStatus")) || passed == null;
|
||||
AeItemDetail row = new AeItemDetail();
|
||||
row.setAeId(String.valueOf(log.getId()));
|
||||
row.setContent(names.getOrDefault(log.getNodeId(), "视频智能分析"));
|
||||
row.setIteration(log.getIteration());
|
||||
row.setStatus(error ? ANALYSIS_ERROR : passed ? PASSED : NOT_PASSED);
|
||||
row.setExpectedResult(input.getString("instruction"));
|
||||
row.setVideoPath(StrUtil.blankToDefault(FlowMediaParamResolver.lastUrl(output, "mediaUrl"),
|
||||
FlowMediaParamResolver.lastUrl(input, "videoUrl")));
|
||||
row.setExecutionDetail(StrUtil.blankToDefault(output.getString("summary"), output.getString("conclusion")));
|
||||
row.setItemResponseTime(output.getLong("analysisTimingMs"));
|
||||
if (error) {
|
||||
row.setFailureReason(StrUtil.blankToDefault(log.getMessage(), "视频分析未返回有效结果"));
|
||||
} else if (!passed) {
|
||||
row.setFailureReason(StrUtil.blankToDefault(output.getString("conclusion"),
|
||||
output.getString("decisionReason")));
|
||||
}
|
||||
JSONObject model = output.getJSONObject("analysisModel");
|
||||
if (model != null) {
|
||||
row.setModelName(model.getString("name"));
|
||||
}
|
||||
JSONArray events = output.getJSONArray("events");
|
||||
if (events != null) {
|
||||
row.setVideoEvents(events.stream()
|
||||
.filter(JSONObject.class::isInstance)
|
||||
.map(JSONObject.class::cast)
|
||||
.map(event -> new VideoEvent(event.getString("timeRange"), event.getString("event")))
|
||||
.toList());
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
private static Map<String, String> nodeNames(TeDetectionItemVersion version) {
|
||||
Map<String, String> names = new HashMap<>();
|
||||
if (version == null) {
|
||||
return names;
|
||||
}
|
||||
JSONArray nodes = object(version.getFlowData()).getJSONArray("nodes");
|
||||
if (nodes != null) {
|
||||
for (Object value : nodes) {
|
||||
if (value instanceof JSONObject node) {
|
||||
JSONObject props = node.getJSONObject("properties");
|
||||
String name = props == null ? null : props.getString("name");
|
||||
if (StrUtil.isNotBlank(name)) {
|
||||
names.put(node.getString("id"), name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
private static JSONObject object(String json) {
|
||||
if (StrUtil.isNotBlank(json)) {
|
||||
try {
|
||||
JSONObject parsed = JSON.parseObject(json);
|
||||
if (parsed != null) {
|
||||
return parsed;
|
||||
}
|
||||
} catch (JSONException ignored) {
|
||||
// An incomplete log must not prevent other rows from rendering.
|
||||
}
|
||||
}
|
||||
return new JSONObject();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user