refactor(edge): 优化边缘控制器代码结构

- 移除EdgeArmController中未使用的返回值变量
- 将EdgeArmOperateService中的switch语句替换为if-else判断
- 添加Objects.requireNonNull进行空值检查
- 简化EdgeTouchOperateService中的条件判断逻辑
- 统一异常处理方式,移除多余的break语句
- 优化代码可读性和执行效率
This commit is contained in:
lixiaolong 2026-07-01 11:39:48 +08:00
parent ac35fd229b
commit 9ae4334421
3 changed files with 42 additions and 47 deletions

View File

@ -32,14 +32,14 @@ public class EdgeArmController {
@ApiOperation("关闭力矩")
@GetMapping("/torqueOff")
public AjaxResult torqueOff(EdgeCommonVO vo) {
Common.CommandHeader.Feedback result = edgeArmService.torqueOff(vo);
edgeArmService.torqueOff(vo);
return AjaxResult.ok();
}
@ApiOperation("开启力矩")
@GetMapping("/torqueOn")
public AjaxResult torqueOn(EdgeCommonVO vo) {
Common.CommandHeader.Feedback result = edgeArmService.torqueOn(vo);
edgeArmService.torqueOn(vo);
return AjaxResult.ok();
}

View File

@ -12,6 +12,8 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Objects;
/**
* 机械臂边缘操作服务
* 处理机械臂相关的设备行为如末端运动到指定位置
@ -51,32 +53,31 @@ public class EdgeArmOperateService implements EdgeOperateService {
// 先调用开启力矩
edgeArmService.torqueOn(edgeCommonVO);
switch (action) {
case ARM_MOVE_TO_POINT: {
log.info("执行机械臂末端运动到指定点操作设备ID: {}", deviceId);
if (Objects.requireNonNull(action) == ActionEnum.ARM_MOVE_TO_POINT) {
log.info("执行机械臂末端运动到指定点操作设备ID: {}", deviceId);
// 从输入参数中获取坐标信息
Double x = inputParams.getDouble("x");
Double y = inputParams.getDouble("y");
Double z = inputParams.getDouble("z");
Double rx = inputParams.getDouble("rx");
Double ry = inputParams.getDouble("ry");
Double rz = inputParams.getDouble("rz");
String frame = inputParams.getString("frame");
Double velocity = inputParams.getDouble("velocity");
Double acceleration = inputParams.getDouble("acceleration");
Double blendRadius = inputParams.getDouble("blendRadius");
// 从输入参数中获取坐标信息
Double x = inputParams.getDouble("x");
Double y = inputParams.getDouble("y");
Double z = inputParams.getDouble("z");
Double rx = inputParams.getDouble("rx");
Double ry = inputParams.getDouble("ry");
Double rz = inputParams.getDouble("rz");
String frame = inputParams.getString("frame");
Double velocity = inputParams.getDouble("velocity");
Double acceleration = inputParams.getDouble("acceleration");
Double blendRadius = inputParams.getDouble("blendRadius");
// 参数验证
if (x == null || y == null || z == null) {
throw new GlobalException("X、Y、Z坐标不能为空");
}
if (rx == null || ry == null || rz == null) {
throw new GlobalException("RX、RY、RZ旋转角度不能为空");
}
// 参数验证
if (x == null || y == null || z == null) {
throw new GlobalException("X、Y、Z坐标不能为空");
}
if (rx == null || ry == null || rz == null) {
throw new GlobalException("RX、RY、RZ旋转角度不能为空");
}
// 直接调用边缘端机械臂服务执行笛卡尔空间直线运动
ArmCommand.MoveL.Response result = edgeArmService.moveL(
// 直接调用边缘端机械臂服务执行笛卡尔空间直线运动
edgeArmService.moveL(
edgeCommonVO,
x,
y,
@ -88,15 +89,11 @@ public class EdgeArmOperateService implements EdgeOperateService {
velocity,
acceleration,
blendRadius
);
);
log.info("机械臂末端运动任务下发成功");
break;
}
default:
throw new GlobalException("不支持的机械臂操作类型: " + action);
log.info("机械臂末端运动任务下发成功");
} else {
throw new GlobalException("不支持的机械臂操作类型: " + action);
}
return TaskNodeExecuteResult.success();

View File

@ -12,6 +12,8 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Objects;
@Slf4j
@Service
@ -33,13 +35,12 @@ public class EdgeTouchOperateService implements EdgeOperateService {
String deviceId = inputParams.getString("deviceId");
String touchParams = inputParams.getString("touchParams");
switch (action) {
case TOUCH: {
EdgeArmMoveJVO edgeArmMoveJVO = JSON.parseObject(touchParams, EdgeArmMoveJVO.class);
edgeArmMoveJVO.setTerminalId(terminalId);
edgeArmMoveJVO.setDeviceId(deviceId);
if (Objects.requireNonNull(action) == ActionEnum.TOUCH) {
EdgeArmMoveJVO edgeArmMoveJVO = JSON.parseObject(touchParams, EdgeArmMoveJVO.class);
edgeArmMoveJVO.setTerminalId(terminalId);
edgeArmMoveJVO.setDeviceId(deviceId);
edgeArmService.moveJ(
edgeArmService.moveJ(
edgeArmMoveJVO,
edgeArmMoveJVO.getTarget(),
edgeArmMoveJVO.getVelocity(),
@ -47,12 +48,9 @@ public class EdgeTouchOperateService implements EdgeOperateService {
edgeArmMoveJVO.getBlendRadius(),
edgeArmMoveJVO.getJointVelocityLimits(),
edgeArmMoveJVO.getAsynchronous()
);
break;
}
default:
throw new GlobalException("不支持的触控操作类型: " + action);
);
} else {
throw new GlobalException("不支持的触控操作类型: " + action);
}
return TaskNodeExecuteResult.success();
}