From a418c3d32469d8713fcd289255e0a8d1da5976d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=A2=A6=E8=BF=9C?= <1063331231@qq.com> Date: Fri, 25 Jul 2025 14:40:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E5=8A=A8=E4=B8=9A=E5=8A=A1=E6=8C=87?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/cache/DevicePositionData.java | 13 + .../command/control/heat/HeatRodCloseCommand.java | 39 +++ .../command/control/heat/HeatRodOpenCommand.java | 40 +++ .../pipeline/PipelineCleanStartCommand.java | 42 +++ .../control/pipeline/PipelineCleanStopCommand.java | 40 +++ .../pipeline/PipelineDrainStartCommand.java | 41 +++ .../control/pipeline/PipelineDrainStopCommand.java | 40 +++ .../pipeline/PipelinePreFillStartCommand.java | 41 +++ .../pipeline/PipelinePreFillStopCommand.java | 40 +++ .../pipeline/WastePoolDrainStartCommand.java | 29 ++ .../pipeline/WastePoolDrainStopCommand.java | 29 ++ .../control/solution/ShakeStartCommand.java | 41 +++ .../command/control/solution/ShakeStopCommand.java | 39 +++ .../control/solution/SolutionAddCommand.java | 48 +++ .../control/solution/SolutionStopCommand.java | 40 +++ .../transfer/HeatAreaMoveTitrationAreaCommand.java | 75 +++++ .../transfer/TitrationAreaMoveHeatAreaCommand.java | 75 +++++ .../transfer/TitrationMoveTrayAreaCommand.java | 70 +++++ .../transfer/TrayMoveTitrationAreaCommand.java | 76 +++++ .../app/common/enums/DevicePositionCode.java | 72 +++++ .../app/common/enums/DevicePositionType.java | 35 +++ .../app/service/DeviceInitService.java | 1 + .../app/service/module/HeatModuleService.java | 25 ++ .../app/service/module/TitrationModuleService.java | 348 +++++++++++++++++++++ .../app/service/module/TransferModuleService.java | 151 +++++++++ .../common/model/entity/Position.java | 28 ++ .../colortitration/common/result/ResultCode.java | 17 +- .../common/service/PositionService.java | 10 +- 28 files changed, 1535 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/iflytop/colortitration/app/cache/DevicePositionData.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/heat/HeatRodCloseCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/heat/HeatRodOpenCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelineCleanStartCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelineCleanStopCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelineDrainStartCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelineDrainStopCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelinePreFillStartCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelinePreFillStopCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/pipeline/WastePoolDrainStartCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/pipeline/WastePoolDrainStopCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/solution/ShakeStartCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/solution/ShakeStopCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/solution/SolutionAddCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/solution/SolutionStopCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/transfer/HeatAreaMoveTitrationAreaCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/transfer/TitrationAreaMoveHeatAreaCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/transfer/TitrationMoveTrayAreaCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/command/control/transfer/TrayMoveTitrationAreaCommand.java create mode 100644 src/main/java/com/iflytop/colortitration/app/common/enums/DevicePositionCode.java create mode 100644 src/main/java/com/iflytop/colortitration/app/common/enums/DevicePositionType.java diff --git a/src/main/java/com/iflytop/colortitration/app/cache/DevicePositionData.java b/src/main/java/com/iflytop/colortitration/app/cache/DevicePositionData.java new file mode 100644 index 0000000..80aae44 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/cache/DevicePositionData.java @@ -0,0 +1,13 @@ +package com.iflytop.colortitration.app.cache; + + +public class DevicePositionData { + + public static final String HEAT_AREA_1 = ""; + public static final String HEAT_AREA_2 = "HEAT_AREA_2"; + + public static final String TITRATION_AREA_1 = "TITRATION_AREA_1"; // + public static final String TITRATION_AREA_2 = "TITRATION_AREA_2"; + + +} diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/heat/HeatRodCloseCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/heat/HeatRodCloseCommand.java new file mode 100644 index 0000000..8ac884a --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/heat/HeatRodCloseCommand.java @@ -0,0 +1,39 @@ +package com.iflytop.colortitration.app.command.control.heat; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.HeatModuleService; +import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.result.ResultCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 关闭加热棒 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("heater_stop") +public class HeatRodCloseCommand extends BaseCommandHandler { + private final HeatModuleService heatModuleService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + String heatModuleCodeStr = commandDTO.getStringParam("heatModuleCode"); + if (StringUtils.isEmpty(heatModuleCodeStr)) { + throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失 + } + MultipleModuleCode heatModuleCode = MultipleModuleCode.valueOf(heatModuleCodeStr); + return runAsync(() -> { + heatModuleService.closeHeatRod(heatModuleCode); + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/heat/HeatRodOpenCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/heat/HeatRodOpenCommand.java new file mode 100644 index 0000000..c98864a --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/heat/HeatRodOpenCommand.java @@ -0,0 +1,40 @@ +package com.iflytop.colortitration.app.command.control.heat; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.HeatModuleService; +import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.result.ResultCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 开启加热棒 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("heater_start") +public class HeatRodOpenCommand extends BaseCommandHandler { + private final HeatModuleService heatModuleService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + String heatModuleCodeStr = commandDTO.getStringParam("heatModuleCode"); + Double temperature = commandDTO.getDoubleParam("temperature"); + if (StringUtils.isEmpty(heatModuleCodeStr) || temperature == null) { + throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失 + } + MultipleModuleCode heatModuleCode = MultipleModuleCode.valueOf(heatModuleCodeStr); + return runAsync(() -> { + heatModuleService.openHeatRod(heatModuleCode, temperature); + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelineCleanStartCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelineCleanStartCommand.java new file mode 100644 index 0000000..bf6b62f --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelineCleanStartCommand.java @@ -0,0 +1,42 @@ +package com.iflytop.colortitration.app.command.control.pipeline; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.result.ResultCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 开始清洗管路 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("solution_clean_start") +public class PipelineCleanStartCommand extends BaseCommandHandler { + private final TitrationModuleService titrationModuleService; + + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + Integer solutionId = commandDTO.getIntegerParam("solutionId"); + String titrationModuleCodeStr = commandDTO.getStringParam("titrationModuleCode"); + if (StringUtils.isEmpty(titrationModuleCodeStr) || solutionId == null) { + throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失 + } + MultipleModuleCode titrationModuleCode = MultipleModuleCode.valueOf(titrationModuleCodeStr); + return runAsync(() -> { + titrationModuleService.titrationMotorMoveToWastePool(titrationModuleCode);//移动到废液池 + titrationModuleService.cleanStart(titrationModuleCode, solutionId);//开始清洗 + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelineCleanStopCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelineCleanStopCommand.java new file mode 100644 index 0000000..f178c26 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelineCleanStopCommand.java @@ -0,0 +1,40 @@ +package com.iflytop.colortitration.app.command.control.pipeline; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.result.ResultCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 停止清洗管路 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("solution_clean_stop") +public class PipelineCleanStopCommand extends BaseCommandHandler { + private final TitrationModuleService titrationModuleService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + Integer solutionId = commandDTO.getIntegerParam("solutionId"); + String titrationModuleCodeStr = commandDTO.getStringParam("titrationModuleCode"); + if (StringUtils.isEmpty(titrationModuleCodeStr) || solutionId == null) { + throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失 + } + MultipleModuleCode titrationModuleCode = MultipleModuleCode.valueOf(titrationModuleCodeStr); + return runAsync(() -> { + titrationModuleService.cleanStop(titrationModuleCode, solutionId); + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelineDrainStartCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelineDrainStartCommand.java new file mode 100644 index 0000000..8ae5da7 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelineDrainStartCommand.java @@ -0,0 +1,41 @@ +package com.iflytop.colortitration.app.command.control.pipeline; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.result.ResultCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 开始排空管路 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("solution_drain_start") +public class PipelineDrainStartCommand extends BaseCommandHandler { + private final TitrationModuleService titrationModuleService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + Integer solutionId = commandDTO.getIntegerParam("solutionId"); + String titrationModuleCodeStr = commandDTO.getStringParam("titrationModuleCode"); + if (StringUtils.isEmpty(titrationModuleCodeStr) || solutionId == null) { + throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失 + } + MultipleModuleCode titrationModuleCode = MultipleModuleCode.valueOf(titrationModuleCodeStr); + return runAsync(() -> { + titrationModuleService.titrationMotorMoveToWastePool(titrationModuleCode);//移动到废液池 + titrationModuleService.drainStart(titrationModuleCode, solutionId);//开始排空 + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelineDrainStopCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelineDrainStopCommand.java new file mode 100644 index 0000000..74d7dda --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelineDrainStopCommand.java @@ -0,0 +1,40 @@ +package com.iflytop.colortitration.app.command.control.pipeline; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.result.ResultCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 停止排空管路 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("solution_drain_stop") +public class PipelineDrainStopCommand extends BaseCommandHandler { + private final TitrationModuleService titrationModuleService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + Integer solutionId = commandDTO.getIntegerParam("solutionId"); + String motorCode = commandDTO.getStringParam("titrationModuleCode"); + if (StringUtils.isEmpty(motorCode) || solutionId == null) { + throw new AppException(ResultCode.INVALID_PARAMETER); + } + MultipleModuleCode titrationModuleCode = MultipleModuleCode.valueOf(motorCode); + return runAsync(() -> { + titrationModuleService.drainStop(titrationModuleCode, solutionId); + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelinePreFillStartCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelinePreFillStartCommand.java new file mode 100644 index 0000000..ca0e79d --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelinePreFillStartCommand.java @@ -0,0 +1,41 @@ +package com.iflytop.colortitration.app.command.control.pipeline; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.result.ResultCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 开始预充管路 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("solution_pre_fill_start") +public class PipelinePreFillStartCommand extends BaseCommandHandler { + private final TitrationModuleService titrationModuleService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + Integer solutionId = commandDTO.getIntegerParam("solutionId"); + String titrationModuleCodeStr = commandDTO.getStringParam("titrationModuleCode"); + if (StringUtils.isEmpty(titrationModuleCodeStr) || solutionId == null) { + throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失 + } + MultipleModuleCode titrationModuleCode = MultipleModuleCode.valueOf(titrationModuleCodeStr); + return runAsync(() -> { + titrationModuleService.titrationMotorMoveToWastePool(titrationModuleCode);//移动到废液池 + titrationModuleService.preFillStart(titrationModuleCode, solutionId);//开始预充 + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelinePreFillStopCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelinePreFillStopCommand.java new file mode 100644 index 0000000..ce6c064 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/PipelinePreFillStopCommand.java @@ -0,0 +1,40 @@ +package com.iflytop.colortitration.app.command.control.pipeline; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.result.ResultCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 停止预充管窥 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("solution_pre_fill_stop") +public class PipelinePreFillStopCommand extends BaseCommandHandler { + private final TitrationModuleService titrationModuleService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + Integer solutionId = commandDTO.getIntegerParam("solutionId"); + String titrationModuleCodeStr = commandDTO.getStringParam("titrationModuleCode"); + if (StringUtils.isEmpty(titrationModuleCodeStr) || solutionId == null) { + throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失 + } + MultipleModuleCode titrationModuleCode = MultipleModuleCode.valueOf(titrationModuleCodeStr); + return runAsync(() -> { + titrationModuleService.preFillStop(titrationModuleCode, solutionId); + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/WastePoolDrainStartCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/WastePoolDrainStartCommand.java new file mode 100644 index 0000000..cb199d6 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/WastePoolDrainStartCommand.java @@ -0,0 +1,29 @@ +package com.iflytop.colortitration.app.command.control.pipeline; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 开始抽废液 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("solution_waste_drain_start") +public class WastePoolDrainStartCommand extends BaseCommandHandler { + private final TitrationModuleService titrationModuleService; + + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + return runAsync(titrationModuleService::drainWasteStart); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/WastePoolDrainStopCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/WastePoolDrainStopCommand.java new file mode 100644 index 0000000..d93cb31 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/pipeline/WastePoolDrainStopCommand.java @@ -0,0 +1,29 @@ +package com.iflytop.colortitration.app.command.control.pipeline; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 停止抽废液 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("solution_waste_drain_stop") +public class WastePoolDrainStopCommand extends BaseCommandHandler { + private final TitrationModuleService titrationModuleService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + + return runAsync(titrationModuleService::drainWasteStop); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/solution/ShakeStartCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/solution/ShakeStartCommand.java new file mode 100644 index 0000000..8d5039f --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/solution/ShakeStartCommand.java @@ -0,0 +1,41 @@ +package com.iflytop.colortitration.app.command.control.solution; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.result.ResultCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 开始摇匀溶液 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("shake_start") +public class ShakeStartCommand extends BaseCommandHandler { + private final TitrationModuleService titrationModuleService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + String motorCode = commandDTO.getStringParam("titrationModuleCode"); + Double speed = commandDTO.getDoubleParam("speed"); + Integer time = commandDTO.getIntegerParam("time"); + if (StringUtils.isEmpty(motorCode)) { + throw new AppException(ResultCode.INVALID_PARAMETER); + } + MultipleModuleCode titrationModuleCode = MultipleModuleCode.valueOf(motorCode); + return runAsync(() -> { + titrationModuleService.shakeStart(titrationModuleCode, speed, time); + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/solution/ShakeStopCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/solution/ShakeStopCommand.java new file mode 100644 index 0000000..85c423b --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/solution/ShakeStopCommand.java @@ -0,0 +1,39 @@ +package com.iflytop.colortitration.app.command.control.solution; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.result.ResultCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 停止摇匀加液 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("shake_stop") +public class ShakeStopCommand extends BaseCommandHandler { + private final TitrationModuleService titrationModuleService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + String motorCode = commandDTO.getStringParam("titrationModuleCode"); + if (StringUtils.isEmpty(motorCode)) { + throw new AppException(ResultCode.INVALID_PARAMETER); + } + MultipleModuleCode titrationModuleCode = MultipleModuleCode.valueOf(motorCode); + return runAsync(() -> { + titrationModuleService.shakeStop(titrationModuleCode); + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/solution/SolutionAddCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/solution/SolutionAddCommand.java new file mode 100644 index 0000000..178876c --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/solution/SolutionAddCommand.java @@ -0,0 +1,48 @@ +package com.iflytop.colortitration.app.command.control.solution; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.result.ResultCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 开始加液 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("solution_add_start") +public class SolutionAddCommand extends BaseCommandHandler { + private final TitrationModuleService titrationModuleService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + String moduleCodeStr = commandDTO.getStringParam("titrationModuleCode"); + Integer solutionId = commandDTO.getIntegerParam("solutionId"); + Double volume = commandDTO.getDoubleParam("volume"); + String type = commandDTO.getStringParam("type"); + if (type.equals("drop")) { + volume = 0.5; + } + if (StringUtils.isEmpty(moduleCodeStr) || solutionId == null || StringUtils.isEmpty(type)) { + throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失 + } + MultipleModuleCode titrationModuleCode = MultipleModuleCode.valueOf(moduleCodeStr); + Double finalVolume = volume; + return runAsync(() -> { + //移动滴定电机到滴定位 + titrationModuleService.titrationMotorMoveToSolution(titrationModuleCode); + titrationModuleService.addSolutionStart(titrationModuleCode, solutionId, finalVolume); + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/solution/SolutionStopCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/solution/SolutionStopCommand.java new file mode 100644 index 0000000..f809265 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/solution/SolutionStopCommand.java @@ -0,0 +1,40 @@ +package com.iflytop.colortitration.app.command.control.solution; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.result.ResultCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 结束加液 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("solution_add_stop") +public class SolutionStopCommand extends BaseCommandHandler { + private final TitrationModuleService titrationModuleService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + String moduleCodeStr = commandDTO.getStringParam("titrationModuleCode"); + Integer solutionId = commandDTO.getIntegerParam("solutionId"); + if (StringUtils.isEmpty(moduleCodeStr) || solutionId == null) { + throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失 + } + MultipleModuleCode titrationModuleCode = MultipleModuleCode.valueOf(moduleCodeStr); + return runAsync(() -> { + titrationModuleService.addSolutionStop(titrationModuleCode, solutionId); + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/transfer/HeatAreaMoveTitrationAreaCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/transfer/HeatAreaMoveTitrationAreaCommand.java new file mode 100644 index 0000000..6408a33 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/transfer/HeatAreaMoveTitrationAreaCommand.java @@ -0,0 +1,75 @@ +package com.iflytop.colortitration.app.command.control.transfer; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.core.state.DeviceState; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import com.iflytop.colortitration.app.service.module.TransferModuleService; +import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.result.ResultCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 加热区转移至滴定区 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("heat_move_to_titration_area") +public class HeatAreaMoveTitrationAreaCommand extends BaseCommandHandler { + private final DeviceState deviceState; + private final TransferModuleService transferModuleService; + private final TitrationModuleService titrationModuleService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + String heatModuleCodeStr = commandDTO.getStringParam("heatModuleCode"); + String titrationModuleCodeStr = commandDTO.getStringParam("titrationModuleCode"); + if (StringUtils.isEmpty(heatModuleCodeStr) || StringUtils.isEmpty(titrationModuleCodeStr)) { + throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失 + } + MultipleModuleCode titrationModuleCode = MultipleModuleCode.valueOf(titrationModuleCodeStr); + MultipleModuleCode heatModuleCode = MultipleModuleCode.valueOf(heatModuleCodeStr); + boolean tubeExist = switch (titrationModuleCode) { //首先滴定位是否存在试管 + case MultipleModuleCode.MODULE_1 -> deviceState.isTrayExist1(); + case MultipleModuleCode.MODULE_2 -> deviceState.isTrayExist2(); + }; + if (!tubeExist) throw new AppException(ResultCode.TARGET_MODULE_NO_TUBE);//目标模块无试管 + boolean heatTubeExist = switch (heatModuleCode) { //加热位是否存在试管 + case MultipleModuleCode.MODULE_1 -> + deviceState.getHeatModuleStateMap().get(MultipleModuleCode.MODULE_1).isBubeExist(); + case MultipleModuleCode.MODULE_2 -> + deviceState.getHeatModuleStateMap().get(MultipleModuleCode.MODULE_2).isBubeExist(); + }; + if (heatTubeExist) throw new AppException(ResultCode.TARGET_MODULE_OCCUPIED);//目标模块被占用 + //3、判断夹爪是否夹取了试管 todo + return runAsync(() -> { + //滴定电机回原点 + titrationModuleService.titrationMotorOrigin(titrationModuleCode); + //移动到需要移动的试管为止,z轴先抬升,再移动到试管上方 + transferModuleService.roboticMoveToHeat(heatModuleCode); + //打开夹爪 + transferModuleService.clawOpen(); + //z轴下降 + transferModuleService.zMoveDownWithHeatArea(); + //关闭夹爪 + transferModuleService.clawClose(); + //1移动到滴定位上方 + transferModuleService.roboticMoveToTitration(titrationModuleCode); + //z轴下降 + transferModuleService.zMoveDownWithTitrationArea(); + //打开夹爪 + transferModuleService.clawOpen(); + //机械臂回到原点 + transferModuleService.roboticMoveToOrigin(); + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/transfer/TitrationAreaMoveHeatAreaCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/transfer/TitrationAreaMoveHeatAreaCommand.java new file mode 100644 index 0000000..d1879d4 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/transfer/TitrationAreaMoveHeatAreaCommand.java @@ -0,0 +1,75 @@ +package com.iflytop.colortitration.app.command.control.transfer; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.core.state.DeviceState; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import com.iflytop.colortitration.app.service.module.TransferModuleService; +import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.result.ResultCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 滴定区转移至加热区 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("titration_move_to_heat_area") +public class TitrationAreaMoveHeatAreaCommand extends BaseCommandHandler { + private final DeviceState deviceState; + private final TransferModuleService transferModuleService; + private final TitrationModuleService titrationModuleService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + String heatModuleCodeStr = commandDTO.getStringParam("heatModuleCode"); + String titrationModuleCodeStr = commandDTO.getStringParam("titrationModuleCode"); + if (StringUtils.isEmpty(heatModuleCodeStr) || StringUtils.isEmpty(titrationModuleCodeStr)) { + throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失 + } + MultipleModuleCode titrationModuleCode = MultipleModuleCode.valueOf(titrationModuleCodeStr); + MultipleModuleCode heatModuleCode = MultipleModuleCode.valueOf(heatModuleCodeStr); + boolean tubeExist = switch (titrationModuleCode) { //首先滴定位是否存在试管 + case MultipleModuleCode.MODULE_1 -> deviceState.isTrayExist1(); + case MultipleModuleCode.MODULE_2 -> deviceState.isTrayExist2(); + }; + if (!tubeExist) throw new AppException(ResultCode.TARGET_MODULE_NO_TUBE);//目标模块无试管 + boolean heatTubeExist = switch (heatModuleCode) { //加热位是否存在试管 + case MultipleModuleCode.MODULE_1 -> + deviceState.getHeatModuleStateMap().get(MultipleModuleCode.MODULE_1).isBubeExist(); + case MultipleModuleCode.MODULE_2 -> + deviceState.getHeatModuleStateMap().get(MultipleModuleCode.MODULE_2).isBubeExist(); + }; + if (heatTubeExist) throw new AppException(ResultCode.TARGET_MODULE_OCCUPIED);//目标模块被占用 + //3、判断夹爪是否夹取了试管 todo + return runAsync(() -> { + //滴定电机回原点 + titrationModuleService.titrationMotorOrigin(titrationModuleCode); + //移动到需要移动的试管为止,z轴先抬升,再移动到试管上方 + transferModuleService.roboticMoveToTitration(titrationModuleCode); + //打开夹爪 + transferModuleService.clawOpen(); + //z轴下降 + transferModuleService.zMoveDownWithTitrationArea(); + //关闭夹爪 + transferModuleService.clawClose(); + //1移动到滴定位上方 + transferModuleService.roboticMoveToHeat(heatModuleCode); + //z轴下降 + transferModuleService.zMoveDownWithHeatArea(); + //打开夹爪 + transferModuleService.clawOpen(); + //机械臂回到原点 + transferModuleService.roboticMoveToOrigin(); + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/transfer/TitrationMoveTrayAreaCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/transfer/TitrationMoveTrayAreaCommand.java new file mode 100644 index 0000000..90bc1e8 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/transfer/TitrationMoveTrayAreaCommand.java @@ -0,0 +1,70 @@ +package com.iflytop.colortitration.app.command.control.transfer; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.core.state.DeviceState; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import com.iflytop.colortitration.app.service.module.TransferModuleService; +import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.result.ResultCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 滴定区转移至托盘位 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("titration_move_tray_area") +public class TitrationMoveTrayAreaCommand extends BaseCommandHandler { + private final DeviceState deviceState; + private final TransferModuleService transferModuleService; + private final TitrationModuleService titrationModuleService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + Integer tubeNum = commandDTO.getIntegerParam("tubeNum"); + String moduleCode = commandDTO.getStringParam("moduleCode"); + if (StringUtils.isEmpty(moduleCode) || tubeNum == null) { + throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失 + } + MultipleModuleCode titrationModuleCode = MultipleModuleCode.valueOf(moduleCode); + boolean tubeExist = switch (titrationModuleCode) { //1首先滴定位试管状态 + case MultipleModuleCode.MODULE_1 -> + deviceState.getTitrationModuleStateMap().get(titrationModuleCode).isBubeExist(); + case MultipleModuleCode.MODULE_2 -> + deviceState.getTitrationModuleStateMap().get(titrationModuleCode).isBubeExist(); + }; + if (!tubeExist) throw new AppException(ResultCode.TARGET_MODULE_NO_TUBE);//目标被占用 + //3、判断夹爪是否夹取了试管 todo + + return runAsync(() -> { + //滴定电机回原点 + titrationModuleService.titrationMotorOrigin(titrationModuleCode); + //移动到滴定位 + transferModuleService.roboticMoveToTitration(titrationModuleCode); + //打开夹爪 + transferModuleService.clawOpen(); + //z轴下降 + transferModuleService.zMoveDownWithTitrationArea(); + //抓紧夹爪 + transferModuleService.clawClose(); + //移动到试管位上方 + transferModuleService.roboticMoveToTubePosition(tubeNum); + //z轴下降 + transferModuleService.zMoveDownWithTitrationArea(); + //打开夹爪 + transferModuleService.clawOpen(); + //机械臂回到原点 + transferModuleService.roboticMoveToOrigin(); + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/control/transfer/TrayMoveTitrationAreaCommand.java b/src/main/java/com/iflytop/colortitration/app/command/control/transfer/TrayMoveTitrationAreaCommand.java new file mode 100644 index 0000000..2e8e6c2 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/control/transfer/TrayMoveTitrationAreaCommand.java @@ -0,0 +1,76 @@ +package com.iflytop.colortitration.app.command.control.transfer; + +import com.iflytop.colortitration.app.common.annotation.CommandDebugMapping; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.core.state.DeviceState; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.module.TitrationModuleService; +import com.iflytop.colortitration.app.service.module.TransferModuleService; +import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.result.ResultCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 托盘位转移至滴定区 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandDebugMapping("tray_move_titration_area") +public class TrayMoveTitrationAreaCommand extends BaseCommandHandler { + private final DeviceState deviceState; + private final TransferModuleService transferModuleService; + private final TitrationModuleService titrationModuleService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + Integer tubeNum = commandDTO.getIntegerParam("tubeNum"); + String moduleCode = commandDTO.getStringParam("titrationModuleCode"); + if (StringUtils.isEmpty(moduleCode) || tubeNum == null) { + throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失 + } + MultipleModuleCode titrationModuleCode = MultipleModuleCode.valueOf(moduleCode); + boolean trayExist = switch (titrationModuleCode) { //1、首先检测试管所在的托盘传感器的值 + case MultipleModuleCode.MODULE_1 -> deviceState.isTrayExist1(); + case MultipleModuleCode.MODULE_2 -> deviceState.isTrayExist2(); + }; + if (!trayExist) throw new AppException(ResultCode.TARGET_MODULE_OCCUPIED);//目标模块无试管 + //3、判断夹爪是否夹取了试管 todo + + return runAsync(() -> { + //滴定电机回原点 + titrationModuleService.titrationMotorOrigin(titrationModuleCode); + //移动到需要移动的试管为止,z轴先抬升,再移动到试管上方 + transferModuleService.roboticMoveToTubePosition(tubeNum); + //打开夹爪 + transferModuleService.clawOpen(); + //z轴下降 + transferModuleService.zMoveDownWithTrayArea(); + //关闭夹爪 + transferModuleService.clawClose(); + //判断滴定位传感器状态 + boolean titrationExist = switch (titrationModuleCode) { //1、首先检测试管所在的托盘传感器的值 + case MultipleModuleCode.MODULE_1 -> + deviceState.getTitrationModuleStateMap().get(MultipleModuleCode.MODULE_1).isBubeExist(); + case MultipleModuleCode.MODULE_2 -> + deviceState.getTitrationModuleStateMap().get(MultipleModuleCode.MODULE_2).isBubeExist(); + }; + if (titrationExist) throw new AppException(ResultCode.TARGET_MODULE_OCCUPIED);//目标模块被占用 + //移动到滴定位上方 + transferModuleService.roboticMoveToTitration(titrationModuleCode); + //z轴下降 + transferModuleService.zMoveDownWithTitrationArea(); + //打开夹爪 + transferModuleService.clawOpen(); + //机械臂回到原点 + transferModuleService.roboticMoveToOrigin(); + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/common/enums/DevicePositionCode.java b/src/main/java/com/iflytop/colortitration/app/common/enums/DevicePositionCode.java new file mode 100644 index 0000000..e1a2222 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/common/enums/DevicePositionCode.java @@ -0,0 +1,72 @@ +package com.iflytop.colortitration.app.common.enums; + +import lombok.Getter; + +/** + * 设备位置代码 + */ +@Getter +public enum DevicePositionCode { + ////////////相对距离 + /** + * 夹爪松开距离 + */ + clawReleaseDistance(DevicePositionType.DISTANCE, "夹爪松开距离"), + /** + * 夹爪收紧距离 + */ + clawGripDistance(DevicePositionType.DISTANCE, "夹爪收紧距离"), + /** + * z轴下降高度 + */ + trayDownDistance(DevicePositionType.DISTANCE, "试管位托盘下降距离"), + /** + * 滴定位下降高度 + */ + titrationDownDistance(DevicePositionType.DISTANCE, "滴定位下降高度"), + /** + * 加热位下降高度 + */ + heatDownDistance(DevicePositionType.DISTANCE, "加热位托盘下降距离"), + /** + * 滴定电机1加液位置 + */ + titrationAddSolutionDistance_1(DevicePositionType.DISTANCE, "滴定电机1加液位置"), + /** + * 滴定电机2加液位置 + */ + titrationAddSolutionDistance_2(DevicePositionType.DISTANCE, "滴定电机2加液位置"), + /** + * 滴定电机移动至废液池距离 + */ + titrationWastePoolDistance(DevicePositionType.DISTANCE, "滴定电机移动至废液池距离"), + ////////////////位置 + /** + * 滴定位1位置 + */ + titrationArea_1(DevicePositionType.POINT_3D, "滴定位1位置"), + /** + * 滴定位2位置 + */ + titrationArea_2(DevicePositionType.POINT_3D, "滴定位2位置"), + /** + * 加热位置1 + */ + heatArea_1(DevicePositionType.POINT_3D, "加热位置1"), + /** + * 加热位置2 + */ + heatArea_2(DevicePositionType.POINT_3D, "加热位置2"), + /** + * 试管架1号试管位置 + */ + tube(DevicePositionType.POINT_3D, "试管1位置"); + + private final DevicePositionType type; + private final String name; + + DevicePositionCode(DevicePositionType type, String name) { + this.type = type; + this.name = name; + } +} diff --git a/src/main/java/com/iflytop/colortitration/app/common/enums/DevicePositionType.java b/src/main/java/com/iflytop/colortitration/app/common/enums/DevicePositionType.java new file mode 100644 index 0000000..2020bb1 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/common/enums/DevicePositionType.java @@ -0,0 +1,35 @@ +package com.iflytop.colortitration.app.common.enums; + +import lombok.Getter; + +/** + * 设备位置类型 + */ +@Getter +public enum DevicePositionType { + /** + * 直线距离 + */ + DISTANCE("距离"), + /** + * 位置 + */ + POSITION("位置"), + /** + * 二维点 + */ + POINT_2D("二维点"), + /** + * 三维点 + */ + POINT_3D("三维点"); + + + private final String name; + + // 构造函数 + DevicePositionType(String name) { + this.name = name; + } + +} diff --git a/src/main/java/com/iflytop/colortitration/app/service/DeviceInitService.java b/src/main/java/com/iflytop/colortitration/app/service/DeviceInitService.java index c087824..d627fbc 100644 --- a/src/main/java/com/iflytop/colortitration/app/service/DeviceInitService.java +++ b/src/main/java/com/iflytop/colortitration/app/service/DeviceInitService.java @@ -29,6 +29,7 @@ public class DeviceInitService { log.info("初始化开始"); initDeviceState(); + //缓存点位数据 deviceState.setInitComplete(true); log.info("初始化完毕"); diff --git a/src/main/java/com/iflytop/colortitration/app/service/module/HeatModuleService.java b/src/main/java/com/iflytop/colortitration/app/service/module/HeatModuleService.java index f524f75..e820006 100644 --- a/src/main/java/com/iflytop/colortitration/app/service/module/HeatModuleService.java +++ b/src/main/java/com/iflytop/colortitration/app/service/module/HeatModuleService.java @@ -1,5 +1,8 @@ package com.iflytop.colortitration.app.service.module; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.DeviceCommand; +import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator; import com.iflytop.colortitration.app.service.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -14,4 +17,26 @@ import org.springframework.stereotype.Service; public class HeatModuleService { private final DeviceCommandService deviceCommandService; + /** + * 关闭加热棒 + */ + public void closeHeatRod(MultipleModuleCode heatModuleCode) { + DeviceCommand deviceCommand = switch (heatModuleCode) { + case MultipleModuleCode.MODULE_1 -> DeviceCommandGenerator.heatRod1Close(); + case MultipleModuleCode.MODULE_2 -> DeviceCommandGenerator.heatRod2Close(); + }; + deviceCommandService.sendCommand(deviceCommand); + } + + /** + * 打开就加热棒 + */ + public void openHeatRod(MultipleModuleCode heatModuleCode, double temperature) { + DeviceCommand deviceCommand = switch (heatModuleCode) { + case MultipleModuleCode.MODULE_1 -> DeviceCommandGenerator.heatRod1Open(temperature); + case MultipleModuleCode.MODULE_2 -> DeviceCommandGenerator.heatRod2Open(temperature); + }; + deviceCommandService.sendCommand(deviceCommand); + } + } diff --git a/src/main/java/com/iflytop/colortitration/app/service/module/TitrationModuleService.java b/src/main/java/com/iflytop/colortitration/app/service/module/TitrationModuleService.java index 7e15d64..d80ca67 100644 --- a/src/main/java/com/iflytop/colortitration/app/service/module/TitrationModuleService.java +++ b/src/main/java/com/iflytop/colortitration/app/service/module/TitrationModuleService.java @@ -1,10 +1,26 @@ package com.iflytop.colortitration.app.service.module; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.iflytop.colortitration.app.common.enums.DevicePositionCode; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.command.DeviceCommand; +import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator; import com.iflytop.colortitration.app.service.DeviceCommandService; +import com.iflytop.colortitration.common.enums.Device; +import com.iflytop.colortitration.common.exception.AppException; +import com.iflytop.colortitration.common.model.entity.Container; +import com.iflytop.colortitration.common.model.entity.Position; +import com.iflytop.colortitration.common.model.entity.Pump; +import com.iflytop.colortitration.common.result.ResultCode; +import com.iflytop.colortitration.common.service.ContainerService; +import com.iflytop.colortitration.common.service.PositionService; +import com.iflytop.colortitration.common.service.PumpService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.util.concurrent.TimeUnit; + /** * 滴定模块 */ @@ -13,5 +29,337 @@ import org.springframework.stereotype.Service; @RequiredArgsConstructor public class TitrationModuleService { private final DeviceCommandService deviceCommandService; + private final ContainerService containerService; + private final PumpService pumpService; + private final PositionService positionService; + + /** + * 添加溶液开始 + */ + public void addSolutionStart(MultipleModuleCode titrationModuleCode, Integer solutionId, double volume) { + //找到泵 + Device deviceCode = getPumpCode(titrationModuleCode, solutionId); + DeviceCommand deviceCommand = switch (deviceCode) { + case Device.BRUSHLESS_PUMP_1 -> DeviceCommandGenerator.brushlessPump1MoveBy(volume); + case Device.BRUSHLESS_PUMP_2 -> DeviceCommandGenerator.brushlessPump2MoveBy(volume); + case Device.BRUSHLESS_PUMP_3 -> DeviceCommandGenerator.brushlessPump3MoveBy(volume); + case Device.BRUSHLESS_PUMP_4 -> DeviceCommandGenerator.brushlessPump4MoveBy(volume); + case Device.BRUSHLESS_PUMP_5 -> DeviceCommandGenerator.brushlessPump5MoveBy(volume); + case Device.BRUSHLESS_PUMP_6 -> DeviceCommandGenerator.brushlessPump6MoveBy(volume); + case Device.BRUSHLESS_PUMP_7 -> DeviceCommandGenerator.brushlessPump7MoveBy(volume); + case Device.BRUSHLESS_PUMP_8 -> DeviceCommandGenerator.brushlessPump8MoveBy(volume); + case Device.BRUSHLESS_PUMP_9 -> DeviceCommandGenerator.brushlessPump9MoveBy(volume); + case Device.BRUSHLESS_PUMP_10 -> DeviceCommandGenerator.brushlessPump10MoveBy(volume); + case Device.CERAMIC_PUMP_1 -> DeviceCommandGenerator.ceramicPump1MoveBy(volume); + case Device.CERAMIC_PUMP_2 -> DeviceCommandGenerator.ceramicPump2MoveBy(volume); + case Device.STEP_PUMP_1 -> DeviceCommandGenerator.stepPump1MoveBy(volume); + case Device.STEP_PUMP_2 -> DeviceCommandGenerator.stepPump2MoveBy(volume); + case Device.STEP_PUMP_3 -> DeviceCommandGenerator.stepPump3MoveBy(volume); + default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效 + }; + deviceCommandService.sendCommand(deviceCommand); + + } + + /** + * 添加溶液结束 + */ + public void addSolutionStop(MultipleModuleCode titrationModuleCode, Integer solutionId) { + //找到泵 + Device deviceCode = getPumpCode(titrationModuleCode, solutionId); + DeviceCommand deviceCommand = switch (deviceCode) { + case Device.BRUSHLESS_PUMP_1 -> DeviceCommandGenerator.brushlessPump1ForwardRotate(); + case Device.BRUSHLESS_PUMP_2 -> DeviceCommandGenerator.brushlessPump2ForwardRotate(); + case Device.BRUSHLESS_PUMP_3 -> DeviceCommandGenerator.brushlessPump3ForwardRotate(); + case Device.BRUSHLESS_PUMP_4 -> DeviceCommandGenerator.brushlessPump4ForwardRotate(); + case Device.BRUSHLESS_PUMP_5 -> DeviceCommandGenerator.brushlessPump5ForwardRotate(); + case Device.BRUSHLESS_PUMP_6 -> DeviceCommandGenerator.brushlessPump6ForwardRotate(); + case Device.BRUSHLESS_PUMP_7 -> DeviceCommandGenerator.brushlessPump7ForwardRotate(); + case Device.BRUSHLESS_PUMP_8 -> DeviceCommandGenerator.brushlessPump8ForwardRotate(); + case Device.BRUSHLESS_PUMP_9 -> DeviceCommandGenerator.brushlessPump9ForwardRotate(); + case Device.BRUSHLESS_PUMP_10 -> DeviceCommandGenerator.brushlessPump10ForwardRotate(); + case Device.CERAMIC_PUMP_1 -> DeviceCommandGenerator.ceramicPump1ForwardRotate(); + case Device.CERAMIC_PUMP_2 -> DeviceCommandGenerator.ceramicPump2ForwardRotate(); + case Device.STEP_PUMP_1 -> DeviceCommandGenerator.stepPump1ForwardRotate(); + case Device.STEP_PUMP_2 -> DeviceCommandGenerator.stepPump2ForwardRotate(); + case Device.STEP_PUMP_3 -> DeviceCommandGenerator.stepPump3ForwardRotate(); + default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效 + }; + deviceCommandService.sendCommand(deviceCommand); + + } + + /** + * 预充开始 + */ + public void preFillStart(MultipleModuleCode titrationModuleCode, Integer solutionId) { + //找到泵 + Device deviceCode = getPumpCode(titrationModuleCode, solutionId); + DeviceCommand deviceCommand = switch (deviceCode) { + case Device.BRUSHLESS_PUMP_1 -> DeviceCommandGenerator.brushlessPump1ForwardRotate(); + case Device.BRUSHLESS_PUMP_2 -> DeviceCommandGenerator.brushlessPump2ForwardRotate(); + case Device.BRUSHLESS_PUMP_3 -> DeviceCommandGenerator.brushlessPump3ForwardRotate(); + case Device.BRUSHLESS_PUMP_4 -> DeviceCommandGenerator.brushlessPump4ForwardRotate(); + case Device.BRUSHLESS_PUMP_5 -> DeviceCommandGenerator.brushlessPump5ForwardRotate(); + case Device.BRUSHLESS_PUMP_6 -> DeviceCommandGenerator.brushlessPump6ForwardRotate(); + case Device.BRUSHLESS_PUMP_7 -> DeviceCommandGenerator.brushlessPump7ForwardRotate(); + case Device.BRUSHLESS_PUMP_8 -> DeviceCommandGenerator.brushlessPump8ForwardRotate(); + case Device.BRUSHLESS_PUMP_9 -> DeviceCommandGenerator.brushlessPump9ForwardRotate(); + case Device.BRUSHLESS_PUMP_10 -> DeviceCommandGenerator.brushlessPump10ForwardRotate(); + case Device.CERAMIC_PUMP_1 -> DeviceCommandGenerator.ceramicPump1ForwardRotate(); + case Device.CERAMIC_PUMP_2 -> DeviceCommandGenerator.ceramicPump2ForwardRotate(); + case Device.STEP_PUMP_1 -> DeviceCommandGenerator.stepPump1ForwardRotate(); + case Device.STEP_PUMP_2 -> DeviceCommandGenerator.stepPump2ForwardRotate(); + case Device.STEP_PUMP_3 -> DeviceCommandGenerator.stepPump3ForwardRotate(); + default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效 + }; + deviceCommandService.sendCommand(deviceCommand); + + } + + /** + * 预充结束 + */ + public void preFillStop(MultipleModuleCode titrationModuleCode, Integer solutionId) { + //找到泵 + Device deviceCode = getPumpCode(titrationModuleCode, solutionId); + DeviceCommand deviceCommand = switch (deviceCode) { + case Device.BRUSHLESS_PUMP_1 -> DeviceCommandGenerator.brushlessPump1Stop(); + case Device.BRUSHLESS_PUMP_2 -> DeviceCommandGenerator.brushlessPump2Stop(); + case Device.BRUSHLESS_PUMP_3 -> DeviceCommandGenerator.brushlessPump3Stop(); + case Device.BRUSHLESS_PUMP_4 -> DeviceCommandGenerator.brushlessPump4Stop(); + case Device.BRUSHLESS_PUMP_5 -> DeviceCommandGenerator.brushlessPump5Stop(); + case Device.BRUSHLESS_PUMP_6 -> DeviceCommandGenerator.brushlessPump6Stop(); + case Device.BRUSHLESS_PUMP_7 -> DeviceCommandGenerator.brushlessPump7Stop(); + case Device.BRUSHLESS_PUMP_8 -> DeviceCommandGenerator.brushlessPump8Stop(); + case Device.BRUSHLESS_PUMP_9 -> DeviceCommandGenerator.brushlessPump9Stop(); + case Device.BRUSHLESS_PUMP_10 -> DeviceCommandGenerator.brushlessPump10Stop(); + case Device.CERAMIC_PUMP_1 -> DeviceCommandGenerator.ceramicPump1Stop(); + case Device.CERAMIC_PUMP_2 -> DeviceCommandGenerator.ceramicPump2Stop(); + case Device.STEP_PUMP_1 -> DeviceCommandGenerator.stepPump1Stop(); + case Device.STEP_PUMP_2 -> DeviceCommandGenerator.stepPump2Stop(); + case Device.STEP_PUMP_3 -> DeviceCommandGenerator.stepPump3Stop(); + default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效 + }; + deviceCommandService.sendCommand(deviceCommand); + + } + + /** + * 清洗开始 + */ + public void cleanStart(MultipleModuleCode titrationModuleCode, Integer solutionId) { + //找到泵 + Device deviceCode = getPumpCode(titrationModuleCode, solutionId); + DeviceCommand deviceCommand = switch (deviceCode) { + case Device.BRUSHLESS_PUMP_1 -> DeviceCommandGenerator.brushlessPump1ForwardRotate(); + case Device.BRUSHLESS_PUMP_2 -> DeviceCommandGenerator.brushlessPump2ForwardRotate(); + case Device.BRUSHLESS_PUMP_3 -> DeviceCommandGenerator.brushlessPump3ForwardRotate(); + case Device.BRUSHLESS_PUMP_4 -> DeviceCommandGenerator.brushlessPump4ForwardRotate(); + case Device.BRUSHLESS_PUMP_5 -> DeviceCommandGenerator.brushlessPump5ForwardRotate(); + case Device.BRUSHLESS_PUMP_6 -> DeviceCommandGenerator.brushlessPump6ForwardRotate(); + case Device.BRUSHLESS_PUMP_7 -> DeviceCommandGenerator.brushlessPump7ForwardRotate(); + case Device.BRUSHLESS_PUMP_8 -> DeviceCommandGenerator.brushlessPump8ForwardRotate(); + case Device.BRUSHLESS_PUMP_9 -> DeviceCommandGenerator.brushlessPump9ForwardRotate(); + case Device.BRUSHLESS_PUMP_10 -> DeviceCommandGenerator.brushlessPump10ForwardRotate(); + case Device.CERAMIC_PUMP_1 -> DeviceCommandGenerator.ceramicPump1ForwardRotate(); + case Device.CERAMIC_PUMP_2 -> DeviceCommandGenerator.ceramicPump2ForwardRotate(); + case Device.STEP_PUMP_1 -> DeviceCommandGenerator.stepPump1ForwardRotate(); + case Device.STEP_PUMP_2 -> DeviceCommandGenerator.stepPump2ForwardRotate(); + case Device.STEP_PUMP_3 -> DeviceCommandGenerator.stepPump3ForwardRotate(); + default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效 + }; + deviceCommandService.sendCommand(deviceCommand); + + } + + /** + * 清洗结束 + */ + public void cleanStop(MultipleModuleCode titrationModuleCode, Integer solutionId) { + //找到泵 + Device deviceCode = getPumpCode(titrationModuleCode, solutionId); + DeviceCommand deviceCommand = switch (deviceCode) { + case Device.BRUSHLESS_PUMP_1 -> DeviceCommandGenerator.brushlessPump1Stop(); + case Device.BRUSHLESS_PUMP_2 -> DeviceCommandGenerator.brushlessPump2Stop(); + case Device.BRUSHLESS_PUMP_3 -> DeviceCommandGenerator.brushlessPump3Stop(); + case Device.BRUSHLESS_PUMP_4 -> DeviceCommandGenerator.brushlessPump4Stop(); + case Device.BRUSHLESS_PUMP_5 -> DeviceCommandGenerator.brushlessPump5Stop(); + case Device.BRUSHLESS_PUMP_6 -> DeviceCommandGenerator.brushlessPump6Stop(); + case Device.BRUSHLESS_PUMP_7 -> DeviceCommandGenerator.brushlessPump7Stop(); + case Device.BRUSHLESS_PUMP_8 -> DeviceCommandGenerator.brushlessPump8Stop(); + case Device.BRUSHLESS_PUMP_9 -> DeviceCommandGenerator.brushlessPump9Stop(); + case Device.BRUSHLESS_PUMP_10 -> DeviceCommandGenerator.brushlessPump10Stop(); + case Device.CERAMIC_PUMP_1 -> DeviceCommandGenerator.ceramicPump1Stop(); + case Device.CERAMIC_PUMP_2 -> DeviceCommandGenerator.ceramicPump2Stop(); + case Device.STEP_PUMP_1 -> DeviceCommandGenerator.stepPump1Stop(); + case Device.STEP_PUMP_2 -> DeviceCommandGenerator.stepPump2Stop(); + case Device.STEP_PUMP_3 -> DeviceCommandGenerator.stepPump3Stop(); + default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效 + }; + deviceCommandService.sendCommand(deviceCommand); + + } + + /** + * 排空溶液开始 + */ + public void drainStart(MultipleModuleCode titrationModuleCode, Integer solutionId) { + Device deviceCode = getPumpCode(titrationModuleCode, solutionId); + DeviceCommand deviceCommand = switch (deviceCode) { + case Device.BRUSHLESS_PUMP_1 -> DeviceCommandGenerator.brushlessPump1BackwardRotate(); + case Device.BRUSHLESS_PUMP_2 -> DeviceCommandGenerator.brushlessPump2BackwardRotate(); + case Device.BRUSHLESS_PUMP_3 -> DeviceCommandGenerator.brushlessPump3BackwardRotate(); + case Device.BRUSHLESS_PUMP_4 -> DeviceCommandGenerator.brushlessPump4BackwardRotate(); + case Device.BRUSHLESS_PUMP_5 -> DeviceCommandGenerator.brushlessPump5BackwardRotate(); + case Device.BRUSHLESS_PUMP_6 -> DeviceCommandGenerator.brushlessPump6BackwardRotate(); + case Device.BRUSHLESS_PUMP_7 -> DeviceCommandGenerator.brushlessPump7BackwardRotate(); + case Device.BRUSHLESS_PUMP_8 -> DeviceCommandGenerator.brushlessPump8BackwardRotate(); + case Device.BRUSHLESS_PUMP_9 -> DeviceCommandGenerator.brushlessPump9BackwardRotate(); + case Device.BRUSHLESS_PUMP_10 -> DeviceCommandGenerator.brushlessPump10BackwardRotate(); + case Device.CERAMIC_PUMP_1 -> DeviceCommandGenerator.ceramicPump1BackwardRotate(); + case Device.CERAMIC_PUMP_2 -> DeviceCommandGenerator.ceramicPump2BackwardRotate(); + case Device.STEP_PUMP_1 -> DeviceCommandGenerator.stepPump1BackwardRotate(); + case Device.STEP_PUMP_2 -> DeviceCommandGenerator.stepPump2BackwardRotate(); + case Device.STEP_PUMP_3 -> DeviceCommandGenerator.stepPump3BackwardRotate(); + default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效 + }; + deviceCommandService.sendCommand(deviceCommand); + + } + + /** + * 排空结束 + */ + public void drainStop(MultipleModuleCode titrationModuleCode, Integer solutionId) { + //找到泵 + Device deviceCode = getPumpCode(titrationModuleCode, solutionId); + DeviceCommand deviceCommand = switch (deviceCode) { + case Device.BRUSHLESS_PUMP_1 -> DeviceCommandGenerator.brushlessPump1Stop(); + case Device.BRUSHLESS_PUMP_2 -> DeviceCommandGenerator.brushlessPump2Stop(); + case Device.BRUSHLESS_PUMP_3 -> DeviceCommandGenerator.brushlessPump3Stop(); + case Device.BRUSHLESS_PUMP_4 -> DeviceCommandGenerator.brushlessPump4Stop(); + case Device.BRUSHLESS_PUMP_5 -> DeviceCommandGenerator.brushlessPump5Stop(); + case Device.BRUSHLESS_PUMP_6 -> DeviceCommandGenerator.brushlessPump6Stop(); + case Device.BRUSHLESS_PUMP_7 -> DeviceCommandGenerator.brushlessPump7Stop(); + case Device.BRUSHLESS_PUMP_8 -> DeviceCommandGenerator.brushlessPump8Stop(); + case Device.BRUSHLESS_PUMP_9 -> DeviceCommandGenerator.brushlessPump9Stop(); + case Device.BRUSHLESS_PUMP_10 -> DeviceCommandGenerator.brushlessPump10Stop(); + case Device.CERAMIC_PUMP_1 -> DeviceCommandGenerator.ceramicPump1Stop(); + case Device.CERAMIC_PUMP_2 -> DeviceCommandGenerator.ceramicPump2Stop(); + case Device.STEP_PUMP_1 -> DeviceCommandGenerator.stepPump1Stop(); + case Device.STEP_PUMP_2 -> DeviceCommandGenerator.stepPump2Stop(); + case Device.STEP_PUMP_3 -> DeviceCommandGenerator.stepPump3Stop(); + default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效 + }; + deviceCommandService.sendCommand(deviceCommand); + + } + + /** + * 获取泵的code值 + */ + public Device getPumpCode(MultipleModuleCode titrationModuleCode, Integer solutionId) { + Container container = containerService.getOne(new LambdaQueryWrapper<>(Container.class).eq(Container::getSolutionsId, solutionId)); + if (container != null) { + Pump pump = pumpService.getOne(new LambdaQueryWrapper<>(Pump.class).eq(Pump::getContainerId, container.getId()).eq(Pump::getSolutionModule, titrationModuleCode.name())); + return pump.getDeviceCode(); + } + return null; + } + + /** + * 摇匀开始 + */ + public void shakeStart(MultipleModuleCode titrationModuleCode, Double speed, Integer time) throws InterruptedException { + if (speed != null) { + DeviceCommand deviceCommand = switch (titrationModuleCode) { + case MultipleModuleCode.MODULE_1 -> DeviceCommandGenerator.stirMotor1SetSpeed(speed); + case MultipleModuleCode.MODULE_2 -> DeviceCommandGenerator.stirMotor2SetSpeed(speed); + }; + deviceCommandService.sendCommand(deviceCommand); + } + DeviceCommand deviceCommand = switch (titrationModuleCode) { + case MultipleModuleCode.MODULE_1 -> DeviceCommandGenerator.stirMotor1ForwardRotate(); + case MultipleModuleCode.MODULE_2 -> DeviceCommandGenerator.stirMotor2ForwardRotate(); + }; + deviceCommandService.sendCommand(deviceCommand); + if (time != null) { + TimeUnit.SECONDS.sleep(time); + DeviceCommand stopCommand = switch (titrationModuleCode) { + case MultipleModuleCode.MODULE_1 -> DeviceCommandGenerator.stirMotor1Stop(); + case MultipleModuleCode.MODULE_2 -> DeviceCommandGenerator.stirMotor2Stop(); + }; + deviceCommandService.sendCommand(stopCommand); + } + + } + + /** + * 停止摇匀 + */ + public void shakeStop(MultipleModuleCode titrationModuleCode) { + DeviceCommand deviceCommand = switch (titrationModuleCode) { + case MultipleModuleCode.MODULE_1 -> DeviceCommandGenerator.stirMotor1Stop(); + case MultipleModuleCode.MODULE_2 -> DeviceCommandGenerator.stirMotor2Stop(); + }; + deviceCommandService.sendCommand(deviceCommand); + } + + /** + * 滴定电机移动到滴定位 + */ + public void titrationMotorMoveToSolution(MultipleModuleCode moduleCode) { + Position position = switch (moduleCode) { + case MultipleModuleCode.MODULE_1 -> + positionService.getPositionByCode(DevicePositionCode.titrationAddSolutionDistance_1); + case MultipleModuleCode.MODULE_2 -> + positionService.getPositionByCode(DevicePositionCode.titrationAddSolutionDistance_2); + }; + DeviceCommand deviceCommand = switch (moduleCode) { + case MODULE_1 -> DeviceCommandGenerator.titrationMotor1MoveTo(position.getDistance()); + case MODULE_2 -> DeviceCommandGenerator.titrationMotor2MoveTo(position.getDistance()); + }; + deviceCommandService.sendCommand(deviceCommand); + } + + /** + * 滴定电机移动至废液池 + */ + public void titrationMotorMoveToWastePool(MultipleModuleCode moduleCode) { + Position position = positionService.getPositionByCode(DevicePositionCode.titrationWastePoolDistance); + DeviceCommand deviceCommand = switch (moduleCode) { + case MODULE_1 -> DeviceCommandGenerator.titrationMotor1MoveTo(position.getDistance()); + case MODULE_2 -> DeviceCommandGenerator.titrationMotor2MoveTo(position.getDistance()); + }; + deviceCommandService.sendCommand(deviceCommand); + } + + /** + * 滴定电机移动到原点 + */ + public void titrationMotorOrigin(MultipleModuleCode moduleCode) { + DeviceCommand deviceCommand = switch (moduleCode) { + case MODULE_1 -> DeviceCommandGenerator.titrationMotor1Origin(); + case MODULE_2 -> DeviceCommandGenerator.titrationMotor2Origin(); + }; + deviceCommandService.sendCommand(deviceCommand); + } + + /** + * 开始抽废液 + */ + public void drainWasteStart() { + DeviceCommand deviceCommand = DeviceCommandGenerator.stepPump3ForwardRotate(); + deviceCommandService.sendCommand(deviceCommand); + } + + /** + * 结束抽废液 + */ + public void drainWasteStop() { + DeviceCommand deviceCommand = DeviceCommandGenerator.stepPump3Stop(); + deviceCommandService.sendCommand(deviceCommand); + } } diff --git a/src/main/java/com/iflytop/colortitration/app/service/module/TransferModuleService.java b/src/main/java/com/iflytop/colortitration/app/service/module/TransferModuleService.java index 35cb11b..b975165 100644 --- a/src/main/java/com/iflytop/colortitration/app/service/module/TransferModuleService.java +++ b/src/main/java/com/iflytop/colortitration/app/service/module/TransferModuleService.java @@ -1,6 +1,13 @@ package com.iflytop.colortitration.app.service.module; +import com.iflytop.colortitration.app.common.enums.DevicePositionCode; +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.common.utils.CommandUtil; +import com.iflytop.colortitration.app.core.command.CommandFuture; +import com.iflytop.colortitration.app.core.command.DeviceCommand; +import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator; import com.iflytop.colortitration.app.service.DeviceCommandService; +import com.iflytop.colortitration.common.model.bo.Point3D; import com.iflytop.colortitration.common.service.PositionService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -16,4 +23,148 @@ public class TransferModuleService { private final DeviceCommandService deviceCommandService; private final PositionService positionService; + /** + * 机械臂回原点 + */ + public void roboticMoveToOrigin() throws Exception { + // Z轴回零点 + DeviceCommand zOriginCommand = DeviceCommandGenerator.zMove(0.0); + CommandFuture zOriginFuture = deviceCommandService.sendCommand(zOriginCommand); + CommandUtil.wait(zOriginFuture); + // 机械臂大轴移动 + DeviceCommand xMoveCommand = DeviceCommandGenerator.roboticArmBigMotorMoveTo(0.0); + CommandFuture xcommandFuture = deviceCommandService.sendCommand(xMoveCommand); + // 机械臂小轴移动 + DeviceCommand yMoveCommand = DeviceCommandGenerator.roboticArmBigMotorMoveTo(0.0); + CommandFuture ycommandFuture = deviceCommandService.sendCommand(yMoveCommand); + CommandUtil.wait(xcommandFuture, ycommandFuture); + } + + /** + * 机械臂移动到指定试管为止 + */ + public void roboticMoveToTubePosition(Integer index) throws Exception { + Point3D position = positionService.getPositionByCode(DevicePositionCode.tube).getPoint3D(); //根据index和第一个托盘试管的位置计算index试管的位置 todo + // Z轴回零点 + DeviceCommand zOriginCommand = DeviceCommandGenerator.zMove(0.0); + CommandFuture zOriginFuture = deviceCommandService.sendCommand(zOriginCommand); + CommandUtil.wait(zOriginFuture); + // 机械臂大轴移动 + DeviceCommand xMoveCommand = DeviceCommandGenerator.roboticArmBigMotorMoveTo(position.getX()); + CommandFuture xcommandFuture = deviceCommandService.sendCommand(xMoveCommand); + // 机械臂小轴移动 + DeviceCommand yMoveCommand = DeviceCommandGenerator.roboticArmBigMotorMoveTo(position.getX()); + CommandFuture ycommandFuture = deviceCommandService.sendCommand(yMoveCommand); + CommandUtil.wait(xcommandFuture, ycommandFuture); + } + + /** + * 机械臂移动到指定滴定位 + */ + public void roboticMoveToTitration(MultipleModuleCode moduleCode) throws Exception { + Point3D position = switch (moduleCode) { //1、首先检测试管所在的托盘传感器的值 + case MultipleModuleCode.MODULE_1 -> + positionService.getPositionByCode(DevicePositionCode.titrationArea_1).getPoint3D(); + case MultipleModuleCode.MODULE_2 -> + positionService.getPositionByCode(DevicePositionCode.titrationArea_2).getPoint3D(); + }; + // Z轴回零点 + DeviceCommand zOriginCommand = DeviceCommandGenerator.zMove(0.0); + CommandFuture zOriginFuture = deviceCommandService.sendCommand(zOriginCommand); + CommandUtil.wait(zOriginFuture); + // 机械臂大轴移动 + DeviceCommand xMoveCommand = DeviceCommandGenerator.roboticArmBigMotorMoveTo(position.getX()); + CommandFuture xcommandFuture = deviceCommandService.sendCommand(xMoveCommand); + // 机械臂小轴移动 + DeviceCommand yMoveCommand = DeviceCommandGenerator.roboticArmBigMotorMoveTo(position.getX()); + CommandFuture ycommandFuture = deviceCommandService.sendCommand(yMoveCommand); + CommandUtil.wait(xcommandFuture, ycommandFuture); + } + + /** + * 机械臂移动到指定加热位 + */ + public void roboticMoveToHeat(MultipleModuleCode moduleCode) throws Exception { + Point3D position = switch (moduleCode) { //1、首先检测试管所在的托盘传感器的值 + case MultipleModuleCode.MODULE_1 -> + positionService.getPositionByCode(DevicePositionCode.heatArea_1).getPoint3D(); + case MultipleModuleCode.MODULE_2 -> + positionService.getPositionByCode(DevicePositionCode.heatArea_2).getPoint3D(); + }; + // Z轴回零点 + DeviceCommand zOriginCommand = DeviceCommandGenerator.zMove(0.0); + CommandFuture zOriginFuture = deviceCommandService.sendCommand(zOriginCommand); + CommandUtil.wait(zOriginFuture); + // 机械臂大轴移动 + DeviceCommand xMoveCommand = DeviceCommandGenerator.roboticArmBigMotorMoveTo(position.getX()); + CommandFuture xcommandFuture = deviceCommandService.sendCommand(xMoveCommand); + // 机械臂小轴移动 + DeviceCommand yMoveCommand = DeviceCommandGenerator.roboticArmBigMotorMoveTo(position.getX()); + CommandFuture ycommandFuture = deviceCommandService.sendCommand(yMoveCommand); + CommandUtil.wait(xcommandFuture, ycommandFuture); + } + + /** + * 夹爪打开 + */ + public void clawOpen() throws Exception { + //夹爪张开distance + Double distance = positionService.getPositionByCode(DevicePositionCode.clawReleaseDistance).getDistance(); + DeviceCommand clawOpenCommand = DeviceCommandGenerator.clawMove(distance); + CommandFuture clawOpenFuture = deviceCommandService.sendCommand(clawOpenCommand); + CommandUtil.wait(clawOpenFuture); + } + + /** + * 夹爪抓紧 + */ + public void clawClose() throws Exception { + //夹爪张开distance + Double distance = positionService.getPositionByCode(DevicePositionCode.clawGripDistance).getDistance(); + DeviceCommand clawOpenCommand = DeviceCommandGenerator.clawMove(distance); + CommandFuture clawOpenFuture = deviceCommandService.sendCommand(clawOpenCommand); + CommandUtil.wait(clawOpenFuture); + } + + /** + * z轴托盘位下降 + */ + public void zMoveDownWithTrayArea() throws Exception { + Double distance = positionService.getPositionByCode(DevicePositionCode.trayDownDistance).getDistance(); + DeviceCommand zOriginCommand = DeviceCommandGenerator.zMove(distance); + CommandFuture zOriginFuture = deviceCommandService.sendCommand(zOriginCommand); + CommandUtil.wait(zOriginFuture); + } + + /** + * z轴滴定位下降 + */ + public void zMoveDownWithTitrationArea() throws Exception { + Double distance = positionService.getPositionByCode(DevicePositionCode.titrationDownDistance).getDistance(); + DeviceCommand zOriginCommand = DeviceCommandGenerator.zMove(distance); + CommandFuture zOriginFuture = deviceCommandService.sendCommand(zOriginCommand); + CommandUtil.wait(zOriginFuture); + } + + /** + * z轴加热位下降 + */ + public void zMoveDownWithHeatArea() throws Exception { + Double distance = positionService.getPositionByCode(DevicePositionCode.heatDownDistance).getDistance(); + DeviceCommand zOriginCommand = DeviceCommandGenerator.zMove(distance); + CommandFuture zOriginFuture = deviceCommandService.sendCommand(zOriginCommand); + CommandUtil.wait(zOriginFuture); + } + + /** + * z轴回原点 + */ + public void zMoveOrigin() throws Exception { + // Z轴回零点 + DeviceCommand zOriginCommand = DeviceCommandGenerator.zMove(0.0); + CommandFuture zOriginFuture = deviceCommandService.sendCommand(zOriginCommand); + CommandUtil.wait(zOriginFuture); + } + + } diff --git a/src/main/java/com/iflytop/colortitration/common/model/entity/Position.java b/src/main/java/com/iflytop/colortitration/common/model/entity/Position.java index e7621c7..def9e3f 100644 --- a/src/main/java/com/iflytop/colortitration/common/model/entity/Position.java +++ b/src/main/java/com/iflytop/colortitration/common/model/entity/Position.java @@ -2,10 +2,14 @@ package com.iflytop.colortitration.common.model.entity; import com.baomidou.mybatisplus.annotation.TableName; import com.iflytop.colortitration.common.base.BaseEntity; +import com.iflytop.colortitration.common.model.bo.Point2D; +import com.iflytop.colortitration.common.model.bo.Point3D; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; +import java.util.Arrays; + @Data @TableName("position") @EqualsAndHashCode(callSuper = true) @@ -22,4 +26,28 @@ public class Position extends BaseEntity { @Schema(description = "位置信息") private String position; + + public Point3D getPoint3D() { + String[] positions = position.split(","); + Double[] doublePositions = Arrays.stream(positions) + .map(Double::parseDouble) + .toArray(Double[]::new); + return new Point3D(doublePositions[0], doublePositions[1], doublePositions[2]); + } + + public Point2D getPoint2D() { + String[] positions = position.split(","); + Double[] doublePositions = Arrays.stream(positions) + .map(Double::parseDouble) + .toArray(Double[]::new); + return new Point2D(doublePositions[0], doublePositions[1]); + } + + public Double getDistance() { + return Double.valueOf(position); + } + + public Double getPositon() { + return Double.valueOf(position); + } } diff --git a/src/main/java/com/iflytop/colortitration/common/result/ResultCode.java b/src/main/java/com/iflytop/colortitration/common/result/ResultCode.java index 274207a..6714f5a 100644 --- a/src/main/java/com/iflytop/colortitration/common/result/ResultCode.java +++ b/src/main/java/com/iflytop/colortitration/common/result/ResultCode.java @@ -54,18 +54,17 @@ public enum ResultCode implements IResultCode, Serializable { COMMAND_NOT_FOUND("6000", "指令未找到"), COMMAND_ALREADY_EXECUTING("6001", "指令正在执行,无法重复执行"), SENSOR_STATUS_FAILED("6010", "获取传感器状态失败"), - TARGET_HEAT_MODULE_OCCUPIED("6021", "目标加热模块被占用"), - TARGET_HEAT_MODULE_NO_TRAY("6022", "目标加热模块无托盘"), - SOLUTION_MODULE_NO_TRAY("6023", "加液模块无托盘"), - CAP_LIFT_ERROR("6024", "拍子升降错误"), + TARGET_MODULE_OCCUPIED("6021", "目标模块被占用"), + TARGET_MODULE_NO_TUBE("6022", "目标模块无试管"), CMD_BUSY("6025", "设备忙,请稍后"), - HEAT_MODULE_NO_IDLE("6026", "加热模块无空闲"), - CAP_MODULE_NO_CAP("6027", "拍子存放区未检测到拍子"), - SOLUTION_MODULE_OCCUPIED("6028", "加液模块被占用"), ; - /** 状态码 */ + /** + * 状态码 + */ private final String code; - /** 提示信息 */ + /** + * 提示信息 + */ private final String msg; @Override diff --git a/src/main/java/com/iflytop/colortitration/common/service/PositionService.java b/src/main/java/com/iflytop/colortitration/common/service/PositionService.java index 1bd2597..be9bdd1 100644 --- a/src/main/java/com/iflytop/colortitration/common/service/PositionService.java +++ b/src/main/java/com/iflytop/colortitration/common/service/PositionService.java @@ -1,8 +1,10 @@ package com.iflytop.colortitration.common.service; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.iflytop.colortitration.common.model.entity.Position; +import com.iflytop.colortitration.app.common.enums.DevicePositionCode; import com.iflytop.colortitration.common.mapper.PositionMapper; +import com.iflytop.colortitration.common.model.entity.Position; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -12,5 +14,11 @@ import org.springframework.stereotype.Service; @Service @RequiredArgsConstructor public class PositionService extends ServiceImpl { + /** + * 根据位置Code获取位置 + */ + public Position getPositionByCode(DevicePositionCode code) { + return this.getOne(new LambdaQueryWrapper<>(Position.class).eq(Position::getCode, code)); + } } \ No newline at end of file