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 23935a2..c80f94f 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 @@ -1,6 +1,8 @@ package com.iflytop.gd.app.service.crafts; +import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; +import com.iflytop.gd.app.core.CraftsDebugGenerator; import com.iflytop.gd.app.model.bo.CraftsStep; import com.iflytop.gd.app.model.bo.Point3D; import com.iflytop.gd.app.service.api.ContainerService; @@ -12,8 +14,11 @@ import com.iflytop.gd.app.service.device.module.GantryModuleService; import com.iflytop.gd.app.service.device.module.HeatModuleService; import com.iflytop.gd.app.service.device.module.SolutionModuleService; import com.iflytop.gd.app.ws.server.WebSocketSender; +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.Service; @@ -59,33 +64,28 @@ public class CraftsStepService { * 将托盘从加热区移动至加液区并且添加溶液 */ private boolean addLiquid(String heatId, JSONObject params) throws Exception { -// HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatId); -// moveToSolutionModule(heatModuleCode); -// JSONArray tubeSolList = params.getJSONArray("tubeSolList"); -// for (int i = 0; i < tubeSolList.size(); i++) { -// JSONObject tubeSol = tubeSolList.getJSONObject(i); -// Integer tubeNum = tubeSol.getInt("tubeNum"); -// JSONArray addLiquidList = tubeSol.getJSONArray("addLiquidList"); -// for (int j = 0; j < addLiquidList.size(); j++) { -// JSONObject addLiquid = addLiquidList.getJSONObject(j); -// Long solId = addLiquid.getLong("solId"); -// Double volume = addLiquid.getDouble("volume"); -// AcidPumpDeviceCode acidPumpDevice = containerService.getPumpBySolutionId(solId); -// if (acidPumpDevice == null) { -// throw new AppException(ResultCode.CRAFT_CONTAINER_NOT_FOUND); -// } -// webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatId, "移动加液机械臂到指定试管", tubeNum)); -// solutionModuleService.dualRobotMovePoint(tubeNum);//移动加液机械臂到指定试管 -// webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatId, "添加溶液", addLiquid)); -// solutionModuleService.acidPumpMoveBy(acidPumpDevice, volume);//添加溶液 -// } -// } -// solutionModuleService.dualRobotOrigin(); - - log.info("{}--申请使用加液区并等待", heatId); - solutionModuleService.requestSolutionModule();//申请使用加液区并等待 - log.info("{}--申请到加液区,将托盘从加热区移动至加液区并且添加溶液", heatId); - delay(5); + HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatId); + moveToSolutionModule(heatModuleCode); + JSONArray tubeSolList = params.getJSONArray("tubeSolList"); + for (int i = 0; i < tubeSolList.size(); i++) { + JSONObject tubeSol = tubeSolList.getJSONObject(i); + Integer tubeNum = tubeSol.getInt("tubeNum"); + JSONArray addLiquidList = tubeSol.getJSONArray("addLiquidList"); + for (int j = 0; j < addLiquidList.size(); j++) { + JSONObject addLiquid = addLiquidList.getJSONObject(j); + Long solId = addLiquid.getLong("solId"); + Double volume = addLiquid.getDouble("volume"); + AcidPumpDeviceCode acidPumpDevice = containerService.getPumpBySolutionId(solId); + if (acidPumpDevice == null) { + throw new AppException(ResultCode.CRAFT_CONTAINER_NOT_FOUND); + } + webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatId, "移动加液机械臂到指定试管", tubeNum)); + solutionModuleService.dualRobotMovePoint(tubeNum);//移动加液机械臂到指定试管 + webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatId, "添加溶液", addLiquid)); + solutionModuleService.acidPumpMoveBy(acidPumpDevice, volume);//添加溶液 + } + } + solutionModuleService.dualRobotOrigin(); return true; } @@ -93,19 +93,16 @@ public class CraftsStepService { * 摇匀操作 */ private boolean shaking(String heatId, JSONObject params) throws Exception { -// HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatId); -// if(deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() == 0){ -// moveToSolutionModule(heatModuleCode); -// } -// Integer second = params.getInt("second"); -// webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatId, "开始摇匀", params)); -// solutionModuleService.shakeStart();//开始摇匀 -// delay(second); -// webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatId, "停止摇匀", null)); -// solutionModuleService.shakeStop();//停止摇匀 - - log.info("{}--摇匀", heatId); - delay(5); + HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatId); + if (deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() == 0) { + moveToSolutionModule(heatModuleCode); + } + Integer second = params.getInt("second"); + webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatId, "开始摇匀", params)); + solutionModuleService.shakeStart();//开始摇匀 + delay(second); + webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatId, "停止摇匀", null)); + solutionModuleService.shakeStop();//停止摇匀 return true; } @@ -113,20 +110,15 @@ public class CraftsStepService { * 将托盘从加液区移动至加热区并开启加热 */ private boolean heating(String heatId, JSONObject params) throws Exception { -// HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatId); -// double trayLift = devicePositionService.getPosition(DevicePositionCode.trayLift).getDistance(); //获取加热位抬升托盘位置 -// moveToHeatModule(heatModuleCode); -// Double temperature = params.getDouble("temperature"); -// Integer second = params.getInt("second"); -// heatModuleService.heatRodOpen(heatModuleCode, temperature);//开始加热 -// delay(second); -// heatModuleService.heatRodClose(heatModuleCode);//停止加热 -// heatModuleService.heaterMotorMove(heatModuleCode, trayLift);//抬升加热位托盘 - - log.info("{}--将托盘从加液区移动至加热区并开启加热", heatId); - delay(5); - solutionModuleService.releaseSolutionModule();//释放加液区 - log.info("{}--释放加液区", heatId); + HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatId); + double trayLift = devicePositionService.getPosition(DevicePositionCode.trayLift).getDistance(); //获取加热位抬升托盘位置 + moveToHeatModule(heatModuleCode); + Double temperature = params.getDouble("temperature"); + Integer second = params.getInt("second"); + heatModuleService.heatRodOpen(heatModuleCode, temperature);//开始加热 + delay(second); + heatModuleService.heatRodClose(heatModuleCode);//停止加热 + heatModuleService.heaterMotorMove(heatModuleCode, trayLift);//抬升加热位托盘 return true; } @@ -134,19 +126,16 @@ public class CraftsStepService { * 拍照操作· */ private boolean takePhoto(String heatId) throws Exception { -// HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatId); -// if(deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() == 0){ -// moveToSolutionModule(heatModuleCode); -// } -// webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatId, "开启补光灯", 100.0)); -// solutionModuleService.fillLightOpen(100.0);//TODO 开启补光灯 亮度从数据库获取 -// webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatId, "拍照", null)); -// solutionModuleService.takePhoto();//拍照 -// webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatId, "关闭补光灯", null)); -// solutionModuleService.fillLightClose();//关闭补光灯 - - log.info("{}--拍照", heatId); - delay(5); + HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatId); + if (deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() == 0) { + moveToSolutionModule(heatModuleCode); + } + webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatId, "开启补光灯", 100.0)); + solutionModuleService.fillLightOpen(100.0);//TODO 开启补光灯 亮度从数据库获取 + webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatId, "拍照", null)); + solutionModuleService.takePhoto();//拍照 + webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatId, "关闭补光灯", null)); + solutionModuleService.fillLightClose();//关闭补光灯 return true; }