Browse Source

现场代码同步

master
白凤吉 3 months ago
parent
commit
5ef2ae1092
  1. 74
      src/main/java/com/iflytop/gd/app/cmd/MoveToHeatAreaCommand.java
  2. 83
      src/main/java/com/iflytop/gd/app/cmd/MoveToSolutionAreaCommand.java
  3. 6
      src/main/java/com/iflytop/gd/app/cmd/ShakeStartCommand.java
  4. 7
      src/main/java/com/iflytop/gd/app/cmd/ShakeStopCommand.java
  5. 16
      src/main/java/com/iflytop/gd/app/cmd/TrayDownCommand.java
  6. 19
      src/main/java/com/iflytop/gd/app/cmd/TrayUpCommand.java
  7. 7
      src/main/java/com/iflytop/gd/app/cmd/debug/step/DebugCapInHeatAreaCommand.java
  8. 6
      src/main/java/com/iflytop/gd/app/cmd/debug/step/DebugCapOutHeatAreaCommand.java
  9. 1
      src/main/java/com/iflytop/gd/app/cmd/debug/step/DebugMoveTrayToHeatAreaCommand.java
  10. 2
      src/main/java/com/iflytop/gd/app/cmd/debug/step/DebugMoveTrayToSolutionAreaCommand.java
  11. 21
      src/main/java/com/iflytop/gd/app/config/AsyncConfig.java
  12. 7
      src/main/java/com/iflytop/gd/app/controller/CmdController.java
  13. 6
      src/main/java/com/iflytop/gd/app/controller/DevicePointController.java
  14. 2
      src/main/java/com/iflytop/gd/app/controller/TasksController.java
  15. 9
      src/main/java/com/iflytop/gd/app/core/BaseCommandHandler.java
  16. 31
      src/main/java/com/iflytop/gd/app/core/CommandPoolManager.java
  17. 35
      src/main/java/com/iflytop/gd/app/core/device/CommandState.java
  18. 1
      src/main/java/com/iflytop/gd/app/core/device/DeviceState.java
  19. 20
      src/main/java/com/iflytop/gd/app/model/dto/AddDevicePositionDTO.java
  20. 10
      src/main/java/com/iflytop/gd/app/service/DevicePositionService.java
  21. 6
      src/main/java/com/iflytop/gd/app/service/DeviceStateService.java
  22. 18
      src/main/java/com/iflytop/gd/app/service/TasksService.java
  23. 2
      src/main/java/com/iflytop/gd/app/service/WebSocketService.java
  24. 61
      src/main/java/com/iflytop/gd/app/ws/client/DeviceEmergencyStopClient.java
  25. 50
      src/main/java/com/iflytop/gd/app/ws/client/DeviceEmergencyStopConfig.java
  26. 2
      src/main/java/com/iflytop/gd/app/ws/server/WebSocketServer.java
  27. 4
      src/main/java/com/iflytop/gd/app/ws/server/WebSocketServerConfig.java
  28. 4
      src/main/java/com/iflytop/gd/common/result/ResultCode.java
  29. 2
      src/main/java/com/iflytop/gd/hardware/config/StepMotorConfig.java
  30. 3
      src/main/resources/sql/init.sql

74
src/main/java/com/iflytop/gd/app/cmd/MoveToHeatAreaCommand.java

@ -18,7 +18,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* 移至加热
@ -32,13 +31,15 @@ public class MoveToHeatAreaCommand extends BaseCommandHandler {
private final DevicePositionService devicePositionService;
private final GantryArmService gantryArmService;
private final DeviceStateService deviceStateService;
private final AtomicBoolean isExecuting = new AtomicBoolean(false);
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) throws Exception {
if (isExecuting.get()) {
if (deviceStateService.getCommandState().get().isMoveToHeatAreaCommandExecuting()) {
throw new AppException(ResultCode.COMMAND_ALREADY_EXECUTING);
}
if (deviceStateService.getCommandState().get().isMoveToSolutionAreaCommandExecuting()) {
throw new AppException(ResultCode.CMD_BUSY);
}
String heatId = cmdDTO.getStringParam("heatId");
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId);
double clawCapPick = devicePositionService.getPosition(DevicePositionCode.clawCapPick).getDistance(); //获取拍子夹取距离
@ -54,57 +55,90 @@ public class MoveToHeatAreaCommand extends BaseCommandHandler {
Point3D liquidAreaTrayPoint3D = devicePositionService.getPosition(DevicePositionCode.liquidAreaTrayPoint).getPoint3D();//获取加液模块上方点位
Point3D heatAreaTrayClawPoint3D = deviceCommandUtilService.getHeatAreaTrayClawPoint3D(heatModuleId);//获取指定加热模块上方点位
Point3D heatArea4TrayClawPoint3D = deviceCommandUtilService.getHeatAreaTrayClawPoint3D(HeatModuleCode.heat_module_04);//获取指定加热模块上方点位
Point3D heatAreaCapClawPointPoint3D = deviceCommandUtilService.getHeatAreaCapClawPointPoint3D(heatModuleId);//获取指定加热模块拍子上方点位
Point3D capStorageCapClawPoint3D = devicePositionService.getPosition(DevicePositionCode.capStorageCapClawPoint).getPoint3D();//获取拍子存放区上方点位;
//校验目标加热位是否有托盘
try {
deviceStateService.setGantryArmStateIdle(false);
isExecuting.set(true);
Boolean heatModuleTray = deviceCommandUtilService.heatModuleSensorState(heatModuleId);
if (heatModuleTray) {
throw new AppException(ResultCode.TARGET_HEAT_MODULE_NO_TRAY);
}
} finally {
deviceStateService.setGantryArmStateIdle(true);
isExecuting.set(false);
deviceStateService.getCommandState().get().setMoveToHeatAreaCommandExecuting(true);
// Boolean heatModuleTray = deviceCommandUtilService.heatModuleSensorState(heatModuleId);
// if (heatModuleTray) {
// throw new AppException(ResultCode.TARGET_HEAT_MODULE_NO_TRAY);
// }
} catch (Exception e) {
deviceStateService.getCommandState().get().setMoveToHeatAreaCommandExecuting(false);
throw e;
}
return runAsync(() -> {
try {
TrayState trayState = deviceStateService.getTrayInSolutionModule();
deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand());//提升拍子存放区至拍子夹取的高度
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint3D); //将机械臂移动至加液模块上方
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayPick);//将夹爪打开准备夹取托盘
deviceCommandUtilService.gantryZMove(solutionModuleTrayMoveHeight);//下降z轴,使夹爪落入托盘孔位
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayGrip);//将夹爪收紧夹住托盘
deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
deviceStateService.setSolutionModuleStateTrayStatus(0);//加液模块是否有托盘
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatArea4TrayClawPoint3D);//将携带托盘的机械臂移动至4号加热模块上方
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaTrayClawPoint3D);//将携带托盘的机械臂移动至加热模块上方
deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLift);//抬升加热位托盘
deviceCommandUtilService.gantryZMove(heatModuleTrayMoveHeight);//下降z轴,使托盘落入加热模块
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayPick);//将夹爪打开释放托盘
deviceStateService.setHeatModuleStateTrayStatus(heatModuleId, 1);//加热模块是否存在托盘
deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
// deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand());//提升拍子存放区至拍子夹取的高度
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开准备夹取拍子
deviceCommandUtilService.gantryZMove(capModuleCapMoveHeight);//下降z轴,使夹爪落入拍子升降模块拍子孔位
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapGrip);//将夹爪收紧夹住拍子
deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand()); //提升拍子存放区
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaTrayClawPoint3D);//将携带拍子的机械臂移动至加热模块上方
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaCapClawPointPoint3D);//将携带拍子的机械臂移动至加热模块拍子上方
deviceCommandUtilService.gantryZMove(heatModuleCapMoveHeight);//下降z轴,使夹拍子落入加热模块
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开释放拍子
deviceStateService.setHeatModuleStateCapExist(heatModuleId, true);//加热模块是否存在拍子
deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
trayState.setHeatModuleId(heatModuleId);
trayState.setInHeatModule(true);
// trayState.setHeatModuleId(heatModuleId);
// trayState.setInHeatModule(true);
gantryArmService.setLiquidIdleTrue();//释放加液区等待
deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLower);//下降加热模块托盘
deviceStateService.setHeatModuleStateTrayUp(heatModuleId, 0);//加热模块托盘升降状态
deviceCommandUtilService.gantryMoveZero();//将机械臂移动至0点
// deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand()); //提升拍子存放区
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方
// deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand());//提升拍子存放区至拍子夹取的高度
// deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint3D); //将机械臂移动至加液模块上方
// deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayPick);//将夹爪打开准备夹取托盘
// deviceCommandUtilService.gantryZMove(solutionModuleTrayMoveHeight);//下降z轴,使夹爪落入托盘孔位
// deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayGrip);//将夹爪收紧夹住托盘
// deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
// deviceStateService.setSolutionModuleStateTrayStatus(0);//加液模块是否有托盘
// deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaTrayClawPoint3D);//将携带托盘的机械臂移动至加热模块上方
// deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLift);//抬升加热位托盘
// deviceCommandUtilService.gantryZMove(heatModuleTrayMoveHeight);//下降z轴,使托盘落入加热模块
// deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayPick);//将夹爪打开释放托盘
// deviceStateService.setHeatModuleStateTrayStatus(heatModuleId, 1);//加热模块是否存在托盘
// deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
// deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方
// deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开准备夹取拍子
// deviceCommandUtilService.gantryZMove(capModuleCapMoveHeight);//下降z轴,使夹爪落入拍子升降模块拍子孔位
// deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapGrip);//将夹爪收紧夹住拍子
// deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
// deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand()); //提升拍子存放区
// deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaTrayClawPoint3D);//将携带拍子的机械臂移动至加热模块上方
// deviceCommandUtilService.gantryZMove(heatModuleCapMoveHeight);//下降z轴,使夹拍子落入加热模块
// deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开释放拍子
// deviceStateService.setHeatModuleStateCapExist(heatModuleId, true);//加热模块是否存在拍子
// deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
// trayState.setHeatModuleId(heatModuleId);
// trayState.setInHeatModule(true);
// gantryArmService.setLiquidIdleTrue();//释放加液区等待
// deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLower);//下降加热模块托盘
// deviceStateService.setHeatModuleStateTrayUp(heatModuleId, 0);//加热模块托盘升降状态
// deviceCommandUtilService.gantryMoveZero();//将机械臂移动至0点
} finally {
deviceStateService.setGantryArmStateIdle(true);
isExecuting.set(false);
deviceStateService.getCommandState().get().setMoveToHeatAreaCommandExecuting(false);
}
});
}

83
src/main/java/com/iflytop/gd/app/cmd/MoveToSolutionAreaCommand.java

@ -7,7 +7,6 @@ import com.iflytop.gd.app.model.dto.CmdDTO;
import com.iflytop.gd.app.service.DeviceCommandUtilService;
import com.iflytop.gd.app.service.DevicePositionService;
import com.iflytop.gd.app.service.DeviceStateService;
import com.iflytop.gd.app.service.GantryArmService;
import com.iflytop.gd.common.annotation.CommandMapping;
import com.iflytop.gd.common.enums.HeatModuleCode;
import com.iflytop.gd.common.enums.data.DevicePositionCode;
@ -18,7 +17,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* 移至加液
@ -30,15 +28,16 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class MoveToSolutionAreaCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final DevicePositionService devicePositionService;
private final GantryArmService gantryArmService;
private final DeviceStateService deviceStateService;
private final AtomicBoolean isExecuting = new AtomicBoolean(false);
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) throws Exception {
if (isExecuting.get()) {
if (deviceStateService.getCommandState().get().isMoveToSolutionAreaCommandExecuting()) {
throw new AppException(ResultCode.COMMAND_ALREADY_EXECUTING);
}
if (deviceStateService.getCommandState().get().isMoveToHeatAreaCommandExecuting()) {
throw new AppException(ResultCode.CMD_BUSY);
}
String heatId = cmdDTO.getStringParam("heatId");
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId);
double clawCapPick = devicePositionService.getPosition(DevicePositionCode.clawCapPick).getDistance(); //获取拍子夹取距离
@ -54,58 +53,94 @@ public class MoveToSolutionAreaCommand extends BaseCommandHandler {
Point3D liquidAreaTrayPoint3D = devicePositionService.getPosition(DevicePositionCode.liquidAreaTrayPoint).getPoint3D();//获取加液模块上方点位
Point3D heatAreaTrayClawPoint3D = deviceCommandUtilService.getHeatAreaTrayClawPoint3D(heatModuleId);//获取指定加热模块上方点位
Point3D heatArea4TrayClawPoint3D = deviceCommandUtilService.getHeatAreaTrayClawPoint3D(HeatModuleCode.heat_module_04);//获取指定加热模块上方点位
Point3D heatAreaCapClawPointPoint3D = deviceCommandUtilService.getHeatAreaCapClawPointPoint3D(heatModuleId);//获取指定加热模块拍子上方点位
Point3D capStorageCapClawPoint3D = devicePositionService.getPosition(DevicePositionCode.capStorageCapClawPoint).getPoint3D();//获取拍子存放区上方点位;
//校验目标加热位是否有托盘
try {
deviceStateService.setGantryArmStateIdle(false);
isExecuting.set(true);
Boolean heatModuleTray = deviceCommandUtilService.heatModuleSensorState(heatModuleId);
if (!heatModuleTray) {
throw new AppException(ResultCode.TARGET_HEAT_MODULE_OCCUPIED);
}
} finally {
deviceStateService.setGantryArmStateIdle(true);
isExecuting.set(false);
deviceStateService.getCommandState().get().setMoveToSolutionAreaCommandExecuting(true);
// Boolean heatModuleTray = deviceCommandUtilService.heatModuleSensorState(heatModuleId);
// if (!heatModuleTray) {
// throw new AppException(ResultCode.TARGET_HEAT_MODULE_OCCUPIED);
// }
} catch (Exception e) {
deviceStateService.getCommandState().get().setMoveToSolutionAreaCommandExecuting(false);
throw e;
}
return runAsync(() -> {
try {
TrayState trayState = deviceStateService.getTrayInSolutionModule();
// gantryArmService.waitLiquidIdle();//等待加液区空闲
// gantryArmService.setLiquidIdleFalse();//锁定加液区
deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand()); //提升拍子存放区至拍子夹取的高度
// deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand()); //提升拍子存放区至拍子夹取的高度
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaCapClawPointPoint3D);//将机械臂移动至加热模块拍子上方
deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLift);//抬升指定加热位托盘
deviceStateService.setHeatModuleStateTrayUp(heatModuleId, 1);//将加热模块托盘状态改为抬起
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaTrayClawPoint3D);//将机械臂移动至加热模块上方
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开准备夹取拍子
deviceCommandUtilService.gantryZMove(heatModuleCapMoveHeight);//下降z轴,使夹爪落入加热模块拍子孔位
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapGrip);//将夹爪收紧夹住拍子
deviceStateService.setHeatModuleStateCapExist(heatModuleId, false);//加热模块是否存在拍子
deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
// deviceCommandUtilService.capMotorMoveByNum(-1);//拍子存放模块下降1个拍子位置
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), capStorageCapClawPoint3D);//将携带拍子的机械臂移动至存放区上方
deviceCommandUtilService.capMotorMoveByNum(-1);//拍子存放模块下降1个拍子位置
deviceCommandUtilService.gantryZMove(capModuleCapMoveHeight);//下降z轴,使夹拍子落入存放区
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开释放夹取的拍子
deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaTrayClawPoint3D);//将机械臂移动至加热模块上方
deviceStateService.setHeatModuleStateTrayUp(heatModuleId, 1);//将加热模块托盘状态改为抬起
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayPick);//将夹爪打开准备夹取托盘
deviceCommandUtilService.gantryZMove(heatModuleTrayMoveHeight);//下降z轴,使夹爪落入托盘孔位
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayGrip);//将夹爪收紧夹住托盘
deviceStateService.setHeatModuleStateTrayStatus(heatModuleId, 0);//加热模块是否存在托盘
trayState.setInHeatModule(false);//托盘是否在加热模块中
// trayState.setInHeatModule(false);//托盘是否在加热模块中
deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLower);//下降加热模块托盘
deviceStateService.setHeatModuleStateTrayUp(heatModuleId, 0);//加热模块托盘升降状态
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatArea4TrayClawPoint3D);//将携带托盘的机械臂移动至4号加热模块上方
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint3D); //将携带托盘的机械臂移动至加液模块上方
deviceCommandUtilService.gantryZMove(solutionModuleTrayMoveHeight);//下降z轴,使托盘落入加液模块
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayPick);//将夹爪打开释放托盘
trayState.setInSolutionModule(true);//托盘是否在加液模块中
// trayState.setInSolutionModule(true);//托盘是否在加液模块中
deviceStateService.setSolutionModuleStateTrayStatus(1);//加液模块是否存在托盘
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayPick);//将夹爪打开释放托盘
deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLower);//下降加热模块托盘
deviceCommandUtilService.gantryMoveZero();//将机械臂移动至0点
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方
// deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand()); //提升拍子存放区至拍子夹取的高度
// deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLift);//抬升指定加热位托盘
// deviceStateService.setHeatModuleStateTrayUp(heatModuleId, 1);//将加热模块托盘状态改为抬起
// deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaTrayClawPoint3D);//将机械臂移动至加热模块上方
// deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开准备夹取拍子
// deviceCommandUtilService.gantryZMove(heatModuleCapMoveHeight);//下降z轴,使夹爪落入加热模块拍子孔位
// deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapGrip);//将夹爪收紧夹住拍子
// deviceStateService.setHeatModuleStateCapExist(heatModuleId, false);//加热模块是否存在拍子
// deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
// deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), capStorageCapClawPoint3D);//将携带拍子的机械臂移动至存放区上方
// deviceCommandUtilService.capMotorMoveByNum(-1);//拍子存放模块下降1个拍子位置
// deviceCommandUtilService.gantryZMove(capModuleCapMoveHeight);//下降z轴,使夹拍子落入存放区
// deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开释放夹取的拍子
// deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
// deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaTrayClawPoint3D);//将机械臂移动至加热模块上方
// deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayPick);//将夹爪打开准备夹取托盘
// deviceCommandUtilService.gantryZMove(heatModuleTrayMoveHeight);//下降z轴,使夹爪落入托盘孔位
// deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayGrip);//将夹爪收紧夹住托盘
// deviceStateService.setHeatModuleStateTrayStatus(heatModuleId, 0);//加热模块是否存在托盘
// trayState.setInHeatModule(false);//托盘是否在加热模块中
// deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
// deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint3D); //将携带托盘的机械臂移动至加液模块上方
// deviceCommandUtilService.gantryZMove(solutionModuleTrayMoveHeight);//下降z轴,使托盘落入加液模块
// deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayPick);//将夹爪打开释放托盘
// trayState.setInSolutionModule(true);//托盘是否在加液模块中
// deviceStateService.setSolutionModuleStateTrayStatus(1);//加液模块是否存在托盘
// deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
// deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLower);//下降加热模块托盘
// deviceCommandUtilService.gantryMoveZero();//将机械臂移动至0点
} finally {
deviceStateService.setGantryArmStateIdle(true);
isExecuting.set(false);
deviceStateService.getCommandState().get().setMoveToSolutionAreaCommandExecuting(false);
}
});
}

6
src/main/java/com/iflytop/gd/app/cmd/ShakeStartCommand.java

@ -5,6 +5,8 @@ import com.iflytop.gd.app.model.dto.CmdDTO;
import com.iflytop.gd.app.service.DeviceCommandUtilService;
import com.iflytop.gd.app.service.DeviceStateService;
import com.iflytop.gd.common.annotation.CommandMapping;
import com.iflytop.gd.common.exception.AppException;
import com.iflytop.gd.common.result.ResultCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@ -24,6 +26,10 @@ public class ShakeStartCommand extends BaseCommandHandler {
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
if (deviceStateService.getCommandState().get().isMoveToHeatAreaCommandExecuting()
|| deviceStateService.getCommandState().get().isMoveToSolutionAreaCommandExecuting()) {
throw new AppException(ResultCode.CMD_BUSY);
}
return runAsync(() -> {
deviceCommandUtilService.shakeStart(cmdDTO.getCommandId(), cmdDTO.getCommand());//开始摇匀
deviceStateService.setSolutionModuleStateShaking(true);

7
src/main/java/com/iflytop/gd/app/cmd/ShakeStopCommand.java

@ -5,6 +5,8 @@ import com.iflytop.gd.app.model.dto.CmdDTO;
import com.iflytop.gd.app.service.DeviceCommandUtilService;
import com.iflytop.gd.app.service.DeviceStateService;
import com.iflytop.gd.common.annotation.CommandMapping;
import com.iflytop.gd.common.exception.AppException;
import com.iflytop.gd.common.result.ResultCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@ -25,7 +27,12 @@ public class ShakeStopCommand extends BaseCommandHandler {
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
if (deviceStateService.getCommandState().get().isMoveToHeatAreaCommandExecuting()
|| deviceStateService.getCommandState().get().isMoveToSolutionAreaCommandExecuting()) {
throw new AppException(ResultCode.CMD_BUSY);
}
deviceCommandUtilService.shakeStop(cmdDTO.getCommandId(), cmdDTO.getCommand());//停止摇匀
deviceCommandUtilService.shakeOrigin(cmdDTO.getCommandId(), cmdDTO.getCommand());//摇匀回原点
deviceStateService.setSolutionModuleStateShaking(false);
});
}

16
src/main/java/com/iflytop/gd/app/cmd/TrayDownCommand.java

@ -9,6 +9,8 @@ import com.iflytop.gd.app.service.DeviceStateService;
import com.iflytop.gd.common.annotation.CommandMapping;
import com.iflytop.gd.common.enums.HeatModuleCode;
import com.iflytop.gd.common.enums.data.DevicePositionCode;
import com.iflytop.gd.common.exception.AppException;
import com.iflytop.gd.common.result.ResultCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@ -29,16 +31,26 @@ public class TrayDownCommand extends BaseCommandHandler {
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
if (deviceStateService.getCommandState().get().isMoveToHeatAreaCommandExecuting()
|| deviceStateService.getCommandState().get().isMoveToSolutionAreaCommandExecuting()) {
throw new AppException(ResultCode.CMD_BUSY);
}
JSONArray heatIdJsonArray = cmdDTO.getJSONArrayParam("heatId");
//从数据库获取加热位下降托盘位置
double trayLower = devicePositionService.getPosition(DevicePositionCode.trayLower).getDistance();
return runAsync(() -> {
for (int i = 0; i < heatIdJsonArray.size(); i++) {
String heatId = heatIdJsonArray.getStr(i);
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId);
//从数据库获取加热位下降托盘位置
double trayLower = devicePositionService.getPosition(DevicePositionCode.trayLower).getDistance();
CompletableFuture.runAsync(() -> {
try {
//下降加热位托盘
deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLower);
deviceStateService.setHeatModuleStateTrayUp(heatModuleId, 0);
} catch (Exception e) {
log.error("降下托盘失败", e);
}
});
}
});
}

19
src/main/java/com/iflytop/gd/app/cmd/TrayUpCommand.java

@ -7,8 +7,11 @@ import com.iflytop.gd.app.service.DeviceCommandUtilService;
import com.iflytop.gd.app.service.DevicePositionService;
import com.iflytop.gd.app.service.DeviceStateService;
import com.iflytop.gd.common.annotation.CommandMapping;
import com.iflytop.gd.common.enums.AcidPumpDeviceCode;
import com.iflytop.gd.common.enums.HeatModuleCode;
import com.iflytop.gd.common.enums.data.DevicePositionCode;
import com.iflytop.gd.common.exception.AppException;
import com.iflytop.gd.common.result.ResultCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@ -26,19 +29,29 @@ public class TrayUpCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final DevicePositionService devicePositionService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
if (deviceStateService.getCommandState().get().isMoveToHeatAreaCommandExecuting()
|| deviceStateService.getCommandState().get().isMoveToSolutionAreaCommandExecuting()) {
throw new AppException(ResultCode.CMD_BUSY);
}
JSONArray heatIdJsonArray = cmdDTO.getJSONArrayParam("heatId");
//获取加热位抬升托盘位置
double trayLift = devicePositionService.getPosition(DevicePositionCode.trayLift).getDistance();
return runAsync(() -> {
for (int i = 0; i < heatIdJsonArray.size(); i++) {
String heatId = heatIdJsonArray.getStr(i);
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId);
//获取加热位抬升托盘位置
double trayLift = devicePositionService.getPosition(DevicePositionCode.trayLift).getDistance();
CompletableFuture.runAsync(() -> {
try {
//抬升加热位托盘
deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLift);
deviceStateService.setHeatModuleStateTrayUp(heatModuleId, 1);
} catch (Exception e) {
log.error("抬起托盘失败", e);
}
});
}
});
}

7
src/main/java/com/iflytop/gd/app/cmd/debug/step/DebugCapInHeatAreaCommand.java

@ -40,19 +40,20 @@ public class DebugCapInHeatAreaCommand extends BaseCommandHandler {
Point3D capStorageCapClawPoint3D = devicePositionService.getPosition(DevicePositionCode.capStorageCapClawPoint).getPoint3D();//获取拍子存放区上方点位;
return runAsync(() -> {
deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand());//提升拍子存放区至拍子夹取的高度
deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLift);//抬升加热模块托盘
// deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand());//提升拍子存放区至拍子夹取的高度
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开准备夹取拍子
deviceCommandUtilService.gantryZMove(capModuleCapMoveHeight);//下降z轴,使夹爪落入拍子升降模块拍子孔位
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapGrip);//将夹爪收紧夹住拍子
deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaCapClawPointPoint3D);//将携带拍子的机械臂移动至加热模块拍子上方
deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLift);//抬升加热模块托盘
deviceCommandUtilService.gantryZMove(heatModuleCapMoveHeight);//下降z轴,使夹拍子落入加热模块
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开释放拍子
deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLower);//下降加热模块托盘
deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand()); //提升拍子存放区
// deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand()); //提升拍子存放区
});
}
}

6
src/main/java/com/iflytop/gd/app/cmd/debug/step/DebugCapOutHeatAreaCommand.java

@ -40,14 +40,14 @@ public class DebugCapOutHeatAreaCommand extends BaseCommandHandler {
Point3D capStorageCapClawPoint3D = devicePositionService.getPosition(DevicePositionCode.capStorageCapClawPoint).getPoint3D();//获取拍子存放区上方点位;
return runAsync(() -> {
deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand()); //提升拍子存放区至拍子夹取的高度
deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLift);//抬升指定加热位托盘
// deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand()); //提升拍子存放区至拍子夹取的高度
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaCapClawPointPoint3D);//将机械臂移动至加热模块拍子上方
deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLift);//抬升指定加热位托盘
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开准备夹取拍子
deviceCommandUtilService.gantryZMove(heatModuleCapMoveHeight);//下降z轴,使夹爪落入加热模块拍子孔位
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapGrip);//将夹爪收紧夹住拍子
deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
deviceCommandUtilService.capMotorMoveByNum(-1);//拍子存放模块下降1个拍子位置
// deviceCommandUtilService.capMotorMoveByNum(-1);//拍子存放模块下降1个拍子位置
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), capStorageCapClawPoint3D);//将携带拍子的机械臂移动至存放区上方
deviceCommandUtilService.gantryZMove(capModuleCapMoveHeight);//下降z轴,使夹拍子落入存放区
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开释放夹取的拍子

1
src/main/java/com/iflytop/gd/app/cmd/debug/step/DebugMoveTrayToHeatAreaCommand.java

@ -41,7 +41,6 @@ public class DebugMoveTrayToHeatAreaCommand extends BaseCommandHandler {
Point3D heatArea4TrayClawPoint3D = deviceCommandUtilService.getHeatAreaTrayClawPoint3D(HeatModuleCode.heat_module_04);//获取指定加热模块上方点位
return runAsync(() -> {
deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLift);//抬升指定加热位托盘
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint3D); //将机械臂移动至加液模块上方
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayPick);//将夹爪打开准备夹取托盘
deviceCommandUtilService.gantryZMove(solutionModuleTrayMoveHeight);//下降z轴,使夹爪落入托盘孔位

2
src/main/java/com/iflytop/gd/app/cmd/debug/step/DebugMoveTrayToSolutionAreaCommand.java

@ -41,8 +41,8 @@ public class DebugMoveTrayToSolutionAreaCommand extends BaseCommandHandler {
Point3D heatArea4TrayClawPoint3D = deviceCommandUtilService.getHeatAreaTrayClawPoint3D(HeatModuleCode.heat_module_04);//获取指定加热模块上方点位
return runAsync(() -> {
deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLift);//抬升指定加热位托盘
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaTrayClawPoint3D);//将机械臂移动至加热模块上方
deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLift);//抬升指定加热位托盘
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayPick);//将夹爪打开准备夹取托盘
deviceCommandUtilService.gantryZMove(heatModuleTrayMoveHeight);//下降z轴,使夹爪落入托盘孔位
deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayGrip);//将夹爪收紧夹住托盘

21
src/main/java/com/iflytop/gd/app/config/AsyncConfig.java

@ -0,0 +1,21 @@
package com.iflytop.gd.app.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@Configuration
public class AsyncConfig {
@Bean("commandTaskExecutor")
public ThreadPoolTaskExecutor taskExecutor() {
ThreadPoolTaskExecutor exec = new ThreadPoolTaskExecutor();
exec.setCorePoolSize(10);
exec.setMaxPoolSize(20);
exec.setQueueCapacity(50);
exec.setThreadNamePrefix("cmd-exec-");
exec.setWaitForTasksToCompleteOnShutdown(true);
exec.setAwaitTerminationSeconds(30);
exec.initialize();
return exec;
}
}

7
src/main/java/com/iflytop/gd/app/controller/CmdController.java

@ -4,10 +4,13 @@ import cn.hutool.json.JSONUtil;
import com.iflytop.gd.app.core.CommandHandlerRegistry;
import com.iflytop.gd.app.core.DebugGenerator;
import com.iflytop.gd.app.model.dto.CmdDTO;
import com.iflytop.gd.app.service.DeviceStateService;
import com.iflytop.gd.app.service.WebSocketService;
import com.iflytop.gd.common.cmd.CommandHandler;
import com.iflytop.gd.common.constant.CommandStatus;
import com.iflytop.gd.common.exception.AppException;
import com.iflytop.gd.common.result.Result;
import com.iflytop.gd.common.result.ResultCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
@ -28,6 +31,7 @@ import java.util.concurrent.CompletableFuture;
public class CmdController {
private final CommandHandlerRegistry registry;
private final WebSocketService webSocketService;
private final DeviceStateService deviceStateService;
@Operation(summary = "前端统一调用一个接口")
@PostMapping
@ -36,6 +40,9 @@ public class CmdController {
String command = cmdDTO.getCommand();
try {
webSocketService.pushDebug(DebugGenerator.generateJson(commandId, command, CommandStatus.RECEIVE, "已收到业务指令请求,开始处理"));
if (deviceStateService.getDeviceState().isEmergencyStop()) {
throw new AppException(ResultCode.EMERGENCY_STOP);
}
CommandHandler commandHandler = registry.getCommandHandler(command);
if (commandHandler == null) {
webSocketService.pushDebug(DebugGenerator.generateJson(commandId, command, CommandStatus.DEVICE_ERROR, "未找到对应的业务指令"));

6
src/main/java/com/iflytop/gd/app/controller/DevicePointController.java

@ -1,5 +1,6 @@
package com.iflytop.gd.app.controller;
import com.iflytop.gd.app.model.dto.AddDevicePositionDTO;
import com.iflytop.gd.app.model.entity.DevicePosition;
import com.iflytop.gd.app.model.vo.DevicePositionVO;
import com.iflytop.gd.app.service.DevicePositionService;
@ -42,9 +43,8 @@ public class DevicePointController {
@Operation(summary = "修改")
@PutMapping("")
public Result<String> update(@Valid @RequestBody DevicePosition devicePoint) {
devicePointService.updateById(devicePoint);
return Result.success();
public Result<?> update(@Valid @RequestBody AddDevicePositionDTO addDevicePositionDTO) {
return Result.success(devicePointService.updatePosition(addDevicePositionDTO));
}
@Operation(summary = "删除")

2
src/main/java/com/iflytop/gd/app/controller/TasksController.java

@ -57,7 +57,7 @@ public class TasksController {
@PostMapping("/")
public Result<Tasks> start(@RequestBody TaskDTO dto) {
if (tasksService.getCurrent() != null) {
return Result.failed("存在正在运行的实验,请先止");
return Result.failed("存在正在运行的实验,请先止");
}
return Result.success(tasksService.start(dto.getName()));
}

9
src/main/java/com/iflytop/gd/app/core/BaseCommandHandler.java

@ -5,15 +5,22 @@ import com.iflytop.gd.common.annotation.CheckedRunnable;
import com.iflytop.gd.common.cmd.CommandFuture;
import com.iflytop.gd.common.cmd.CommandHandler;
import com.iflytop.gd.common.utils.LambdaUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
public abstract class BaseCommandHandler implements CommandHandler {
@Autowired
@Qualifier("commandTaskExecutor")
private Executor commandExecutor;
protected CompletableFuture<Void> runAsync(CheckedRunnable task) {
return CompletableFuture.runAsync(LambdaUtil.unchecked(task));
return CompletableFuture.runAsync(LambdaUtil.unchecked(task), commandExecutor);
}
protected void commandWait(CommandFuture... futures) throws Exception {

31
src/main/java/com/iflytop/gd/app/core/CommandPoolManager.java

@ -0,0 +1,31 @@
package com.iflytop.gd.app.core;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import java.util.concurrent.ThreadPoolExecutor;
@Slf4j
@Component
public class CommandPoolManager {
private final ThreadPoolTaskExecutor executor;
public CommandPoolManager(@Qualifier("commandTaskExecutor") ThreadPoolTaskExecutor executor) {
this.executor = executor;
}
/**
* 强制中断所有正在执行的任务
*/
public void forceShutdownAll() {
try {
ThreadPoolExecutor nativeExecutor = executor.getThreadPoolExecutor();
nativeExecutor.shutdownNow();
} catch (Exception e) {
log.error("强制关闭所有cmd线程失败");
}
}
}

35
src/main/java/com/iflytop/gd/app/core/device/CommandState.java

@ -0,0 +1,35 @@
package com.iflytop.gd.app.core.device;
import lombok.Data;
/**
* 指令互斥关系状态
*/
@Data
public class CommandState {
private boolean capFreeCommandExecuting = false;
private boolean capLiftingOriginCommandExecuting = false;
private boolean capUsedCommandExecuting = false;
private boolean doorCloseCommandExecuting = false;
private boolean doorOpenCommandExecuting = false;
private boolean doorOriginCommandExecuting = false;
private boolean dualRobotJointOriginCommandExecuting = false;
private boolean fanStartCommandExecuting = false;
private boolean fanStopCommandExecuting = false;
private boolean filledSolutionStartCommandExecuting = false;
private boolean filledSolutionStopCommandExecuting = false;
private boolean gantryXOriginCommandExecuting = false;
private boolean gantryYOriginCommandExecuting = false;
private boolean gantryZOriginCommandExecuting = false;
private boolean heatStartCommandExecuting = false;
private boolean heatStopCommandExecuting = false;
private boolean moveToHeatAreaCommandExecuting = false;
private boolean moveToSolutionAreaCommandExecuting = false;
private boolean shakeStartCommandExecuting = false;
private boolean shakeStopCommandExecuting = false;
private boolean solutionAddCommandExecuting = false;
private boolean takePhotoCommandExecuting = false;
private boolean trayDownCommandExecuting = false;
private boolean trayLiftingOriginCommandExecuting = false;
private boolean trayUpCommandExecuting = false;
}

1
src/main/java/com/iflytop/gd/app/core/device/DeviceState.java

@ -7,6 +7,7 @@ import lombok.Data;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
@Schema(description = "当前设备")
@Data

20
src/main/java/com/iflytop/gd/app/model/dto/AddDevicePositionDTO.java

@ -0,0 +1,20 @@
package com.iflytop.gd.app.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@Data
public class AddDevicePositionDTO {
private Long id;
@NotNull
@NotBlank
@Schema(description = "位置数据")
private String position;
}

10
src/main/java/com/iflytop/gd/app/service/DevicePositionService.java

@ -3,6 +3,7 @@ package com.iflytop.gd.app.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iflytop.gd.app.mapper.DevicePositionMapper;
import com.iflytop.gd.app.model.dto.AddDevicePositionDTO;
import com.iflytop.gd.app.model.entity.DevicePosition;
import com.iflytop.gd.app.model.vo.DevicePositionVO;
import com.iflytop.gd.common.enums.data.DevicePositionCode;
@ -36,6 +37,15 @@ public class DevicePositionService extends ServiceImpl<DevicePositionMapper, Dev
}
}
public boolean updatePosition(AddDevicePositionDTO addDevicePositionDTO){
DevicePosition devicePosition = this.getById(addDevicePositionDTO.getId());
if(devicePosition != null){
devicePosition.setPosition(addDevicePositionDTO.getPosition());
return this.updateById(devicePosition);
}
return false;
}
public List<DevicePositionVO> getList() {
List<DevicePosition> devicePositions = super.list();
return devicePositions.stream()

6
src/main/java/com/iflytop/gd/app/service/DeviceStateService.java

@ -6,11 +6,14 @@ import com.iflytop.gd.app.model.entity.Tasks;
import com.iflytop.gd.app.model.entity.User;
import com.iflytop.gd.common.enums.ContainerCode;
import com.iflytop.gd.common.enums.HeatModuleCode;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.beans.PropertyChangeSupport;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
/**
* 设备状态服务
@ -22,6 +25,9 @@ public class DeviceStateService {
private final DeviceState deviceState = new DeviceState();
@Getter
private final AtomicReference<CommandState> commandState = new AtomicReference<>(new CommandState());
public synchronized DeviceState getDeviceState() {

18
src/main/java/com/iflytop/gd/app/service/TasksService.java

@ -6,12 +6,14 @@ import com.iflytop.gd.app.mapper.TasksMapper;
import com.iflytop.gd.app.model.entity.TaskSteps;
import com.iflytop.gd.app.model.entity.Tasks;
import com.iflytop.gd.app.model.vo.TaskStepsVO;
import com.iflytop.gd.common.exception.AppException;
import com.iflytop.gd.common.result.ResultCode;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@ -24,6 +26,14 @@ public class TasksService extends ServiceImpl<TasksMapper, Tasks> {
private final TaskStepsService taskStepsService;
private final DeviceStateService deviceStateService;
@PostConstruct
public void init() {
List<Tasks> tasksList = this.list(new LambdaQueryWrapper<Tasks>().eq(Tasks::getStatus, 1));
if(!tasksList.isEmpty()){
deviceStateService.getDeviceState().setCurrentTasks(tasksList.getFirst());
}
}
public TaskStepsVO detail(Long id) {
Tasks tasks = this.getById(id);
List<TaskSteps> taskSteps = taskStepsService.list(new LambdaQueryWrapper<>(TaskSteps.class).eq(TaskSteps::getTaskId, id));
@ -40,7 +50,11 @@ public class TasksService extends ServiceImpl<TasksMapper, Tasks> {
}
public Tasks start(String taskName) {
Tasks tasks = new Tasks();
Tasks tasks = this.getOne(new LambdaQueryWrapper<Tasks>().eq(Tasks::getName, taskName));
if (tasks != null) {
throw new AppException(ResultCode.DATA_ALREADY_EXISTS);
}
tasks = new Tasks();
tasks.setName(taskName);
tasks.setCreateUser(deviceStateService.getDeviceState().getCurrentUser().getId());
tasks.setStatus(1);

2
src/main/java/com/iflytop/gd/app/service/WebSocketService.java

@ -1,7 +1,7 @@
package com.iflytop.gd.app.service;
import cn.hutool.json.JSONUtil;
import com.iflytop.gd.app.config.WebSocketServer;
import com.iflytop.gd.app.ws.server.WebSocketServer;
import com.iflytop.gd.app.model.bo.Notification;
import com.iflytop.gd.app.model.dto.WebsocketResult;
import com.iflytop.gd.common.constant.WebSocketMessageType;

61
src/main/java/com/iflytop/gd/app/ws/client/DeviceEmergencyStopClient.java

@ -0,0 +1,61 @@
package com.iflytop.gd.app.ws.client;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.enums.ReadyState;
import org.java_websocket.handshake.ServerHandshake;
import org.springframework.scheduling.annotation.Scheduled;
import java.net.URI;
import java.util.function.Consumer;
/**
* WebsocketCliet监听设备发送的急停消息实现设备的急停
*/
@Slf4j
public class DeviceEmergencyStopClient extends WebSocketClient {
private Consumer<JSONObject> consumer;
public DeviceEmergencyStopClient(URI serverUri, Consumer<JSONObject> consumer) {
super(serverUri);
this.consumer = consumer;
}
@Override
public void onOpen(ServerHandshake handshakedata) {
log.info("device_status_listener_websocket connect success");
}
@Override
public void onMessage(String message) {
JSONObject jsonObject = JSONUtil.parseObj(message);
consumer.accept(jsonObject);
}
@Override
public void onClose(int code, String reason, boolean remote) {
log.info("device_status_listener_websocket lost connection...");
}
@Override
public void onError(Exception ex) {
log.info("device_status_listener_websocket on error");
}
//失去连接后重新连接 10s轮询
@Scheduled(fixedRate = 10000)
private void autoConnect() {
if (!isOpen()) {
if (getReadyState().equals(ReadyState.NOT_YET_CONNECTED)) {
try {
connect();
} catch (IllegalStateException ignored) {
}
} else if (getReadyState().equals(ReadyState.CLOSED)) {
reconnect();
}
}
}
}

50
src/main/java/com/iflytop/gd/app/ws/client/DeviceEmergencyStopConfig.java

@ -0,0 +1,50 @@
package com.iflytop.gd.app.ws.client;
import com.iflytop.gd.app.core.CommandPoolManager;
import com.iflytop.gd.app.service.DeviceStateService;
import com.iflytop.gd.app.service.StepCommandService;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.net.URI;
@Slf4j
@Configuration
@RequiredArgsConstructor
public class DeviceEmergencyStopConfig {
private final StepCommandService stepCommandService;
private final DeviceStateService deviceStateService;
private final CommandPoolManager commandPoolManager;
@Value("${iflytophald.ip}")
String ip;
@Value("${iflytophald.datach.port}")
Integer port;
@Bean
DeviceEmergencyStopClient stopAllClientService() {
URI uri = URI.create(String.format("ws://%s:%d/%s", ip, port, "key"));
return new DeviceEmergencyStopClient(uri, s -> {
if (s.get("event").equals("press")) {
log.info("触发急停{}", s);
try {
commandPoolManager.forceShutdownAll();//强制终止现在运行的所有指令
stepCommandService.stopAll();
deviceStateService.setEmergencyStop(true);
} catch (Exception e) {
log.error("设备急停失败:{}", e.getMessage());
throw new RuntimeException(e);
}
} else if (s.get("event").equals("release")) {
deviceStateService.setEmergencyStop(false);
log.info("解除急停{}", s);
}
});
}
}

2
src/main/java/com/iflytop/gd/app/config/WebSocketServer.java → src/main/java/com/iflytop/gd/app/ws/server/WebSocketServer.java

@ -1,4 +1,4 @@
package com.iflytop.gd.app.config;
package com.iflytop.gd.app.ws.server;
import jakarta.websocket.*;
import jakarta.websocket.server.ServerEndpoint;

4
src/main/java/com/iflytop/gd/app/config/WebSocketConfig.java → src/main/java/com/iflytop/gd/app/ws/server/WebSocketServerConfig.java

@ -1,11 +1,11 @@
package com.iflytop.gd.app.config;
package com.iflytop.gd.app.ws.server;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
@Configuration
public class WebSocketConfig {
public class WebSocketServerConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter() {

4
src/main/java/com/iflytop/gd/common/result/ResultCode.java

@ -46,13 +46,15 @@ public enum ResultCode implements IResultCode, Serializable {
EXTERNAL_API_ERROR("5002", "第三方服务调用失败"),
COMMAND_EXEC_TIMEOUT("5003", "命令执行超时"),
HARDWARE_ERROR("5004", "硬件错误"),
EMERGENCY_STOP("5555", "设备急停中"),
//============================ 6xxx指令相关 ============================
COMMAND_NOT_FOUND("6000", "指令未找到"),
COMMAND_ALREADY_EXECUTING("6001", "指令正在执行,无法重复执行"),
SENSOR_STATUS_FAILED("6010", "获取传感器状态失败"),
TARGET_HEAT_MODULE_OCCUPIED("6021", "目标加热模块被占用"),
TARGET_HEAT_MODULE_NO_TRAY("6022", "目标加热模块无托盘"),
CAP_LIFT_ERROR("6023", "拍子升降错误"), // 新增 cap 升降错误
CAP_LIFT_ERROR("6023", "拍子升降错误"),
CMD_BUSY("6024", "设备忙,请稍后"),
;
/** 状态码 */
private final String code;

2
src/main/java/com/iflytop/gd/hardware/config/StepMotorConfig.java

@ -83,7 +83,7 @@ public class StepMotorConfig {
static final double HEATER_MOTOR_DEFAULT_MAX_LIMIT = 100.0;
static final double ACID_PUMP_MOTOR_DEFAULT_MAX_LIMIT = 1000000;
final static Map<StepMotorMId, Double> stepMotorMaxLimitMap = Map.ofEntries(
Map.entry(StepMotorMId.DOOR_MOTOR_MID, 400.0),
Map.entry(StepMotorMId.DOOR_MOTOR_MID, 500.0),
Map.entry(StepMotorMId.SHAKE_MOTOR_MID, 20000.0),
Map.entry(StepMotorMId.TRAY_MOTOR_MID, 385.0),
Map.entry(StepMotorMId.HBOT_X_MOTOR_MID, 1400.0),

3
src/main/resources/sql/init.sql

@ -13,7 +13,8 @@ CREATE TABLE IF NOT EXISTS user
);
INSERT OR IGNORE INTO user (username, nickname, password, role, fixed_user, deleted)
VALUES ('admin', 'Admin', '123456', 'ADMIN', 'ENABLE', 'DISABLE');
VALUES ('admin', 'Admin', '123456', 'ADMIN', 'ENABLE', 'DISABLE'),
('test', 'test', '123456', 'ADMIN', 'ENABLE', 'DISABLE');
-- ores 矿石 表

Loading…
Cancel
Save