白凤吉 2 months ago
parent
commit
32024bcfc0
  1. 25
      src/main/java/com/iflytop/gd/app/command/control/FilledSolutionStopCommand.java
  2. 2
      src/main/java/com/iflytop/gd/app/command/control/HeatStartCommand.java
  3. 2
      src/main/java/com/iflytop/gd/app/command/control/HeatStopCommand.java
  4. 10
      src/main/java/com/iflytop/gd/app/command/control/MoveToHeatAreaCommand.java
  5. 6
      src/main/java/com/iflytop/gd/app/command/control/MoveToSolutionAreaCommand.java
  6. 24
      src/main/java/com/iflytop/gd/app/command/control/SolutionAddCommand.java
  7. 11
      src/main/java/com/iflytop/gd/app/command/control/TrayDownCommand.java
  8. 12
      src/main/java/com/iflytop/gd/app/controller/TestController.java
  9. 16
      src/main/java/com/iflytop/gd/app/model/bo/status/device/HeatModuleState.java
  10. 7
      src/main/java/com/iflytop/gd/app/service/api/TestService.java
  11. 7
      src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java
  12. 37
      src/main/java/com/iflytop/gd/app/service/device/module/SolutionModuleService.java
  13. 16
      src/main/java/com/iflytop/gd/app/service/scheduled/FetchTemperatureScheduledTask.java
  14. 16
      src/main/java/com/iflytop/gd/common/enums/HeatingType.java
  15. 1
      src/main/java/com/iflytop/gd/common/result/ResultCode.java

25
src/main/java/com/iflytop/gd/app/command/control/FilledSolutionStopCommand.java

@ -1,5 +1,6 @@
package com.iflytop.gd.app.command.control;
import cn.hutool.json.JSONArray;
import com.iflytop.gd.app.core.BaseCommandHandler;
import com.iflytop.gd.app.model.dto.CmdDTO;
import com.iflytop.gd.app.service.api.ContainerService;
@ -26,26 +27,18 @@ public class FilledSolutionStopCommand extends BaseCommandHandler {
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
// JSONArray idJsonArray = cmdDTO.getJSONArrayParam("list");
// for (int i = 0; i < idJsonArray.size(); i++) {
// String idStr = idJsonArray.getStr(i);
// CompletableFuture.runAsync(() -> {
// try {
// AcidPumpDeviceCode acidPumpDevice = containerService.getPumpByContainerId(Long.parseLong(idStr));
// solutionModuleService.acidPumpStop(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDevice);
// } catch (Exception e) {
// log.error("停止预充失败", e);
// }
// });
// }
for (AcidPumpDeviceCode acidPumpDeviceCode : AcidPumpDeviceCode.values()) {
JSONArray idJsonArray = cmdDTO.getJSONArrayParam("list");
for (int i = 0; i < idJsonArray.size(); i++) {
String idStr = idJsonArray.getStr(i);
CompletableFuture.runAsync(() -> {
try {
solutionModuleService.acidPumpStop(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDeviceCode);
AcidPumpDeviceCode acidPumpDevice = containerService.getPumpByContainerId(Long.parseLong(idStr));
solutionModuleService.acidPumpStop(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDevice);
} catch (Exception e) {
log.error("停止预充错误", e);
log.error("停止预充失败", e);
}
});
}
Thread.sleep(1000);
solutionModuleService.dualRobotOrigin();
});
}

2
src/main/java/com/iflytop/gd/app/command/control/HeatStartCommand.java

@ -32,7 +32,7 @@ public class HeatStartCommand extends BaseCommandHandler {
double temperature = deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTemperature();
//开启加热
heatModuleService.heatRodOpen(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode, temperature);
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeating(true);
// deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeating(true);
});
}
}

2
src/main/java/com/iflytop/gd/app/command/control/HeatStopCommand.java

@ -30,7 +30,7 @@ public class HeatStopCommand extends BaseCommandHandler {
return runAsync(() -> {
//关闭加热
heatModuleService.heatRodClose(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode);
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeating(false);
// deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeating(false);
});
}
}

10
src/main/java/com/iflytop/gd/app/command/control/MoveToHeatAreaCommand.java

@ -69,10 +69,10 @@ public class MoveToHeatAreaCommand extends BaseCommandHandler {
//校验目标加热位是否有托盘
try {
deviceStateService.getCommandMutexState().get().setMoveToHeatAreaCommandExecuting(true);
Boolean heatModuleTray = heatModuleService.heatModuleSensorState(heatModuleCode);
if (heatModuleTray) {
// Boolean heatModuleTray = heatModuleService.heatModuleSensorState(heatModuleCode);
// if (heatModuleTray) {
// throw new AppException(ResultCode.TARGET_HEAT_MODULE_OCCUPIED);
}
// }
} catch (Exception e) {
deviceStateService.getCommandMutexState().get().setMoveToHeatAreaCommandExecuting(false);
throw e;
@ -109,8 +109,8 @@ public class MoveToHeatAreaCommand extends BaseCommandHandler {
gantryModuleService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
// trayState.setHeatModuleId(heatModuleId);
// trayState.setInHeatModule(true);
heatModuleService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode, trayLower);//下降加热模块托盘
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(0);//加热模块托盘升降状态
// heatModuleService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode, trayLower);//下降加热模块托盘
// deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(0);//加热模块托盘升降状态
capModuleService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand()); //提升拍子存放区
gantryModuleService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方
} finally {

6
src/main/java/com/iflytop/gd/app/command/control/MoveToSolutionAreaCommand.java

@ -72,10 +72,10 @@ public class MoveToSolutionAreaCommand extends BaseCommandHandler {
//校验目标加热位是否有托盘
try {
deviceStateService.getCommandMutexState().get().setMoveToSolutionAreaCommandExecuting(true);
Boolean heatModuleTray = heatModuleService.heatModuleSensorState(heatModuleCode);
if (!heatModuleTray) {
// Boolean heatModuleTray = heatModuleService.heatModuleSensorState(heatModuleCode);
// if (!heatModuleTray) {
// throw new AppException(ResultCode.TARGET_HEAT_MODULE_NO_TRAY);
}
// }
} catch (Exception e) {
deviceStateService.getCommandMutexState().get().setMoveToSolutionAreaCommandExecuting(false);
throw e;

24
src/main/java/com/iflytop/gd/app/command/control/SolutionAddCommand.java

@ -5,7 +5,6 @@ import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.iflytop.gd.app.core.BaseCommandHandler;
import com.iflytop.gd.app.model.dto.CmdDTO;
import com.iflytop.gd.app.model.entity.Container;
import com.iflytop.gd.app.service.api.ContainerService;
import com.iflytop.gd.app.service.device.DeviceStateService;
import com.iflytop.gd.app.service.device.module.SolutionModuleService;
@ -47,13 +46,13 @@ public class SolutionAddCommand extends BaseCommandHandler {
|| deviceStateService.getCommandMutexState().get().isShakeStartCommandExecuting()) {
throw new AppException(ResultCode.CMD_BUSY);
}
if (deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() != 1) {
if(deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() != 1){
throw new AppException(ResultCode.SOLUTION_MODULE_NO_TRAY);
}
deviceStateService.getCommandMutexState().get().setSolutionAddCommandExecuting(true);
deviceStateService.getDeviceState().getSolutionModule().setPumping(true);
return runAsync(() -> {
try {
try{
JSONArray dataList = JSONUtil.parseArray(cmdDTO.getParams().get("dataList"));
for (int i = 0; i < dataList.size(); i++) {//遍历前端传入的加液配置
JSONObject tubeSol = dataList.getJSONObject(i);
@ -67,29 +66,22 @@ public class SolutionAddCommand extends BaseCommandHandler {
List<CommandFuture> futuresList = new ArrayList<>();
for (int k = 0; k < solutionList.size(); k++) {
JSONObject addSolution = solutionList.getJSONObject(k);
Long solId = addSolution.getLong("solutionId");//实际前端传递的是容器id
Long solId = addSolution.getLong("solutionId");
Double volume = addSolution.getDouble("volume");
//AcidPumpDeviceCode acidPumpDevice = containerService.getPumpBySolutionId(solId);//获取溶液对应的泵
Container container = containerService.getById(solId);
if (container == null) {
throw new AppException(ResultCode.CONTAINER_NOT_FOUND);//未找到对应溶液容器
AcidPumpDeviceCode acidPumpDevice = containerService.getPumpBySolutionId(solId);//获取溶液对应的泵
if (acidPumpDevice == null) {
throw new AppException(ResultCode.CRAFT_CONTAINER_NOT_FOUND);//未找到对应溶液容器
}
AcidPumpDeviceCode acidPumpDevice = AcidPumpDeviceCode.valueOf(container.getPumpId());//
int scale = container.getScale() == null ? 120 : container.getScale();//系数
// Integer scale = Optional.ofNullable(container)
// .map(Container::getScale)
// .orElse(500);
CommandFuture deviceCommandFuture = solutionModuleService.acidPumpMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDevice, volume * ((double) scale /100));//添加溶液
CommandFuture deviceCommandFuture = solutionModuleService.acidPumpMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDevice, volume);//添加溶液
futuresList.add(deviceCommandFuture);
}
CommandUtil.wait(futuresList.toArray(new CommandFuture[0]));
}
}
Thread.sleep(1000);
solutionModuleService.dualRobotOrigin();
deviceStateService.getCommandMutexState().get().setSolutionAddCommandExecuting(false);
deviceStateService.getDeviceState().getSolutionModule().setPumping(false);
} finally {
}finally {
deviceStateService.getCommandMutexState().get().setSolutionAddCommandExecuting(false);
}

11
src/main/java/com/iflytop/gd/app/command/control/TrayDownCommand.java

@ -40,11 +40,22 @@ public class TrayDownCommand extends BaseCommandHandler {
HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatId);
//从数据库获取加热位下降托盘位置
double trayLower = devicePositionService.getPosition(DevicePositionCode.trayLower).getDistance();
double trayLift = devicePositionService.getPosition(DevicePositionCode.trayLift).getDistance();
return runAsync(() -> {
try {
//下降加热位托盘
heatModuleService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode, trayLower);
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(0);
if (deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getHeatingType() == HeatingType.thermostatic) {
// schedulerManager.scheduleOnce(heatModuleCode,() -> {
// try {
// heatModuleService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode, trayLift);
// deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(1);
// } catch (Exception e) {
// log.error("加热完毕抬起托盘错误{}", heatModuleCode, e);
// }
// }, deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTargetTime(), TimeUnit.SECONDS);
}
} catch (Exception e) {
log.error("降下托盘失败", e);
}

12
src/main/java/com/iflytop/gd/app/controller/TestController.java

@ -61,10 +61,12 @@ public class TestController {
return Result.success(deviceStateService.getCommandMutexState().get());
}
@Operation(summary = "获取加液区锁状态")
@GetMapping("/module-lock-try-lock")
public Result<Boolean> getModuleLockTryLock() {
return Result.success(solutionModuleService.getModuleLockTryLock());
@Operation(summary = "重置状态")
@PostMapping("/reset")
public Result<?> reset() throws Exception {
testService.reset();
return Result.success();
}
}

16
src/main/java/com/iflytop/gd/app/model/bo/status/device/HeatModuleState.java

@ -9,8 +9,6 @@ import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
@Schema(description = "加热模块")
@Data
@Component
@ -30,29 +28,17 @@ public class HeatModuleState {
@Schema(description = "当前加热类型")
private HeatingType heatingType = HeatingType.stop;
@Schema(description = "是否正在加热,true为正在加热,false为未加热")//可能去掉这个状态
private boolean heating = false;
@Schema(description = "是否启动散热,true为正在散热,false为未在散热")
private boolean fanOpen = false;
@Schema(description = "是否存在拍子,true为存在拍子,false无拍子")
private boolean capExist = false;
@Schema(description = "加热器加热温度")
private Double heatTemperature = null;
@Schema(description = "加热器预热温度")
private Double warmUpTemperature = null;
@Schema(description = "加热器目标温度")
private Double targetTemperature = null;
@Schema(description = "加热器目标加热时间,单位秒")
private Integer targetTime = null;
@Schema(description = "开始加热时间")
private LocalDateTime startHeatTime = null;
private Long targetTime = 0L;
@Schema(description = "加热器当前温度")
private Double temperature = null;

7
src/main/java/com/iflytop/gd/app/service/api/TestService.java

@ -1,6 +1,7 @@
package com.iflytop.gd.app.service.api;
import com.iflytop.gd.app.model.dto.AllSensorDTO;
import com.iflytop.gd.app.service.device.DeviceStateService;
import com.iflytop.gd.hardware.exception.HardwareException;
import com.iflytop.gd.hardware.service.GDDeviceStatusService;
import com.iflytop.gd.hardware.type.IO.InputIOMId;
@ -17,6 +18,7 @@ import java.util.List;
@RequiredArgsConstructor
public class TestService {
private final GDDeviceStatusService gdDeviceStatusService;
private final DeviceStateService deviceStateService;
public List<AllSensorDTO> getAllSensor() throws HardwareException {
List<AllSensorDTO> allSensorDTOList = new ArrayList<>();
@ -38,4 +40,9 @@ public class TestService {
return allSensorDTOList;
}
public void reset(){
deviceStateService.getCommandMutexState().get().reset();
deviceStateService.getDeviceState().reset();
}
}

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

@ -65,7 +65,12 @@ public class CraftsStepService {
*/
private boolean addLiquid(HeatModuleCode heatModuleCode, JSONObject params) throws Exception {
//TODO 判断加液区是否有托盘如果没有托盘的话判断加热区是否有托盘然后将其移动至加液区
if(deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() == 0){
if((deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() == 0 )
&& deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTrayStatus() == 0) {
throw new AppException(ResultCode.CRAFT_NO_TRAY);
}
if((deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() == 0 )
&& deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTrayStatus() == 1) {
moveToSolutionModule(heatModuleCode);
}
JSONArray tubeSolList = params.getJSONArray("tubeSolList");

37
src/main/java/com/iflytop/gd/app/service/device/module/SolutionModuleService.java

@ -20,8 +20,6 @@ import org.springframework.stereotype.Service;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* 加液模块
@ -35,7 +33,6 @@ public class SolutionModuleService {
private final LiquidDistributionArmDriver liquidDistributionArmDriver;
private final WebSocketSender webSocketService;
private final Lock moduleLock = new ReentrantLock();
private final BlockingQueue<Thread> waitingQueue = new ArrayBlockingQueue<>(1);
/**
@ -48,8 +45,9 @@ public class SolutionModuleService {
/**
* 申请使用加液模块
*/
public void requestSolutionModule(String commandId, String command) {
public synchronized void requestSolutionModule(String commandId, String command) {
try {
log.info("申请使用加液模块");
// 如果加液模块繁忙加入队列等待
while (!deviceStateService.getDeviceState().getSolutionModule().isIdle()) {
if (commandId != null && command != null) {
@ -59,7 +57,8 @@ public class SolutionModuleService {
// 把当前线程放到队列中等待
waitingQueue.put(Thread.currentThread()); // 阻塞当前线程直到被唤醒
}
occupySolutionModule();
deviceStateService.getDeviceState().getSolutionModule().setIdle(false);
log.info("加液模块申请成功");
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException("等待加液区空闲错误", e);
@ -67,18 +66,9 @@ public class SolutionModuleService {
}
/**
* 占用加液模块
*/
private void occupySolutionModule() {
moduleLock.lock();
deviceStateService.getDeviceState().getSolutionModule().setIdle(false);
}
/**
* 释放加液区
*/
public void releaseSolutionModule() throws InterruptedException {
try {
public synchronized void releaseSolutionModule() throws InterruptedException {
deviceStateService.getDeviceState().getSolutionModule().setIdle(true);
// 唤醒队列中的第一个线程
if (!waitingQueue.isEmpty()) {
@ -87,29 +77,21 @@ public class SolutionModuleService {
waitingThread.notify(); // 唤醒队列中的第一个等待线程
}
}
} finally {
if (moduleLock.tryLock()) {
moduleLock.unlock();
}
}
}
public boolean getModuleLockTryLock(){
return moduleLock.tryLock();
}
/**
* 双轴械臂 移动至指定试管
*/
public void dualRobotMovePoint(int index) throws Exception {
liquidDistributionArmDriver.liquidDistributionArmMoveTo(LiquidArmMId.LiquidDistributionArm, index);
liquidDistributionArmDriver.liquidDistributionArmMoveToBlock(LiquidArmMId.LiquidDistributionArm, index);
}
/**
* 加液机械臂回原点
*/
public void dualRobotOrigin() throws Exception {
liquidDistributionArmDriver.liquidDistributionArmMoveTo(LiquidArmMId.LiquidDistributionArm, 0);
liquidDistributionArmDriver.liquidDistributionArmMoveToBlock(LiquidArmMId.LiquidDistributionArm, 0);
}
/**
@ -210,7 +192,7 @@ public class SolutionModuleService {
/**
* 添加溶液
*/
public void acidPumpMoveBy(String commandId, String command, AcidPumpDeviceCode acidPumpDevice, double position) throws Exception {
public CommandFuture acidPumpMoveBy(String commandId, String command, AcidPumpDeviceCode acidPumpDevice, double position) throws Exception {
DeviceCommandBundle deviceCommand;
switch (acidPumpDevice) {
case acid_pump_01 -> {
@ -239,8 +221,7 @@ public class SolutionModuleService {
}
default -> throw new RuntimeException("index 未找到");
}
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(commandId, command, deviceCommand);
CommandUtil.wait(deviceCommandFuture);
return deviceCommandService.sendCommand(commandId, command, deviceCommand);
}
/**

16
src/main/java/com/iflytop/gd/app/service/scheduled/FetchTemperatureScheduledTask.java

@ -19,7 +19,7 @@ public class FetchTemperatureScheduledTask {
private final GDDeviceStatusService gdDeviceStatusService;
private final DeviceStateService deviceStateService;
@Scheduled(fixedRate = 10000)
@Scheduled(fixedRate = 30000)
public void fetchTemperature() {
try {
if (!deviceStateService.getDeviceState().isVirtual()) {
@ -42,14 +42,12 @@ public class FetchTemperatureScheduledTask {
deviceStateService.getDeviceState().getHeatModuleByCode(HeatModuleCode.heat_module_06).setTemperature(heatModule06Temperature);
} else {//虚拟模式随便写个值
List<HeatModuleState> heatModuleStateList = deviceStateService.getDeviceState().getHeatModule();
for (HeatModuleState heatModuleState : heatModuleStateList) {
if (heatModuleState.isHeating()) {
heatModuleState.setTemperature(heatModuleState.getTargetTemperature());
} else {
heatModuleState.setTemperature(26.0);
}
}
// List<HeatModuleState> heatModuleStateList = deviceStateService.getDeviceState().getHeatModule();
// for (HeatModuleState heatModuleState : heatModuleStateList) {
// if (heatModuleState.isHeating()) {
// deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleState.getModuleCode()).setTemperature(123.0);
// }
// }
}
} catch (Exception e) {
log.error("定时采集加热棒温度错误", e);

16
src/main/java/com/iflytop/gd/common/enums/HeatingType.java

@ -8,20 +8,6 @@ import lombok.Getter;
@Getter
public enum HeatingType {
stop,
/**
* 预热中
*/
warm_up,
/**
* 加热中
*/
preheating,
thermostatic,
/**
* 恒温中
*/
constant,
/**
* 加热完成
*/
finish,
}

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

@ -40,6 +40,7 @@ public enum ResultCode implements IResultCode, Serializable {
CRAFT_RUNNING("4101", "工艺正在执行"),
CRAFT_CONTEXT_NULL("4102", "请先配置该加热区工艺"),
CRAFT_CONTAINER_NOT_FOUND("4005", "工艺未找到对应溶液容器"),
CRAFT_NO_TRAY("4005", "工艺未找到托盘"),
//============================ 5xxx系统 & 第三方 ============================
SYSTEM_ERROR("5000", "系统内部错误"),
SERVICE_UNAVAILABLE("5001", "服务暂不可用"),

Loading…
Cancel
Save