refactor(edge): 优化边缘控制器代码结构
- 移除EdgeArmController中未使用的返回值变量 - 将EdgeArmOperateService中的switch语句替换为if-else判断 - 添加Objects.requireNonNull进行空值检查 - 简化EdgeTouchOperateService中的条件判断逻辑 - 统一异常处理方式,移除多余的break语句 - 优化代码可读性和执行效率
This commit is contained in:
parent
ac35fd229b
commit
9ae4334421
@ -32,14 +32,14 @@ public class EdgeArmController {
|
|||||||
@ApiOperation("关闭力矩")
|
@ApiOperation("关闭力矩")
|
||||||
@GetMapping("/torqueOff")
|
@GetMapping("/torqueOff")
|
||||||
public AjaxResult torqueOff(EdgeCommonVO vo) {
|
public AjaxResult torqueOff(EdgeCommonVO vo) {
|
||||||
Common.CommandHeader.Feedback result = edgeArmService.torqueOff(vo);
|
edgeArmService.torqueOff(vo);
|
||||||
return AjaxResult.ok();
|
return AjaxResult.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("开启力矩")
|
@ApiOperation("开启力矩")
|
||||||
@GetMapping("/torqueOn")
|
@GetMapping("/torqueOn")
|
||||||
public AjaxResult torqueOn(EdgeCommonVO vo) {
|
public AjaxResult torqueOn(EdgeCommonVO vo) {
|
||||||
Common.CommandHeader.Feedback result = edgeArmService.torqueOn(vo);
|
edgeArmService.torqueOn(vo);
|
||||||
return AjaxResult.ok();
|
return AjaxResult.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,8 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 机械臂边缘操作服务
|
* 机械臂边缘操作服务
|
||||||
* 处理机械臂相关的设备行为,如末端运动到指定位置
|
* 处理机械臂相关的设备行为,如末端运动到指定位置
|
||||||
@ -51,32 +53,31 @@ public class EdgeArmOperateService implements EdgeOperateService {
|
|||||||
// 先调用开启力矩
|
// 先调用开启力矩
|
||||||
edgeArmService.torqueOn(edgeCommonVO);
|
edgeArmService.torqueOn(edgeCommonVO);
|
||||||
|
|
||||||
switch (action) {
|
if (Objects.requireNonNull(action) == ActionEnum.ARM_MOVE_TO_POINT) {
|
||||||
case ARM_MOVE_TO_POINT: {
|
log.info("执行机械臂末端运动到指定点操作,设备ID: {}", deviceId);
|
||||||
log.info("执行机械臂末端运动到指定点操作,设备ID: {}", deviceId);
|
|
||||||
|
|
||||||
// 从输入参数中获取坐标信息
|
// 从输入参数中获取坐标信息
|
||||||
Double x = inputParams.getDouble("x");
|
Double x = inputParams.getDouble("x");
|
||||||
Double y = inputParams.getDouble("y");
|
Double y = inputParams.getDouble("y");
|
||||||
Double z = inputParams.getDouble("z");
|
Double z = inputParams.getDouble("z");
|
||||||
Double rx = inputParams.getDouble("rx");
|
Double rx = inputParams.getDouble("rx");
|
||||||
Double ry = inputParams.getDouble("ry");
|
Double ry = inputParams.getDouble("ry");
|
||||||
Double rz = inputParams.getDouble("rz");
|
Double rz = inputParams.getDouble("rz");
|
||||||
String frame = inputParams.getString("frame");
|
String frame = inputParams.getString("frame");
|
||||||
Double velocity = inputParams.getDouble("velocity");
|
Double velocity = inputParams.getDouble("velocity");
|
||||||
Double acceleration = inputParams.getDouble("acceleration");
|
Double acceleration = inputParams.getDouble("acceleration");
|
||||||
Double blendRadius = inputParams.getDouble("blendRadius");
|
Double blendRadius = inputParams.getDouble("blendRadius");
|
||||||
|
|
||||||
// 参数验证
|
// 参数验证
|
||||||
if (x == null || y == null || z == null) {
|
if (x == null || y == null || z == null) {
|
||||||
throw new GlobalException("X、Y、Z坐标不能为空");
|
throw new GlobalException("X、Y、Z坐标不能为空");
|
||||||
}
|
}
|
||||||
if (rx == null || ry == null || rz == null) {
|
if (rx == null || ry == null || rz == null) {
|
||||||
throw new GlobalException("RX、RY、RZ旋转角度不能为空");
|
throw new GlobalException("RX、RY、RZ旋转角度不能为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 直接调用边缘端机械臂服务执行笛卡尔空间直线运动
|
// 直接调用边缘端机械臂服务执行笛卡尔空间直线运动
|
||||||
ArmCommand.MoveL.Response result = edgeArmService.moveL(
|
edgeArmService.moveL(
|
||||||
edgeCommonVO,
|
edgeCommonVO,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
@ -88,15 +89,11 @@ public class EdgeArmOperateService implements EdgeOperateService {
|
|||||||
velocity,
|
velocity,
|
||||||
acceleration,
|
acceleration,
|
||||||
blendRadius
|
blendRadius
|
||||||
);
|
);
|
||||||
|
|
||||||
log.info("机械臂末端运动任务下发成功");
|
log.info("机械臂末端运动任务下发成功");
|
||||||
|
} else {
|
||||||
break;
|
throw new GlobalException("不支持的机械臂操作类型: " + action);
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new GlobalException("不支持的机械臂操作类型: " + action);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return TaskNodeExecuteResult.success();
|
return TaskNodeExecuteResult.success();
|
||||||
|
|||||||
@ -12,6 +12,8 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@ -33,13 +35,12 @@ public class EdgeTouchOperateService implements EdgeOperateService {
|
|||||||
String deviceId = inputParams.getString("deviceId");
|
String deviceId = inputParams.getString("deviceId");
|
||||||
String touchParams = inputParams.getString("touchParams");
|
String touchParams = inputParams.getString("touchParams");
|
||||||
|
|
||||||
switch (action) {
|
if (Objects.requireNonNull(action) == ActionEnum.TOUCH) {
|
||||||
case TOUCH: {
|
EdgeArmMoveJVO edgeArmMoveJVO = JSON.parseObject(touchParams, EdgeArmMoveJVO.class);
|
||||||
EdgeArmMoveJVO edgeArmMoveJVO = JSON.parseObject(touchParams, EdgeArmMoveJVO.class);
|
edgeArmMoveJVO.setTerminalId(terminalId);
|
||||||
edgeArmMoveJVO.setTerminalId(terminalId);
|
edgeArmMoveJVO.setDeviceId(deviceId);
|
||||||
edgeArmMoveJVO.setDeviceId(deviceId);
|
|
||||||
|
|
||||||
edgeArmService.moveJ(
|
edgeArmService.moveJ(
|
||||||
edgeArmMoveJVO,
|
edgeArmMoveJVO,
|
||||||
edgeArmMoveJVO.getTarget(),
|
edgeArmMoveJVO.getTarget(),
|
||||||
edgeArmMoveJVO.getVelocity(),
|
edgeArmMoveJVO.getVelocity(),
|
||||||
@ -47,12 +48,9 @@ public class EdgeTouchOperateService implements EdgeOperateService {
|
|||||||
edgeArmMoveJVO.getBlendRadius(),
|
edgeArmMoveJVO.getBlendRadius(),
|
||||||
edgeArmMoveJVO.getJointVelocityLimits(),
|
edgeArmMoveJVO.getJointVelocityLimits(),
|
||||||
edgeArmMoveJVO.getAsynchronous()
|
edgeArmMoveJVO.getAsynchronous()
|
||||||
);
|
);
|
||||||
break;
|
} else {
|
||||||
}
|
throw new GlobalException("不支持的触控操作类型: " + action);
|
||||||
|
|
||||||
default:
|
|
||||||
throw new GlobalException("不支持的触控操作类型: " + action);
|
|
||||||
}
|
}
|
||||||
return TaskNodeExecuteResult.success();
|
return TaskNodeExecuteResult.success();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user