diff --git a/src/main/java/com/iflytop/sgs/app/cmd/control/LiquidAddCommand.java b/src/main/java/com/iflytop/sgs/app/cmd/control/LiquidAddCommand.java index 1570ad2..93d0093 100644 --- a/src/main/java/com/iflytop/sgs/app/cmd/control/LiquidAddCommand.java +++ b/src/main/java/com/iflytop/sgs/app/cmd/control/LiquidAddCommand.java @@ -10,6 +10,7 @@ import com.iflytop.sgs.app.model.entity.Solutions; import com.iflytop.sgs.app.service.api.DevicePositionService; import com.iflytop.sgs.app.service.api.SolutionsService; import com.iflytop.sgs.app.service.api.SystemConfigService; +import com.iflytop.sgs.app.service.device.DeviceSensorService; import com.iflytop.sgs.app.service.device.DeviceStateService; import com.iflytop.sgs.app.service.device.module.SolutionModuleService; import com.iflytop.sgs.app.service.device.module.TransferModuleService; @@ -38,10 +39,10 @@ public class LiquidAddCommand extends BaseCommandHandler { private final TransferModuleService transferModuleService; private final SystemConfigService systemConfigService; private final SolutionsService solutionsService; + private final DeviceSensorService deviceSensorService; @Override public CompletableFuture handle(CmdDTO cmdDTO) { - //todo 获取阀门的状态 return runAsync(() -> { @@ -60,8 +61,9 @@ public class LiquidAddCommand extends BaseCommandHandler { Double trayTubeHorizontalSpacingDistance = devicePositionService.getPosition(DevicePositionCode.trayTubeHorizontalSpacingDistance).getDistance(); //托盘试管水平间距 solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//加液机械臂上升 transferModuleService.transferMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint);//移动至加液位置 - //预充 - ValveStateCode oldValveState = deviceStateService.getDeviceState().getSolutionModule().getValveState().getState();//获取当前电磁阀的值 + Integer currentChannel = deviceSensorService.readLiquidValvePosition();//获取当前阀门的状态 + ValveStateCode oldValveState = ValveStateCode.thick.getByChannel(currentChannel);//获取当前电磁阀的值 + double preFillDistance = 0; if (!oldValveState.equals(valveStateCode)) {//判断是否与当前加酸的通道一致 不一致排空 switch (oldValveState) { diff --git a/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidPumpStartCommand.java b/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidPumpStartCommand.java index 139ba1b..ed3088b 100644 --- a/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidPumpStartCommand.java +++ b/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidPumpStartCommand.java @@ -16,7 +16,7 @@ import org.springframework.stereotype.Component; import java.util.concurrent.CompletableFuture; /** - * 处理加液泵启动指令 todo 需要加正向反向 + * 处理加液泵启动指令 */ @Slf4j @Component diff --git a/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidValveOpenThinCommand.java b/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidValveOpenThinCommand.java index d65f124..20ae8b0 100644 --- a/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidValveOpenThinCommand.java +++ b/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidValveOpenThinCommand.java @@ -16,7 +16,7 @@ import org.springframework.stereotype.Component; import java.util.concurrent.CompletableFuture; /** - * 阀转换到稀硝酸通道 todo 需要与小何确定次序 + * 阀转换到稀硝酸通道 */ @Slf4j @Component diff --git a/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidValveOpenVacantCommand.java b/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidValveOpenVacantCommand.java index 5530ed8..14366d2 100644 --- a/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidValveOpenVacantCommand.java +++ b/src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidValveOpenVacantCommand.java @@ -15,7 +15,7 @@ import org.springframework.stereotype.Component; import java.util.concurrent.CompletableFuture; /** - * 阀转换到空通道 todo 需要与小何确定次序 + * 阀转换到空通道 */ @Slf4j @Component diff --git a/src/main/java/com/iflytop/sgs/app/controller/MotorController.java b/src/main/java/com/iflytop/sgs/app/controller/MotorController.java index ab8de4d..0c757ca 100644 --- a/src/main/java/com/iflytop/sgs/app/controller/MotorController.java +++ b/src/main/java/com/iflytop/sgs/app/controller/MotorController.java @@ -26,8 +26,13 @@ public class MotorController { @GetMapping("/position/{motor}") public Result getPosition(@PathVariable String motor) { DevicePartId devicePartId = DevicePartId.valueOf(motor); + Double position; try { - Double position = deviceSensorService.getSensorStatus(devicePartId); + if (devicePartId.equals(DevicePartId.XSV)) { + position = deviceSensorService.getXYServoPosition(devicePartId); + } else { + position = deviceSensorService.getMotorPosition(devicePartId); + } return Result.success(position); } catch (HardwareException e) { throw new RuntimeException(e); diff --git a/src/main/java/com/iflytop/sgs/app/service/device/DeviceSensorService.java b/src/main/java/com/iflytop/sgs/app/service/device/DeviceSensorService.java index f5ed2ca..05095ef 100644 --- a/src/main/java/com/iflytop/sgs/app/service/device/DeviceSensorService.java +++ b/src/main/java/com/iflytop/sgs/app/service/device/DeviceSensorService.java @@ -33,10 +33,27 @@ public class DeviceSensorService { /* * 获取电机位置 * */ - public Double getSensorStatus(DevicePartId devicePartId) throws HardwareException { + public Double getMotorPosition(DevicePartId devicePartId) throws HardwareException { return deviceStatusService.getStepMotorPostion(devicePartId.name()); } + /* + * 获取私服电机位置 + * */ + public Double getXYServoPosition(DevicePartId devicePartId) throws HardwareException { + return deviceStatusService.getXYServoPosition(devicePartId.name()); + } + + /* + * 获取阀门状态 + * */ + public Integer readLiquidValvePosition() throws HardwareException { + return deviceStatusService.readLiquidValvePosition(DevicePartId.LiquidValve.name()); + } + + + + @Scheduled(fixedRate = 1000) public void deviceSensorSchedule() throws HardwareException { HeatModuleState heat_module_01 = deviceStateService.getDeviceState().getHeatModuleByCode(HeatModuleCode.heat_module_01); diff --git a/src/main/java/com/iflytop/sgs/common/enums/DevicePartId.java b/src/main/java/com/iflytop/sgs/common/enums/DevicePartId.java index c6aed2e..a6e6049 100644 --- a/src/main/java/com/iflytop/sgs/common/enums/DevicePartId.java +++ b/src/main/java/com/iflytop/sgs/common/enums/DevicePartId.java @@ -8,11 +8,13 @@ public enum DevicePartId { DoorM("门电机"), LiquidM("加液电机"), ZM("Z轴电机"), + XSV("X轴电机"), LiquidPumpM("加液泵"), HEATER_ROD1_ID("加热棒1"), HEATER_ROD2_ID("加热棒2"), HEATER_ROD3_ID("加热棒3"), HEATER_ROD4_ID("加热棒4"), + LiquidValve("电磁阀"), ; private final String description; diff --git a/src/main/java/com/iflytop/sgs/common/enums/ValveStateCode.java b/src/main/java/com/iflytop/sgs/common/enums/ValveStateCode.java index 5a14b85..7d8b3c8 100644 --- a/src/main/java/com/iflytop/sgs/common/enums/ValveStateCode.java +++ b/src/main/java/com/iflytop/sgs/common/enums/ValveStateCode.java @@ -8,17 +8,17 @@ import lombok.Getter; @Getter public enum ValveStateCode { //加液时 液量的转换系数 - thin(1, "稀硝酸通道", SystemConfigCode.scale_thin,ContainerCode.container_01), - thick(2, "浓硝酸通道", SystemConfigCode.scale_thick,ContainerCode.container_02), - water(3, "蒸馏水通道", SystemConfigCode.scale_water,ContainerCode.container_03), - waste(4, "废水通道", SystemConfigCode.scale_waste,ContainerCode.container_04), - vacant(5, "空气通道", SystemConfigCode.scale_vacant,null), + thin(1, "稀硝酸通道", SystemConfigCode.scale_thin, ContainerCode.container_01), + thick(2, "浓硝酸通道", SystemConfigCode.scale_thick, ContainerCode.container_02), + water(3, "蒸馏水通道", SystemConfigCode.scale_water, ContainerCode.container_03), + waste(4, "废水通道", SystemConfigCode.scale_waste, ContainerCode.container_04), + vacant(5, "空气通道", SystemConfigCode.scale_vacant, null), ; private final Integer channel; private final String description; private final SystemConfigCode systemConfigCode; - private final ContainerCode containerCode ; + private final ContainerCode containerCode; ValveStateCode(Integer channel, String description, SystemConfigCode systemConfigCode, ContainerCode containerCode) { this.channel = channel; @@ -26,6 +26,16 @@ public enum ValveStateCode { this.systemConfigCode = systemConfigCode; this.containerCode = containerCode; } + + public ValveStateCode getByChannel(Integer channel) { + for (ValveStateCode valveStateCode : ValveStateCode.values()) { + if (valveStateCode.getChannel().equals(channel)) { + return valveStateCode; + } + } + return null; + } + } diff --git a/src/main/java/com/iflytop/sgs/common/service/GDDeviceStatusService.java b/src/main/java/com/iflytop/sgs/common/service/GDDeviceStatusService.java index f90fa89..536cd8a 100644 --- a/src/main/java/com/iflytop/sgs/common/service/GDDeviceStatusService.java +++ b/src/main/java/com/iflytop/sgs/common/service/GDDeviceStatusService.java @@ -5,6 +5,7 @@ import com.iflytop.sgs.hardware.type.IO.InputIOMId; import com.iflytop.sgs.hardware.type.Servo.LeisaiServoMId; import com.iflytop.sgs.hardware.type.StepMotor.StepMotorMId; import com.iflytop.sgs.hardware.type.driver.HeaterRodSlavedId; +import com.iflytop.sgs.hardware.type.driver.LiquidValveMId; public interface GDDeviceStatusService { @@ -54,5 +55,13 @@ public interface GDDeviceStatusService { * @return * @throws HardwareException */ - Double getXYServoPosition(LeisaiServoMId mid) throws HardwareException; + Double getXYServoPosition(String mid) throws HardwareException; + + /** + * 获取液体阀门位置 + * @param mid + * @return + * @throws HardwareException + */ + public Integer readLiquidValvePosition(String mid) throws HardwareException; } diff --git a/src/main/java/com/iflytop/sgs/hardware/service/GDDeviceStatusServiceImpl.java b/src/main/java/com/iflytop/sgs/hardware/service/GDDeviceStatusServiceImpl.java index 19077f8..c1a2755 100644 --- a/src/main/java/com/iflytop/sgs/hardware/service/GDDeviceStatusServiceImpl.java +++ b/src/main/java/com/iflytop/sgs/hardware/service/GDDeviceStatusServiceImpl.java @@ -1,6 +1,6 @@ package com.iflytop.sgs.hardware.service; -import com.iflytop.sgs.common.service.GDDeviceStatusInterface; +import com.iflytop.sgs.common.service.GDDeviceStatusService; import com.iflytop.sgs.hardware.drivers.DIDriver.InputDetectDriver; import com.iflytop.sgs.hardware.drivers.HeaterRodDriver; import com.iflytop.sgs.hardware.drivers.LeiSaiServoDriver; @@ -21,7 +21,7 @@ import org.springframework.stereotype.Component; @Slf4j @Component @RequiredArgsConstructor -public class GDDeviceStatusService implements GDDeviceStatusInterface { +public class GDDeviceStatusServiceImpl implements GDDeviceStatusService { private final InputDetectDriver inputDetectDriver; private final HeaterRodDriver heaterRodDriver; private final StepMotorCtrlDriver stepMotorCtrlDriver; @@ -30,6 +30,7 @@ public class GDDeviceStatusService implements GDDeviceStatusInterface { /** * 获取步进电机的原点状态 + * * @param stepMotorMId * @return true 在原点 false 不在原点 */ @@ -39,17 +40,18 @@ public class GDDeviceStatusService implements GDDeviceStatusInterface { /** * 获取XY 伺服的原点状态 + * * @param mid * @return * @throws HardwareException */ - public Boolean getXYServoIsOrigin(LeisaiServoMId mid) throws HardwareException - { + public Boolean getXYServoIsOrigin(LeisaiServoMId mid) throws HardwareException { return leisaiServoDriver.readIoState(mid, 0); } /** * 获取传感器信号 + * * @param inputIOMIdStr * @return * @throws HardwareException @@ -61,23 +63,25 @@ public class GDDeviceStatusService implements GDDeviceStatusInterface { /** * 获取加热棒温度 + * * @param heaterRodSlavedIdStr * @return * @throws Exception */ public Double getHeaterRodTemperature(String heaterRodSlavedIdStr) throws Exception { - HeaterRodSlavedId heaterRodSlavedId=HeaterRodSlavedId.valueOf(heaterRodSlavedIdStr); + HeaterRodSlavedId heaterRodSlavedId = HeaterRodSlavedId.valueOf(heaterRodSlavedIdStr); return heaterRodDriver.getTemperature(heaterRodSlavedId); } /** * 获取电机位置 + * * @param stepMotorMIdStr * @return * @throws HardwareException */ public Double getStepMotorPostion(String stepMotorMIdStr) throws HardwareException { - StepMotorMId stepMotorMId=StepMotorMId.valueOf(stepMotorMIdStr); + StepMotorMId stepMotorMId = StepMotorMId.valueOf(stepMotorMIdStr); Integer motorPosition = stepMotorCtrlDriver.stepMotorReadPos(stepMotorMId); Double realPosition = StepMotorConverter.toUserPosition(motorPosition); return realPosition; @@ -85,12 +89,14 @@ public class GDDeviceStatusService implements GDDeviceStatusInterface { /** * 获取伺服类电机位置 + * * @param mid * @return * @throws HardwareException */ - public Double getXYServoPosition(LeisaiServoMId mid) throws HardwareException { - int servoPosition = leisaiServoDriver.readPosition(mid); + public Double getXYServoPosition(String mid) throws HardwareException { + LeisaiServoMId leisaiServoMId = LeisaiServoMId.valueOf(mid.toString()); + int servoPosition = leisaiServoDriver.readPosition(leisaiServoMId); return StepMotorConverter.toUserPosition(servoPosition); } @@ -100,8 +106,9 @@ public class GDDeviceStatusService implements GDDeviceStatusInterface { * @return * @throws HardwareException */ - public Integer readLiquidValvePosition(LiquidValveMId mid) throws HardwareException { - return liquidValveDriver.readValveHoleIndex(mid); + public Integer readLiquidValvePosition(String mid) throws HardwareException { + LiquidValveMId liquidValveMId = LiquidValveMId.valueOf(mid); + return liquidValveDriver.readValveHoleIndex(liquidValveMId); } }