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,8 +53,7 @@ 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);
|
||||||
|
|
||||||
// 从输入参数中获取坐标信息
|
// 从输入参数中获取坐标信息
|
||||||
@ -76,7 +77,7 @@ public class EdgeArmOperateService implements EdgeOperateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 直接调用边缘端机械臂服务执行笛卡尔空间直线运动
|
// 直接调用边缘端机械臂服务执行笛卡尔空间直线运动
|
||||||
ArmCommand.MoveL.Response result = edgeArmService.moveL(
|
edgeArmService.moveL(
|
||||||
edgeCommonVO,
|
edgeCommonVO,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
@ -91,11 +92,7 @@ public class EdgeArmOperateService implements EdgeOperateService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
log.info("机械臂末端运动任务下发成功");
|
log.info("机械臂末端运动任务下发成功");
|
||||||
|
} else {
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new GlobalException("不支持的机械臂操作类型: " + action);
|
throw new GlobalException("不支持的机械臂操作类型: " + action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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,8 +35,7 @@ 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);
|
||||||
@ -48,10 +49,7 @@ public class EdgeTouchOperateService implements EdgeOperateService {
|
|||||||
edgeArmMoveJVO.getJointVelocityLimits(),
|
edgeArmMoveJVO.getJointVelocityLimits(),
|
||||||
edgeArmMoveJVO.getAsynchronous()
|
edgeArmMoveJVO.getAsynchronous()
|
||||||
);
|
);
|
||||||
break;
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new GlobalException("不支持的触控操作类型: " + action);
|
throw new GlobalException("不支持的触控操作类型: " + action);
|
||||||
}
|
}
|
||||||
return TaskNodeExecuteResult.success();
|
return TaskNodeExecuteResult.success();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user