diff --git a/src/main/java/com/iflytop/gd/app/cmd/CapLiftingOriginCommand.java b/src/main/java/com/iflytop/gd/app/cmd/CapLiftingOriginCommand.java new file mode 100644 index 0000000..9f1646a --- /dev/null +++ b/src/main/java/com/iflytop/gd/app/cmd/CapLiftingOriginCommand.java @@ -0,0 +1,33 @@ +package com.iflytop.gd.app.cmd; + +import com.iflytop.gd.app.core.BaseCommandHandler; +import com.iflytop.gd.app.model.dto.CmdDTO; +import com.iflytop.gd.app.service.DeviceCommandUtilService; +import com.iflytop.gd.app.service.SelfTestService; +import com.iflytop.gd.common.annotation.CommandMapping; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 拍子升降回原点 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandMapping("cap_lifting_origin")//业务指令注解 +public class CapLiftingOriginCommand extends BaseCommandHandler { + private final DeviceCommandUtilService deviceCommandUtilService; + private final SelfTestService selfTestService; + + @Override + public CompletableFuture handle(CmdDTO cmdDTO) { + return runAsync(() -> { + deviceCommandUtilService.trayMotorOrigin(cmdDTO.getCommandId(), cmdDTO.getCommand()); + selfTestService.getSelfTestState().setCapLiftingOrigin(true); + }); + } +} + diff --git a/src/main/java/com/iflytop/gd/app/cmd/DualRobotJointOriginCommand.java b/src/main/java/com/iflytop/gd/app/cmd/DualRobotJointOriginCommand.java new file mode 100644 index 0000000..5297e22 --- /dev/null +++ b/src/main/java/com/iflytop/gd/app/cmd/DualRobotJointOriginCommand.java @@ -0,0 +1,43 @@ +package com.iflytop.gd.app.cmd; + +import com.iflytop.gd.app.core.BaseCommandHandler; +import com.iflytop.gd.app.model.dto.CmdDTO; +import com.iflytop.gd.app.service.DeviceCommandUtilService; +import com.iflytop.gd.app.service.SelfTestService; +import com.iflytop.gd.common.annotation.CommandMapping; +import com.iflytop.gd.common.enums.cmd.CmdAxis; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 指定加液机械臂回原点 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandMapping("dual_robot_joint_origin")//业务指令注解 +public class DualRobotJointOriginCommand extends BaseCommandHandler { + private final DeviceCommandUtilService deviceCommandUtilService; + private final SelfTestService selfTestService; + + @Override + public CompletableFuture handle(CmdDTO cmdDTO) { + Boolean joint1 = cmdDTO.getBooleanParam("joint1"); + Boolean joint2 = cmdDTO.getBooleanParam("joint1"); + return runAsync(() -> { + + if(joint1){ + deviceCommandUtilService.dualRobotOrigin(cmdDTO.getCommandId(), cmdDTO.getCommand(), CmdAxis.joint1); + selfTestService.getSelfTestState().setDualRobotJoint1Origin(true); + } + if(joint2){ + deviceCommandUtilService.dualRobotOrigin(cmdDTO.getCommandId(), cmdDTO.getCommand(), CmdAxis.joint2); + selfTestService.getSelfTestState().setDualRobotJoint2Origin(true); + } + }); + } +} + diff --git a/src/main/java/com/iflytop/gd/app/cmd/GantryXOriginCommand.java b/src/main/java/com/iflytop/gd/app/cmd/GantryXOriginCommand.java new file mode 100644 index 0000000..b0c7f89 --- /dev/null +++ b/src/main/java/com/iflytop/gd/app/cmd/GantryXOriginCommand.java @@ -0,0 +1,54 @@ +package com.iflytop.gd.app.cmd; + +import com.iflytop.gd.app.core.BaseCommandHandler; +import com.iflytop.gd.app.model.dto.CmdDTO; +import com.iflytop.gd.app.service.DeviceCommandUtilService; +import com.iflytop.gd.app.service.DevicePositionService; +import com.iflytop.gd.app.service.SelfTestService; +import com.iflytop.gd.common.annotation.CommandMapping; +import com.iflytop.gd.common.cmd.CommandFuture; +import com.iflytop.gd.common.cmd.DeviceCommandBundle; +import com.iflytop.gd.common.cmd.DeviceCommandGenerator; +import com.iflytop.gd.common.enums.data.DevicePositionCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +/** + * 龙门架机械臂指定轴回原点 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandMapping("gantry_origin")//业务指令注解 +public class GantryXOriginCommand extends BaseCommandHandler { + private final DeviceCommandUtilService deviceCommandUtilService; + private final SelfTestService selfTestService; + + @Override + public CompletableFuture handle(CmdDTO cmdDTO) { + return runAsync(() -> { + Boolean x = cmdDTO.getBooleanParam("x"); + Boolean y = cmdDTO.getBooleanParam("y"); + Boolean z = cmdDTO.getBooleanParam("z"); + if (x) { + deviceCommandUtilService.gantryXMoveOrigin(cmdDTO.getCommandId(), cmdDTO.getCommand()); + selfTestService.getSelfTestState().setGantryXOrigin(true); + } + if (y) { + deviceCommandUtilService.gantryYMoveOrigin(cmdDTO.getCommandId(), cmdDTO.getCommand()); + selfTestService.getSelfTestState().setGantryYOrigin(true); + } + + if (z) { + deviceCommandUtilService.gantryZMoveOrigin(cmdDTO.getCommandId(), cmdDTO.getCommand()); + selfTestService.getSelfTestState().setGantryZOrigin(true); + } + }); + } +} + diff --git a/src/main/java/com/iflytop/gd/app/cmd/TrayLiftingOriginCommand.java b/src/main/java/com/iflytop/gd/app/cmd/TrayLiftingOriginCommand.java new file mode 100644 index 0000000..a89b611 --- /dev/null +++ b/src/main/java/com/iflytop/gd/app/cmd/TrayLiftingOriginCommand.java @@ -0,0 +1,43 @@ +package com.iflytop.gd.app.cmd; + +import com.iflytop.gd.app.core.BaseCommandHandler; +import com.iflytop.gd.app.model.dto.CmdDTO; +import com.iflytop.gd.app.service.DeviceCommandUtilService; +import com.iflytop.gd.app.service.SelfTestService; +import com.iflytop.gd.common.annotation.CommandMapping; +import com.iflytop.gd.common.enums.HeatModuleCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 托盘升降回原点 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandMapping("tray_lifting_origin")//业务指令注解 +public class TrayLiftingOriginCommand extends BaseCommandHandler { + private final DeviceCommandUtilService deviceCommandUtilService; + private final SelfTestService selfTestService; + + @Override + public CompletableFuture handle(CmdDTO cmdDTO) { + String heatId = cmdDTO.getStringParam("heatId"); + HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId); + return runAsync(() -> { + deviceCommandUtilService.heaterMotorMoveOrigin(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId); + switch (heatModuleId) { + case heat_module_01 -> selfTestService.getSelfTestState().setTrayLifting01Origin(true); + case heat_module_02 -> selfTestService.getSelfTestState().setTrayLifting02Origin(true); + case heat_module_03 -> selfTestService.getSelfTestState().setTrayLifting03Origin(true); + case heat_module_04 -> selfTestService.getSelfTestState().setTrayLifting04Origin(true); + case heat_module_05 -> selfTestService.getSelfTestState().setTrayLifting05Origin(true); + case heat_module_06 -> selfTestService.getSelfTestState().setTrayLifting06Origin(true); + } + }); + } +} + diff --git a/src/main/java/com/iflytop/gd/app/controller/SelfTestController.java b/src/main/java/com/iflytop/gd/app/controller/SelfTestController.java new file mode 100644 index 0000000..3cc45b0 --- /dev/null +++ b/src/main/java/com/iflytop/gd/app/controller/SelfTestController.java @@ -0,0 +1,37 @@ +package com.iflytop.gd.app.controller; + +import com.iflytop.gd.app.core.device.SelfTestState; +import com.iflytop.gd.app.service.DeviceStateService; +import com.iflytop.gd.app.service.SelfTestService; +import com.iflytop.gd.common.result.Result; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "自检") +@RestController +@RequestMapping("/api/self-test") +@RequiredArgsConstructor +@Slf4j +public class SelfTestController { + private final SelfTestService selfTestService; + private final DeviceStateService deviceStateService; + + @Operation(summary = "获取自检状态") + @GetMapping("/status") + public Result getSelfTestStatus() { + return Result.success(selfTestService.getSelfTestState()); + } + + @Operation(summary = "自检完毕") + @PostMapping("/finish") + public Result selfTestFinish() { + deviceStateService.setSelfTest(true); + return Result.success(); + } +} diff --git a/src/main/java/com/iflytop/gd/app/core/device/DeviceState.java b/src/main/java/com/iflytop/gd/app/core/device/DeviceState.java index fd92c70..239b542 100644 --- a/src/main/java/com/iflytop/gd/app/core/device/DeviceState.java +++ b/src/main/java/com/iflytop/gd/app/core/device/DeviceState.java @@ -15,6 +15,9 @@ public class DeviceState { @Schema(description = "初始化状态,true初始化完毕") private boolean initComplete = false; + @Schema(description = "自检状态,true自检完毕") + private boolean selfTest = false; + @Schema(description = "是否是急停状态,true为急停") private boolean emergencyStop = false; diff --git a/src/main/java/com/iflytop/gd/app/core/device/SelfTestState.java b/src/main/java/com/iflytop/gd/app/core/device/SelfTestState.java new file mode 100644 index 0000000..13c095a --- /dev/null +++ b/src/main/java/com/iflytop/gd/app/core/device/SelfTestState.java @@ -0,0 +1,49 @@ +package com.iflytop.gd.app.core.device; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "自检状态") +@Data +public class SelfTestState { + @Schema(description = "龙门架机械臂x轴是否在原点") + private boolean gantryXOrigin = false; + + @Schema(description = "龙门架机械臂y轴是否在原点") + private boolean gantryYOrigin = false; + + @Schema(description = "龙门架机械臂z轴是否在原点") + private boolean gantryZOrigin = false; + + @Schema(description = "龙门架机械臂夹爪是否在原点") + private boolean clawOrigin = false; + + @Schema(description = "加液机械臂01是否在原点") + private boolean dualRobotJoint1Origin = false; + + @Schema(description = "加液机械臂02是否在原点") + private boolean dualRobotJoint2Origin = false; + + @Schema(description = "拍子升降是否在原点") + private boolean capLiftingOrigin = false; + + @Schema(description = "加热模块01托盘升降是否在原点") + private boolean trayLifting01Origin = false; + + @Schema(description = "加热模块02托盘升降是否在原点") + private boolean trayLifting02Origin = false; + + @Schema(description = "加热模块03托盘升降是否在原点") + private boolean trayLifting03Origin = false; + + @Schema(description = "加热模块04托盘升降是否在原点") + private boolean trayLifting04Origin = false; + + @Schema(description = "加热模块05托盘升降是否在原点") + private boolean trayLifting05Origin = false; + + @Schema(description = "加热模块06托盘升降是否在原点") + private boolean trayLifting06Origin = false; + + +} diff --git a/src/main/java/com/iflytop/gd/app/core/listener/DeviceStateListener.java b/src/main/java/com/iflytop/gd/app/core/listener/DeviceStateListener.java index d1457e9..a7efea5 100644 --- a/src/main/java/com/iflytop/gd/app/core/listener/DeviceStateListener.java +++ b/src/main/java/com/iflytop/gd/app/core/listener/DeviceStateListener.java @@ -3,6 +3,7 @@ package com.iflytop.gd.app.core.listener; import com.iflytop.gd.app.service.DeviceStateService; import com.iflytop.gd.app.service.WebSocketService; import com.iflytop.gd.common.constant.WebSocketMessageType; +import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -17,6 +18,11 @@ public class DeviceStateListener implements PropertyChangeListener { private final WebSocketService webSocketService; private final DeviceStateService deviceStateService; + @PostConstruct + private void init() { + deviceStateService.addListener(this); + } + // 在此处理DeviceState的变化事件 @Override public void propertyChange(PropertyChangeEvent event) { diff --git a/src/main/java/com/iflytop/gd/app/service/DeviceCommandUtilService.java b/src/main/java/com/iflytop/gd/app/service/DeviceCommandUtilService.java index 1e4c599..ed8a53e 100644 --- a/src/main/java/com/iflytop/gd/app/service/DeviceCommandUtilService.java +++ b/src/main/java/com/iflytop/gd/app/service/DeviceCommandUtilService.java @@ -8,6 +8,7 @@ import com.iflytop.gd.common.cmd.DeviceCommandBundle; import com.iflytop.gd.common.cmd.DeviceCommandGenerator; import com.iflytop.gd.common.enums.AcidPumpDeviceCode; import com.iflytop.gd.common.enums.HeatModuleCode; +import com.iflytop.gd.common.enums.cmd.CmdAxis; import com.iflytop.gd.common.enums.data.DevicePositionCode; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -56,6 +57,55 @@ public class DeviceCommandUtilService { commandWait(deviceCommandFutureArr); } + + /** + * 龙门架机械臂X轴回原点 + */ + public void gantryXMoveOrigin() throws Exception { + gantryXMoveOrigin(null, null); + } + + /** + * 龙门架机械臂X轴回原点 + */ + public void gantryXMoveOrigin(String cmdId, String cmdCode) throws Exception { + DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryXOrigin(); + CommandFuture[] deviceCommandFutureArr = deviceCommandService.sendCommandQueue(cmdId, cmdCode, deviceCommand); + commandWait(deviceCommandFutureArr); + } + + /** + * 龙门架机械臂Y轴回原点 + */ + public void gantryYMoveOrigin() throws Exception { + gantryYMoveOrigin(null, null); + } + + /** + * 龙门架机械臂Y轴回原点 + */ + public void gantryYMoveOrigin(String cmdId, String cmdCode) throws Exception { + DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryYOrigin(); + CommandFuture[] deviceCommandFutureArr = deviceCommandService.sendCommandQueue(cmdId, cmdCode, deviceCommand); + commandWait(deviceCommandFutureArr); + } + + /** + * 龙门架机械臂Z轴回原点 + */ + public void gantryZMoveOrigin() throws Exception { + gantryZMoveOrigin(null, null); + } + + /** + * 龙门架机械臂Z轴回原点 + */ + public void gantryZMoveOrigin(String cmdId, String cmdCode) throws Exception { + DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryZOrigin(); + CommandFuture[] deviceCommandFutureArr = deviceCommandService.sendCommandQueue(cmdId, cmdCode, deviceCommand); + commandWait(deviceCommandFutureArr); + } + /** * 龙门架机械臂X轴移动到指定点 */ @@ -190,6 +240,30 @@ public class DeviceCommandUtilService { commandWait(deviceCommandFuture); } + + /** + * 加热模块升降电机移动到指定位置 + */ + public void heaterMotorMoveOrigin(HeatModuleCode heatModuleId) throws Exception { + heaterMotorMoveOrigin(null, null, heatModuleId); + } + + /** + * 加热模块升降电机回原点 + */ + public void heaterMotorMoveOrigin(String cmdId, String cmdCode, HeatModuleCode heatModuleId) throws Exception { + DeviceCommandBundle deviceCommand = switch (heatModuleId) { + case heat_module_01 -> DeviceCommandGenerator.heaterMotor1Origin(); + case heat_module_02 -> DeviceCommandGenerator.heaterMotor2Origin(); + case heat_module_03 -> DeviceCommandGenerator.heaterMotor3Origin(); + case heat_module_04 -> DeviceCommandGenerator.heaterMotor4Origin(); + case heat_module_05 -> DeviceCommandGenerator.heaterMotor5Origin(); + case heat_module_06 -> DeviceCommandGenerator.heaterMotor6Origin(); + }; + CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdId, cmdCode, deviceCommand); + commandWait(deviceCommandFuture); + } + /** * 加热模块升降电机移动到指定位置 */ @@ -248,6 +322,21 @@ public class DeviceCommandUtilService { } /** + * 加液机械臂回原点 + */ + public void dualRobotOrigin(String cmdId, String cmdCode, CmdAxis cmdAxis) throws Exception { + if (cmdAxis == CmdAxis.joint1) { + DeviceCommandBundle deviceCommand = DeviceCommandGenerator.dualRobotJoint1Origin(); + CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdId, cmdCode, deviceCommand); + commandWait(deviceCommandFuture); + } else { + DeviceCommandBundle deviceCommand = DeviceCommandGenerator.dualRobotJoint2Origin(); + CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdId, cmdCode, deviceCommand); + commandWait(deviceCommandFuture); + } + } + + /** * 添加溶液 */ public void acidPumpMoveBy(AcidPumpDeviceCode acidPumpDevice, double position) throws Exception { @@ -398,6 +487,15 @@ public class DeviceCommandUtilService { commandWait(deviceCommandFuture); } + /** + * 拍子升降回原点 + */ + public void trayMotorOrigin(String cmdId, String cmdCode) throws Exception { + DeviceCommandBundle deviceCommand = DeviceCommandGenerator.trayMotorOrigin(); + CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdId, cmdCode, deviceCommand); + commandWait(deviceCommandFuture); + } + public void commandWait(CommandFuture... futures) throws Exception { CompletableFuture[] responseFutures = Arrays.stream(futures) diff --git a/src/main/java/com/iflytop/gd/app/service/DeviceStateService.java b/src/main/java/com/iflytop/gd/app/service/DeviceStateService.java index 822e310..f0c9d98 100644 --- a/src/main/java/com/iflytop/gd/app/service/DeviceStateService.java +++ b/src/main/java/com/iflytop/gd/app/service/DeviceStateService.java @@ -16,7 +16,6 @@ import java.beans.PropertyChangeSupport; @Service @RequiredArgsConstructor public class DeviceStateService { - private final DeviceStateListener deviceStateListener; private final transient PropertyChangeSupport support = new PropertyChangeSupport(this); private final DeviceState deviceState = new DeviceState(); @@ -25,8 +24,7 @@ public class DeviceStateService { return deviceState; } - @PostConstruct - private void init() { + public void addListener(DeviceStateListener deviceStateListener) { support.addPropertyChangeListener(deviceStateListener); } @@ -59,6 +57,12 @@ public class DeviceStateService { support.firePropertyChange("setEmergencyStop", oldValue, emergencyStop); } + public synchronized void setSelfTest(boolean selfTest) { + boolean oldValue = deviceState.isSelfTest(); + deviceState.setSelfTest(selfTest); + support.firePropertyChange("setSelfTest", oldValue, selfTest); + } + public synchronized void setDoorStatus(boolean status) { boolean oldValue = deviceState.getDoor().isOpen(); deviceState.getDoor().setOpen(status); diff --git a/src/main/java/com/iflytop/gd/app/service/SelfTestService.java b/src/main/java/com/iflytop/gd/app/service/SelfTestService.java new file mode 100644 index 0000000..f512705 --- /dev/null +++ b/src/main/java/com/iflytop/gd/app/service/SelfTestService.java @@ -0,0 +1,16 @@ +package com.iflytop.gd.app.service; + +import com.iflytop.gd.app.core.device.SelfTestState; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@RequiredArgsConstructor +public class SelfTestService { + @Getter + private final SelfTestState selfTestState = new SelfTestState(); + +}