Browse Source

修复加液区锁错误

master
白凤吉 2 months ago
parent
commit
b377cd02dd
  1. 127
      src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java
  2. 8
      src/main/java/com/iflytop/gd/app/service/device/module/SolutionModuleService.java

127
src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java

@ -1,11 +1,8 @@
package com.iflytop.gd.app.service.crafts; package com.iflytop.gd.app.service.crafts;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject; 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.CraftsStep;
import com.iflytop.gd.app.model.bo.Point3D; 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.ContainerService;
import com.iflytop.gd.app.service.api.DevicePositionService; import com.iflytop.gd.app.service.api.DevicePositionService;
import com.iflytop.gd.app.service.device.DeviceCommandTempUtilService; 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.HeatModuleService;
import com.iflytop.gd.app.service.device.module.SolutionModuleService; import com.iflytop.gd.app.service.device.module.SolutionModuleService;
import com.iflytop.gd.app.ws.server.WebSocketSender; 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.HeatModuleCode;
import com.iflytop.gd.common.enums.data.DevicePositionCode; 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.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
* 工艺步骤执行服务 * 工艺步骤执行服务
*/ */
@Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class CraftsStepService { public class CraftsStepService {
@ -63,28 +59,33 @@ public class CraftsStepService {
* 将托盘从加热区移动至加液区并且添加溶液 * 将托盘从加热区移动至加液区并且添加溶液
*/ */
private boolean addLiquid(String heatId, JSONObject params) throws Exception { 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; return true;
} }
@ -92,16 +93,19 @@ public class CraftsStepService {
* 摇匀操作 * 摇匀操作
*/ */
private boolean shaking(String heatId, JSONObject params) throws Exception { 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; return true;
} }
@ -109,15 +113,20 @@ public class CraftsStepService {
* 将托盘从加液区移动至加热区并开启加热 * 将托盘从加液区移动至加热区并开启加热
*/ */
private boolean heating(String heatId, JSONObject params) throws Exception { 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; return true;
} }
@ -125,16 +134,19 @@ public class CraftsStepService {
* 拍照操作· * 拍照操作·
*/ */
private boolean takePhoto(String heatId) throws Exception { 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; return true;
} }
@ -207,6 +219,7 @@ public class CraftsStepService {
heatModuleService.heaterMotorMove(heatModuleCode, trayLower);//下降加热位托盘 heatModuleService.heaterMotorMove(heatModuleCode, trayLower);//下降加热位托盘
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayStatus(1); deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayStatus(1);
solutionModuleService.releaseSolutionModule();//释放加液区
} }
/** /**

8
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) { public void requestSolutionModule(String commandId, String command) {
moduleLock.lock();
try { try {
// 如果加液模块繁忙加入队列等待 // 如果加液模块繁忙加入队列等待
while (!deviceStateService.getDeviceState().getSolutionModule().isIdle()) { while (!deviceStateService.getDeviceState().getSolutionModule().isIdle()) {
@ -64,8 +63,6 @@ public class SolutionModuleService {
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
throw new RuntimeException("等待加液区空闲错误", e); throw new RuntimeException("等待加液区空闲错误", e);
} finally {
moduleLock.unlock();
} }
} }
@ -74,18 +71,13 @@ public class SolutionModuleService {
*/ */
private void occupySolutionModule() { private void occupySolutionModule() {
moduleLock.lock(); moduleLock.lock();
try {
deviceStateService.getDeviceState().getSolutionModule().setIdle(false); deviceStateService.getDeviceState().getSolutionModule().setIdle(false);
} finally {
moduleLock.unlock();
}
} }
/** /**
* 释放加液区 * 释放加液区
*/ */
public void releaseSolutionModule() throws InterruptedException { public void releaseSolutionModule() throws InterruptedException {
moduleLock.lock();
try { try {
deviceStateService.getDeviceState().getSolutionModule().setIdle(true); deviceStateService.getDeviceState().getSolutionModule().setIdle(true);
// 唤醒队列中的第一个线程 // 唤醒队列中的第一个线程

Loading…
Cancel
Save