From 066e26bd3940327d6b112305f202eda99d1da2c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Thu, 5 Jun 2025 16:44:38 +0800 Subject: [PATCH] 1 --- .../gd/app/model/bo/status/device/DeviceState.java | 2 +- .../gd/app/model/bo/status/device/TrayState.java | 13 +++++- .../gd/app/model/bo/status/device/TubeState.java | 7 ++-- .../iflytop/gd/app/model/dto/StartCraftsDTO.java | 4 ++ .../iflytop/gd/app/service/api/CraftsService.java | 1 + .../iflytop/gd/app/service/api/TrayService.java | 5 ++- .../gd/app/service/crafts/CraftsStepService.java | 14 +++++-- .../device/module/SolutionModuleService.java | 49 ++++++++++++++++++---- .../scheduled/FetchTemperatureScheduledTask.java | 17 +++++--- .../scheduled/HeatCountdownScheduledTask.java | 38 ++++++----------- .../iflytop/gd/app/ws/server/WebSocketSender.java | 2 +- 11 files changed, 101 insertions(+), 51 deletions(-) diff --git a/src/main/java/com/iflytop/gd/app/model/bo/status/device/DeviceState.java b/src/main/java/com/iflytop/gd/app/model/bo/status/device/DeviceState.java index 52cdc4d..5032b11 100644 --- a/src/main/java/com/iflytop/gd/app/model/bo/status/device/DeviceState.java +++ b/src/main/java/com/iflytop/gd/app/model/bo/status/device/DeviceState.java @@ -75,7 +75,7 @@ public class DeviceState { public synchronized TrayState getTrayStateByHeatModuleCode(HeatModuleCode heatModuleCode) { for (TrayState t : tray) { - if (t.getHeatModuleId().equals(heatModuleCode)) { + if (heatModuleCode.equals(t.getHeatModuleId())) { return t; } } diff --git a/src/main/java/com/iflytop/gd/app/model/bo/status/device/TrayState.java b/src/main/java/com/iflytop/gd/app/model/bo/status/device/TrayState.java index 425783d..6fd5c14 100644 --- a/src/main/java/com/iflytop/gd/app/model/bo/status/device/TrayState.java +++ b/src/main/java/com/iflytop/gd/app/model/bo/status/device/TrayState.java @@ -1,13 +1,22 @@ package com.iflytop.gd.app.model.bo.status.device; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.iflytop.gd.common.enums.HeatModuleCode; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.annotation.PostConstruct; import lombok.Data; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; import java.util.UUID; @Schema(description = "托盘") @Data +@Component +@Scope("prototype") +@RequiredArgsConstructor +@JsonIgnoreProperties(value = {"advisors", "frozen", "preFiltered", "proxyTargetClass", "targetSource", "exposeProxy", "advisorCount", "proxiedInterfaces", "targetClass"}) public class TrayState { @Schema(description = "托盘唯一id") private String uuid = UUID.randomUUID().toString(); @@ -27,11 +36,13 @@ public class TrayState { @Schema(description = "当前托盘的工艺") private CraftsState crafts = null; - public TrayState() { + @PostConstruct + private void init(){ for (int i = 0; i < tubes.length; i++) { TubeState tubeState = new TubeState(); tubeState.setTubeNum(i + 1); tubes[i] = tubeState; } } + } diff --git a/src/main/java/com/iflytop/gd/app/model/bo/status/device/TubeState.java b/src/main/java/com/iflytop/gd/app/model/bo/status/device/TubeState.java index c8615ad..f47f554 100644 --- a/src/main/java/com/iflytop/gd/app/model/bo/status/device/TubeState.java +++ b/src/main/java/com/iflytop/gd/app/model/bo/status/device/TubeState.java @@ -9,12 +9,13 @@ public class TubeState { @Schema(description = "试管编号") private int tubeNum; + @Schema(description = "是否需要添加溶液 true需要") + private boolean addSolution = true; + @Schema(description = "是否添加过溶液 true添加过") - private boolean addSolution = false; + private boolean existSolution = false; @Schema(description = "是否存在试管 true存在") private boolean exists = true; - @Schema(description = "是否需要添加溶液 true需要") - private boolean needAddSolution = true; } diff --git a/src/main/java/com/iflytop/gd/app/model/dto/StartCraftsDTO.java b/src/main/java/com/iflytop/gd/app/model/dto/StartCraftsDTO.java index e1598ba..9866983 100644 --- a/src/main/java/com/iflytop/gd/app/model/dto/StartCraftsDTO.java +++ b/src/main/java/com/iflytop/gd/app/model/dto/StartCraftsDTO.java @@ -1,5 +1,6 @@ package com.iflytop.gd.app.model.dto; +import com.iflytop.gd.app.model.bo.status.device.TubeState; import com.iflytop.gd.common.enums.HeatModuleCode; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; @@ -16,4 +17,7 @@ public class StartCraftsDTO { @Schema(description = "加热区id,非必填,如果不传递则自动分配加热区") private HeatModuleCode heatId; + + @Schema(description = "试管") + private TubeState[] tubes; } diff --git a/src/main/java/com/iflytop/gd/app/service/api/CraftsService.java b/src/main/java/com/iflytop/gd/app/service/api/CraftsService.java index dc4ff5b..bf90a0d 100644 --- a/src/main/java/com/iflytop/gd/app/service/api/CraftsService.java +++ b/src/main/java/com/iflytop/gd/app/service/api/CraftsService.java @@ -157,6 +157,7 @@ public class CraftsService extends ServiceImpl { craftsState.setOres(ores); craftsState.setState(CraftStates.READY); craftsState.setCurrentIndex(0); + trayState.setHeatModuleId(heatModuleCode); trayState.setCrafts(craftsState); SetCraftsVO setCraftsVO = new SetCraftsVO(); diff --git a/src/main/java/com/iflytop/gd/app/service/api/TrayService.java b/src/main/java/com/iflytop/gd/app/service/api/TrayService.java index 51fb8c1..7d38649 100644 --- a/src/main/java/com/iflytop/gd/app/service/api/TrayService.java +++ b/src/main/java/com/iflytop/gd/app/service/api/TrayService.java @@ -1,10 +1,12 @@ package com.iflytop.gd.app.service.api; +import com.iflytop.gd.app.model.bo.status.device.HeatModuleState; import com.iflytop.gd.app.model.bo.status.device.TrayState; import com.iflytop.gd.app.model.vo.SetTrayTubeVO; import com.iflytop.gd.app.service.device.DeviceStateService; import com.iflytop.gd.app.service.device.module.SolutionModuleService; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.stereotype.Service; import java.util.List; @@ -17,12 +19,13 @@ import java.util.List; public class TrayService { private final DeviceStateService deviceStateService; private final SolutionModuleService solutionModuleService; + private final ObjectProvider trayStateObjectProvider; /** * 放入了新托盘 */ public synchronized TrayState trayIn() { - TrayState trayState = new TrayState(); + TrayState trayState = trayStateObjectProvider.getObject(); trayState.setInSolutionModule(true); deviceStateService.getDeviceState().getTray().add(trayState); deviceStateService.getDeviceState().getSolutionModule().setTrayStatus(1); diff --git a/src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java b/src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java index c2b41dc..f6dd6f7 100644 --- a/src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java +++ b/src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java @@ -75,6 +75,15 @@ public class CraftsStepService { && deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTrayStatus() == 1) { moveToSolutionModule(heatModuleCode); } + + JSONArray tubeNums = params.getJSONArray("tubeNums"); + for (int i = 0; i < tubeNums.size(); i++) { + JSONObject tubeSol = tubeNums.getJSONObject(i); + Integer tubeNum = tubeSol.getInt("tubeNum"); + + } + + JSONArray tubeSolList = params.getJSONArray("tubeSolList"); for (int i = 0; i < tubeSolList.size(); i++) { JSONObject tubeSol = tubeSolList.getJSONObject(i); @@ -90,9 +99,7 @@ public class CraftsStepService { } AcidPumpDeviceCode acidPumpDevice = AcidPumpDeviceCode.valueOf(container.getPumpId());//泵 int scale = container.getScale() == null ? 120 : container.getScale();//系数 - webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatModuleCode.toString(), "移动加液机械臂到指定试管", tubeNum)); solutionModuleService.dualRobotMovePoint(tubeNum);//移动加液机械臂到指定试管 - webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatModuleCode.toString(), "添加溶液", addLiquid)); CommandFuture deviceCommandFuture = solutionModuleService.acidPumpMoveBy(acidPumpDevice, volume * ((double) scale /100));//添加溶液 CommandUtil.wait(deviceCommandFuture); } @@ -131,9 +138,10 @@ public class CraftsStepService { while (deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTemperature() + 1 < temperature) { delay(1); } + deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatingType(HeatingType.constant); delay(second); heatModuleService.heatRodClose(heatModuleCode);//停止加热 - deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatingType(HeatingType.stop); + deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatingType(HeatingType.finish); heatModuleService.heaterMotorMove(heatModuleCode, trayLift);//抬升加热位托盘 return true; } diff --git a/src/main/java/com/iflytop/gd/app/service/device/module/SolutionModuleService.java b/src/main/java/com/iflytop/gd/app/service/device/module/SolutionModuleService.java index 743e86c..799fb82 100644 --- a/src/main/java/com/iflytop/gd/app/service/device/module/SolutionModuleService.java +++ b/src/main/java/com/iflytop/gd/app/service/device/module/SolutionModuleService.java @@ -85,29 +85,60 @@ public class SolutionModuleService { * 双轴械臂 移动至指定试管 */ public void dualRobotMovePoint(int index) throws Exception { - liquidDistributionArmDriver.liquidDistributionArmMoveToBlock(LiquidArmMId.LiquidDistributionArm, index); + if (!deviceStateService.getDeviceState().isVirtual()) { + liquidDistributionArmDriver.liquidDistributionArmMoveToBlock(LiquidArmMId.LiquidDistributionArm, index); + } else { + new Thread(() -> { + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + }).start(); + } } /** * 加液机械臂回原点 */ public void dualRobotOrigin() throws Exception { - liquidDistributionArmDriver.liquidDistributionArmMoveToBlock(LiquidArmMId.LiquidDistributionArm, 0); + if (!deviceStateService.getDeviceState().isVirtual()) { + liquidDistributionArmDriver.liquidDistributionArmMoveToBlock(LiquidArmMId.LiquidDistributionArm, 0); + } else { + new Thread(() -> { + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + }).start(); + } } /** * 加液机械臂回原点 */ public void dualRobotOrigin(String commandId, String command, CmdAxis cmdAxis) throws Exception { - if (cmdAxis == CmdAxis.joint1) { - DeviceCommandBundle deviceCommand = DeviceCommandGenerator.dualRobotJoint1Origin(); - CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(commandId, command, deviceCommand); - CommandUtil.wait(deviceCommandFuture); + if (!deviceStateService.getDeviceState().isVirtual()) { + if (cmdAxis == CmdAxis.joint1) { + DeviceCommandBundle deviceCommand = DeviceCommandGenerator.dualRobotJoint1Origin(); + CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(commandId, command, deviceCommand); + CommandUtil.wait(deviceCommandFuture); + } else { + DeviceCommandBundle deviceCommand = DeviceCommandGenerator.dualRobotJoint2Origin(); + CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(commandId, command, deviceCommand); + CommandUtil.wait(deviceCommandFuture); + } } else { - DeviceCommandBundle deviceCommand = DeviceCommandGenerator.dualRobotJoint2Origin(); - CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(commandId, command, deviceCommand); - CommandUtil.wait(deviceCommandFuture); + new Thread(() -> { + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + }).start(); } + } diff --git a/src/main/java/com/iflytop/gd/app/service/scheduled/FetchTemperatureScheduledTask.java b/src/main/java/com/iflytop/gd/app/service/scheduled/FetchTemperatureScheduledTask.java index da354e3..b3b632c 100644 --- a/src/main/java/com/iflytop/gd/app/service/scheduled/FetchTemperatureScheduledTask.java +++ b/src/main/java/com/iflytop/gd/app/service/scheduled/FetchTemperatureScheduledTask.java @@ -1,5 +1,6 @@ package com.iflytop.gd.app.service.scheduled; +import com.iflytop.gd.app.model.bo.status.device.HeatModuleState; import com.iflytop.gd.app.service.device.DeviceStateService; import com.iflytop.gd.common.enums.HeatModuleCode; import com.iflytop.gd.hardware.service.GDDeviceStatusService; @@ -9,6 +10,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; +import java.util.List; + @Slf4j @Service @RequiredArgsConstructor @@ -39,12 +42,14 @@ public class FetchTemperatureScheduledTask { deviceStateService.getDeviceState().getHeatModuleByCode(HeatModuleCode.heat_module_06).setTemperature(heatModule06Temperature); } else {//虚拟模式随便写个值 -// List heatModuleStateList = deviceStateService.getDeviceState().getHeatModule(); -// for (HeatModuleState heatModuleState : heatModuleStateList) { -// if (heatModuleState.isHeating()) { -// deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleState.getModuleCode()).setTemperature(123.0); -// } -// } + List heatModuleStateList = deviceStateService.getDeviceState().getHeatModule(); + for (HeatModuleState heatModuleState : heatModuleStateList) { + if (heatModuleState.isHeating()) { + heatModuleState.setTemperature(heatModuleState.getTargetTemperature()); + } else { + heatModuleState.setTemperature(26.0); + } + } } } catch (Exception e) { log.error("定时采集加热棒温度错误", e); diff --git a/src/main/java/com/iflytop/gd/app/service/scheduled/HeatCountdownScheduledTask.java b/src/main/java/com/iflytop/gd/app/service/scheduled/HeatCountdownScheduledTask.java index 8e6cc50..079f665 100644 --- a/src/main/java/com/iflytop/gd/app/service/scheduled/HeatCountdownScheduledTask.java +++ b/src/main/java/com/iflytop/gd/app/service/scheduled/HeatCountdownScheduledTask.java @@ -1,6 +1,7 @@ package com.iflytop.gd.app.service.scheduled; import com.iflytop.gd.app.model.bo.status.device.HeatModuleState; +import com.iflytop.gd.app.model.bo.status.device.TrayState; import com.iflytop.gd.app.model.vo.HeatCountdownVO; import com.iflytop.gd.app.service.api.DevicePositionService; import com.iflytop.gd.app.service.device.DeviceStateService; @@ -21,7 +22,7 @@ import java.util.ArrayList; import java.util.List; /** - * 加热倒计时 + * 加热时间到自动抬起 */ @Slf4j @Service @@ -36,8 +37,12 @@ public class HeatCountdownScheduledTask { public void fetchTemperature() { try { LocalDateTime now = LocalDateTime.now(); - List heatCountdownVOList = new ArrayList<>(); for (HeatModuleState heatModuleState : deviceStateService.getDeviceState().getHeatModule()) { + //工艺除外 + TrayState trayState = deviceStateService.getDeviceState().getTrayStateByHeatModuleCode(heatModuleState.getModuleCode()); + if (trayState != null && trayState.getCrafts() != null) { + continue; + } if (heatModuleState.getHeatingType() == HeatingType.thermostatic) {//如果这个加热模块在加热中 if (heatModuleState.getTemperature() + 1 > heatModuleState.getHeatTemperature()) {//当前温度达到目标温度,允许有1度以内的误差 heatModuleState.setStartHeatTime(now); @@ -55,34 +60,15 @@ public class HeatCountdownScheduledTask { //关闭加棒 heatModuleService.heatRodClose(heatModuleState.getModuleCode()); //还原状态 -// heatModuleState.setStartHeatTime(null); -// heatModuleState.setTargetTime(null); -// heatModuleState.setWarmUpTemperature(null); -// heatModuleState.setHeatTemperature(null); -// heatModuleState.setTargetTemperature(null); + heatModuleState.setStartHeatTime(null);//开始加热时间 + heatModuleState.setTargetTime(null);//加热器目标加热时间 + heatModuleState.setWarmUpTemperature(null);//加热器预热温度 + heatModuleState.setHeatTemperature(null);//加热器加热温度 + heatModuleState.setTargetTemperature(null);//加热器目标温度 heatModuleState.setHeatingType(HeatingType.finish); - -// HeatCountdownVO heatCountdownVO = new HeatCountdownVO(); -// heatCountdownVO.setHeatModuleCode(heatModuleState.getModuleCode()); -// heatCountdownVO.setCountdown((int) diffSeconds); -// heatCountdownVO.setCountdownStr("加热完毕"); -// heatCountdownVO.setStartTime(heatModuleState.getStartHeatTime()); -// heatCountdownVO.setEndTime(endTime); -// heatCountdownVOList.add(heatCountdownVO); - } else {//加热中 推送倒计时 -// HeatCountdownVO heatCountdownVO = new HeatCountdownVO(); -// heatCountdownVO.setHeatModuleCode(heatModuleState.getModuleCode()); -// heatCountdownVO.setCountdown((int) diffSeconds); -// heatCountdownVO.setCountdownStr(LocalDateTimeUtil.formatSecondsToHMS(diffSeconds)); -// heatCountdownVO.setStartTime(heatModuleState.getStartHeatTime()); -// heatCountdownVO.setEndTime(endTime); -// heatCountdownVOList.add(heatCountdownVO); } } } - if (!heatCountdownVOList.isEmpty()) { - webSocketSender.pushHeatCountdown(heatCountdownVOList); - } } catch (Exception e) { log.error("加热倒计时错误", e); } diff --git a/src/main/java/com/iflytop/gd/app/ws/server/WebSocketSender.java b/src/main/java/com/iflytop/gd/app/ws/server/WebSocketSender.java index 8746903..fecdb26 100644 --- a/src/main/java/com/iflytop/gd/app/ws/server/WebSocketSender.java +++ b/src/main/java/com/iflytop/gd/app/ws/server/WebSocketSender.java @@ -16,7 +16,7 @@ public class WebSocketSender { websocketResult.setType(type); websocketResult.setData(data); WebSocketServer.sendMessageToClients(JSONUtil.toJsonStr(websocketResult)); - log.info("WS::{}", JSONUtil.toJsonStr(websocketResult)); +// log.info("WS::{}", JSONUtil.toJsonStr(websocketResult)); } public void pushCraftsDebug(Object data) {