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 84ad317..23935a2 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,11 +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.model.bo.status.device.TrayState; import com.iflytop.gd.app.service.api.ContainerService; import com.iflytop.gd.app.service.api.DevicePositionService; import com.iflytop.gd.app.service.device.DeviceCommandTempUtilService; @@ -15,17 +12,16 @@ 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; /** * 工艺步骤执行服务 */ +@Slf4j @Service @RequiredArgsConstructor public class CraftsStepService { @@ -63,28 +59,33 @@ 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(); +// 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); return true; } @@ -92,16 +93,19 @@ 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();//停止摇匀 +// 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); return true; } @@ -109,15 +113,20 @@ 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);//抬升加热位托盘 +// 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); return true; } @@ -125,16 +134,19 @@ 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();//关闭补光灯 +// 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); return true; } @@ -171,42 +183,43 @@ public class CraftsStepService { Point3D heatAreaCapClawPointPoint3D = heatModuleService.getHeatAreaCapClawPointPoint3D(heatModuleCode);//获取指定加热模块拍子上方点位 Point3D capStorageCapClawPoint3D = devicePositionService.getPosition(DevicePositionCode.capStorageCapClawPoint).getPoint3D();//获取拍子存放区上方点位; - gantryModuleService.gantryMove( liquidAreaTrayPoint3D); //将机械臂移动至加液模块上方 - gantryModuleService.clawMove( clawTrayPick);//将夹爪打开,准备夹取托盘 + gantryModuleService.gantryMove(liquidAreaTrayPoint3D); //将机械臂移动至加液模块上方 + gantryModuleService.clawMove(clawTrayPick);//将夹爪打开,准备夹取托盘 gantryModuleService.gantryZMove(solutionModuleTrayMoveHeight);//下降z轴,使夹爪落入托盘孔位 - gantryModuleService.clawMove( clawTrayGrip);//将夹爪收紧,夹住托盘 - gantryModuleService.gantryZMove( 0);//抬升z轴 + gantryModuleService.clawMove(clawTrayGrip);//将夹爪收紧,夹住托盘 + gantryModuleService.gantryZMove(0);//抬升z轴 deviceStateService.getDeviceState().getSolutionModule().setTrayStatus(0);//加液模块是否有托盘 - deviceCommandTempUtilService.moveTrayHeatModuleAvoidDown( null);//TODO 结构有问题临时避让 开始,移动托盘之前先降下所有加热模块 - gantryModuleService.gantryMove( heatArea4TrayClawPoint3D);//将携带托盘的机械臂移动至4号加热模块上方 - gantryModuleService.gantryMove( heatAreaTrayClawPoint3D);//将携带托盘的机械臂移动至加热模块上方 + deviceCommandTempUtilService.moveTrayHeatModuleAvoidDown(null);//TODO 结构有问题临时避让 开始,移动托盘之前先降下所有加热模块 + gantryModuleService.gantryMove(heatArea4TrayClawPoint3D);//将携带托盘的机械臂移动至4号加热模块上方 + gantryModuleService.gantryMove(heatAreaTrayClawPoint3D);//将携带托盘的机械臂移动至加热模块上方 // deviceCommandUtilService.heaterMotorMove( heatModuleId, trayLift);//抬升加热位托盘 TODO 结构有问题临时避让 屏蔽 - deviceCommandTempUtilService.moveTrayHeatModuleAvoidUp( heatModuleCode);//TODO 结构有问题临时避让 完毕,可以升起了,顺带提升目标加热模块 + deviceCommandTempUtilService.moveTrayHeatModuleAvoidUp(heatModuleCode);//TODO 结构有问题临时避让 完毕,可以升起了,顺带提升目标加热模块 gantryModuleService.gantryZMove(heatModuleTrayMoveHeight);//下降z轴,使托盘落入加热模块 - gantryModuleService.clawMove( clawTrayPick);//将夹爪打开,释放托盘 + gantryModuleService.clawMove(clawTrayPick);//将夹爪打开,释放托盘 deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayStatus(1);//加热模块是否存在托盘 - gantryModuleService.gantryZMove( 0);//抬升z轴 + gantryModuleService.gantryZMove(0);//抬升z轴 capModuleService.capUpBalance();//提升拍子存放区至拍子夹取的高度 - gantryModuleService.gantryMove( capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方 - gantryModuleService.clawMove( clawCapPick);//将夹爪打开,准备夹取拍子 + gantryModuleService.gantryMove(capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方 + gantryModuleService.clawMove(clawCapPick);//将夹爪打开,准备夹取拍子 gantryModuleService.gantryZMove(capModuleCapMoveHeight);//下降z轴,使夹爪落入拍子升降模块拍子孔位 - gantryModuleService.clawMove( clawCapGrip);//将夹爪收紧,夹住拍子 - gantryModuleService.gantryZMove( 0);//抬升z轴 - gantryModuleService.gantryMove( heatAreaCapClawPointPoint3D);//将携带拍子的机械臂移动至加热模块拍子上方 + gantryModuleService.clawMove(clawCapGrip);//将夹爪收紧,夹住拍子 + gantryModuleService.gantryZMove(0);//抬升z轴 + gantryModuleService.gantryMove(heatAreaCapClawPointPoint3D);//将携带拍子的机械臂移动至加热模块拍子上方 gantryModuleService.gantryZMove(heatModuleCapMoveHeight);//下降z轴,使夹拍子落入加热模块 - gantryModuleService.clawMove( clawCapPick);//将夹爪打开,释放拍子 + gantryModuleService.clawMove(clawCapPick);//将夹爪打开,释放拍子 deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setCapExist(true);//加热模块是否存在拍子 - gantryModuleService.gantryZMove( 0);//抬升z轴 + gantryModuleService.gantryZMove(0);//抬升z轴 // trayState.setHeatModuleId(heatModuleId); // trayState.setInHeatModule(true); - heatModuleService.heaterMotorMove( heatModuleCode, trayLower);//下降加热模块托盘 + heatModuleService.heaterMotorMove(heatModuleCode, trayLower);//下降加热模块托盘 deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(0);//加热模块托盘升降状态 capModuleService.capUpBalance(); //提升拍子存放区 - gantryModuleService.gantryMove( capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方 + gantryModuleService.gantryMove(capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方 heatModuleService.heaterMotorMove(heatModuleCode, trayLower);//下降加热位托盘 deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayStatus(1); + solutionModuleService.releaseSolutionModule();//释放加液区 } /** 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 497f90b..b776779 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 @@ -49,7 +49,6 @@ public class SolutionModuleService { * 申请使用加液模块 */ public void requestSolutionModule(String commandId, String command) { - moduleLock.lock(); try { // 如果加液模块繁忙,加入队列等待 while (!deviceStateService.getDeviceState().getSolutionModule().isIdle()) { @@ -64,8 +63,6 @@ public class SolutionModuleService { } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException("等待加液区空闲错误", e); - } finally { - moduleLock.unlock(); } } @@ -74,18 +71,13 @@ public class SolutionModuleService { */ private void occupySolutionModule() { moduleLock.lock(); - try { - deviceStateService.getDeviceState().getSolutionModule().setIdle(false); - } finally { - moduleLock.unlock(); - } + deviceStateService.getDeviceState().getSolutionModule().setIdle(false); } /** * 释放加液区 */ public void releaseSolutionModule() throws InterruptedException { - moduleLock.lock(); try { deviceStateService.getDeviceState().getSolutionModule().setIdle(true); // 唤醒队列中的第一个线程