From 6663b248cb66449c1cc077cdc7904be53a5b43b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Sat, 24 May 2025 10:11:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8E=B0=E5=9C=BA=E4=BB=A3=E7=A0=81=E5=90=8C?= =?UTF-8?q?=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gd/GraphiteDigesterServiceApplication.java | 13 ++- .../com/iflytop/gd/app/cmd/DoorCloseCommand.java | 4 +- .../gd/app/cmd/FilledSolutionStartCommand.java | 10 ++ .../iflytop/gd/app/cmd/MoveToHeatAreaCommand.java | 26 ++--- .../gd/app/cmd/MoveToSolutionAreaCommand.java | 24 +++-- .../com/iflytop/gd/app/cmd/ShakeStartCommand.java | 5 +- .../com/iflytop/gd/app/cmd/ShakeStopCommand.java | 5 +- .../com/iflytop/gd/app/cmd/SolutionAddCommand.java | 8 ++ .../debug/DebugTransportationArmMoveCommand.java | 2 +- .../app/service/DeviceCommandTempUtilService.java | 106 +++++++++++++++++++++ .../iflytop/gd/app/service/DeviceInitService.java | 2 +- .../com/iflytop/gd/app/service/UserService.java | 7 +- 12 files changed, 174 insertions(+), 38 deletions(-) create mode 100644 src/main/java/com/iflytop/gd/app/service/DeviceCommandTempUtilService.java diff --git a/src/main/java/com/iflytop/gd/GraphiteDigesterServiceApplication.java b/src/main/java/com/iflytop/gd/GraphiteDigesterServiceApplication.java index 5f299b4..3fa6fa4 100644 --- a/src/main/java/com/iflytop/gd/GraphiteDigesterServiceApplication.java +++ b/src/main/java/com/iflytop/gd/GraphiteDigesterServiceApplication.java @@ -2,6 +2,7 @@ package com.iflytop.gd; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.scheduling.annotation.EnableScheduling; @@ -11,12 +12,20 @@ import org.springframework.scheduling.annotation.EnableScheduling; public class GraphiteDigesterServiceApplication { public static void main(String[] args) { - ConfigurableApplicationContext ctx = SpringApplication.run(GraphiteDigesterServiceApplication.class, args); + SpringApplication app = new SpringApplication(GraphiteDigesterServiceApplication.class); + app.addInitializers(ctx -> { + try { + Thread.sleep(5_000); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + }); + + ConfigurableApplicationContext ctx = app.run(args); ConfigurableEnvironment env = ctx.getEnvironment(); String port = env.getProperty("local.server.port", env.getProperty("server.port", "8080")); System.out.println("应用已启动"); System.out.println("访问地址 → http://localhost:" + port + "/"); System.out.println("文档地址 → http://localhost:" + port + "/doc.html"); - //测试git账户 } } diff --git a/src/main/java/com/iflytop/gd/app/cmd/DoorCloseCommand.java b/src/main/java/com/iflytop/gd/app/cmd/DoorCloseCommand.java index 9457c54..eb05e76 100644 --- a/src/main/java/com/iflytop/gd/app/cmd/DoorCloseCommand.java +++ b/src/main/java/com/iflytop/gd/app/cmd/DoorCloseCommand.java @@ -3,10 +3,8 @@ 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.DeviceStateService; import com.iflytop.gd.common.annotation.CommandMapping; -import com.iflytop.gd.common.enums.data.DevicePositionCode; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -29,7 +27,7 @@ public class DoorCloseCommand extends BaseCommandHandler { public CompletableFuture handle(CmdDTO cmdDTO) { return runAsync(() -> { //门电机回原点 - deviceCommandUtilService.doorOrigin(cmdDTO.getCommandId(), cmdDTO.getCommand()); + deviceCommandUtilService.doorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0); //将门状态设置为false deviceStateService.setDoorStatus(false); }); diff --git a/src/main/java/com/iflytop/gd/app/cmd/FilledSolutionStartCommand.java b/src/main/java/com/iflytop/gd/app/cmd/FilledSolutionStartCommand.java index c7dc5a7..9098d84 100644 --- a/src/main/java/com/iflytop/gd/app/cmd/FilledSolutionStartCommand.java +++ b/src/main/java/com/iflytop/gd/app/cmd/FilledSolutionStartCommand.java @@ -5,8 +5,11 @@ import com.iflytop.gd.app.core.BaseCommandHandler; import com.iflytop.gd.app.model.dto.CmdDTO; import com.iflytop.gd.app.service.ContainerService; import com.iflytop.gd.app.service.DeviceCommandUtilService; +import com.iflytop.gd.app.service.DeviceStateService; import com.iflytop.gd.common.annotation.CommandMapping; import com.iflytop.gd.common.enums.AcidPumpDeviceCode; +import com.iflytop.gd.common.exception.AppException; +import com.iflytop.gd.common.result.ResultCode; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -23,9 +26,16 @@ import java.util.concurrent.CompletableFuture; public class FilledSolutionStartCommand extends BaseCommandHandler { private final DeviceCommandUtilService deviceCommandUtilService; private final ContainerService containerService; + private final DeviceStateService deviceStateService; @Override public CompletableFuture handle(CmdDTO cmdDTO) { + if (deviceStateService.getCommandState().get().isMoveToHeatAreaCommandExecuting() + || deviceStateService.getCommandState().get().isMoveToSolutionAreaCommandExecuting() + || deviceStateService.getCommandState().get().isSolutionAddCommandExecuting() + || deviceStateService.getCommandState().get().isShakeStartCommandExecuting()) { + throw new AppException(ResultCode.CMD_BUSY); + } return runAsync(() -> { JSONArray idJsonArray = cmdDTO.getJSONArrayParam("list"); for (int i = 0; i < idJsonArray.size(); i++) { diff --git a/src/main/java/com/iflytop/gd/app/cmd/MoveToHeatAreaCommand.java b/src/main/java/com/iflytop/gd/app/cmd/MoveToHeatAreaCommand.java index 6437f85..90e7fda 100644 --- a/src/main/java/com/iflytop/gd/app/cmd/MoveToHeatAreaCommand.java +++ b/src/main/java/com/iflytop/gd/app/cmd/MoveToHeatAreaCommand.java @@ -4,10 +4,7 @@ import com.iflytop.gd.app.core.BaseCommandHandler; import com.iflytop.gd.app.core.device.TrayState; import com.iflytop.gd.app.model.bo.Point3D; 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.DeviceStateService; -import com.iflytop.gd.app.service.GantryArmService; +import com.iflytop.gd.app.service.*; import com.iflytop.gd.common.annotation.CommandMapping; import com.iflytop.gd.common.enums.HeatModuleCode; import com.iflytop.gd.common.enums.data.DevicePositionCode; @@ -31,13 +28,16 @@ public class MoveToHeatAreaCommand extends BaseCommandHandler { private final DevicePositionService devicePositionService; private final GantryArmService gantryArmService; private final DeviceStateService deviceStateService; + private final DeviceCommandTempUtilService deviceCommandTempUtilService; @Override public CompletableFuture handle(CmdDTO cmdDTO) throws Exception { if (deviceStateService.getCommandState().get().isMoveToHeatAreaCommandExecuting()) { throw new AppException(ResultCode.COMMAND_ALREADY_EXECUTING); } - if (deviceStateService.getCommandState().get().isMoveToSolutionAreaCommandExecuting()) { + if (deviceStateService.getCommandState().get().isMoveToSolutionAreaCommandExecuting() + || deviceStateService.getCommandState().get().isSolutionAddCommandExecuting() + || deviceStateService.getCommandState().get().isShakeStartCommandExecuting()) { throw new AppException(ResultCode.CMD_BUSY); } String heatId = cmdDTO.getStringParam("heatId"); @@ -62,10 +62,10 @@ public class MoveToHeatAreaCommand extends BaseCommandHandler { //校验目标加热位是否有托盘 try { deviceStateService.getCommandState().get().setMoveToHeatAreaCommandExecuting(true); -// Boolean heatModuleTray = deviceCommandUtilService.heatModuleSensorState(heatModuleId); -// if (heatModuleTray) { -// throw new AppException(ResultCode.TARGET_HEAT_MODULE_NO_TRAY); -// } + Boolean heatModuleTray = deviceCommandUtilService.heatModuleSensorState(heatModuleId); + if (heatModuleTray) { + throw new AppException(ResultCode.TARGET_HEAT_MODULE_OCCUPIED); + } } catch (Exception e) { deviceStateService.getCommandState().get().setMoveToHeatAreaCommandExecuting(false); throw e; @@ -79,15 +79,17 @@ public class MoveToHeatAreaCommand extends BaseCommandHandler { deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayGrip);//将夹爪收紧,夹住托盘 deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴 deviceStateService.setSolutionModuleStateTrayStatus(0);//加液模块是否有托盘 + deviceCommandTempUtilService.moveTrayHeatModuleAvoidDown(cmdDTO.getCommandId(), cmdDTO.getCommand(), null);//TODO 避让 开始,移动托盘之前先降下所有加热模块 deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatArea4TrayClawPoint3D);//将携带托盘的机械臂移动至4号加热模块上方 deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaTrayClawPoint3D);//将携带托盘的机械臂移动至加热模块上方 - deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLift);//抬升加热位托盘 +// deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLift);//抬升加热位托盘 TODO 结构有问题临时屏蔽 + deviceCommandTempUtilService.moveTrayHeatModuleAvoidUp(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId);//TODO 避让 完毕,可以升起了,顺带提升目标加热模块 deviceCommandUtilService.gantryZMove(heatModuleTrayMoveHeight);//下降z轴,使托盘落入加热模块 deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayPick);//将夹爪打开,释放托盘 deviceStateService.setHeatModuleStateTrayStatus(heatModuleId, 1);//加热模块是否存在托盘 deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴 -// deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand());//提升拍子存放区至拍子夹取的高度 + deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand());//提升拍子存放区至拍子夹取的高度 deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方 deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开,准备夹取拍子 deviceCommandUtilService.gantryZMove(capModuleCapMoveHeight);//下降z轴,使夹爪落入拍子升降模块拍子孔位 @@ -103,7 +105,7 @@ public class MoveToHeatAreaCommand extends BaseCommandHandler { gantryArmService.setLiquidIdleTrue();//释放加液区等待 deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLower);//下降加热模块托盘 deviceStateService.setHeatModuleStateTrayUp(heatModuleId, 0);//加热模块托盘升降状态 -// deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand()); //提升拍子存放区 + deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand()); //提升拍子存放区 deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方 // deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand());//提升拍子存放区至拍子夹取的高度 diff --git a/src/main/java/com/iflytop/gd/app/cmd/MoveToSolutionAreaCommand.java b/src/main/java/com/iflytop/gd/app/cmd/MoveToSolutionAreaCommand.java index 5997ac1..1eb0bea 100644 --- a/src/main/java/com/iflytop/gd/app/cmd/MoveToSolutionAreaCommand.java +++ b/src/main/java/com/iflytop/gd/app/cmd/MoveToSolutionAreaCommand.java @@ -4,6 +4,7 @@ import com.iflytop.gd.app.core.BaseCommandHandler; import com.iflytop.gd.app.core.device.TrayState; import com.iflytop.gd.app.model.bo.Point3D; import com.iflytop.gd.app.model.dto.CmdDTO; +import com.iflytop.gd.app.service.DeviceCommandTempUtilService; import com.iflytop.gd.app.service.DeviceCommandUtilService; import com.iflytop.gd.app.service.DevicePositionService; import com.iflytop.gd.app.service.DeviceStateService; @@ -29,13 +30,16 @@ public class MoveToSolutionAreaCommand extends BaseCommandHandler { private final DeviceCommandUtilService deviceCommandUtilService; private final DevicePositionService devicePositionService; private final DeviceStateService deviceStateService; + private final DeviceCommandTempUtilService deviceCommandTempUtilService; @Override public CompletableFuture handle(CmdDTO cmdDTO) throws Exception { if (deviceStateService.getCommandState().get().isMoveToSolutionAreaCommandExecuting()) { throw new AppException(ResultCode.COMMAND_ALREADY_EXECUTING); } - if (deviceStateService.getCommandState().get().isMoveToHeatAreaCommandExecuting()) { + if (deviceStateService.getCommandState().get().isMoveToHeatAreaCommandExecuting() + || deviceStateService.getCommandState().get().isSolutionAddCommandExecuting() + || deviceStateService.getCommandState().get().isShakeStartCommandExecuting()) { throw new AppException(ResultCode.CMD_BUSY); } String heatId = cmdDTO.getStringParam("heatId"); @@ -60,10 +64,10 @@ public class MoveToSolutionAreaCommand extends BaseCommandHandler { //校验目标加热位是否有托盘 try { deviceStateService.getCommandState().get().setMoveToSolutionAreaCommandExecuting(true); -// Boolean heatModuleTray = deviceCommandUtilService.heatModuleSensorState(heatModuleId); -// if (!heatModuleTray) { -// throw new AppException(ResultCode.TARGET_HEAT_MODULE_OCCUPIED); -// } + Boolean heatModuleTray = deviceCommandUtilService.heatModuleSensorState(heatModuleId); + if (!heatModuleTray) { + throw new AppException(ResultCode.TARGET_HEAT_MODULE_NO_TRAY); + } } catch (Exception e) { deviceStateService.getCommandState().get().setMoveToSolutionAreaCommandExecuting(false); throw e; @@ -74,7 +78,7 @@ public class MoveToSolutionAreaCommand extends BaseCommandHandler { // gantryArmService.waitLiquidIdle();//等待加液区空闲 // gantryArmService.setLiquidIdleFalse();//锁定加液区 -// deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand()); //提升拍子存放区至拍子夹取的高度 + deviceCommandUtilService.capUpBalance(cmdDTO.getCommandId(), cmdDTO.getCommand()); //提升拍子存放区至拍子夹取的高度 deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaCapClawPointPoint3D);//将机械臂移动至加热模块拍子上方 deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLift);//抬升指定加热位托盘 deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开,准备夹取拍子 @@ -82,7 +86,7 @@ public class MoveToSolutionAreaCommand extends BaseCommandHandler { deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapGrip);//将夹爪收紧,夹住拍子 deviceStateService.setHeatModuleStateCapExist(heatModuleId, false);//加热模块是否存在拍子 deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴 -// deviceCommandUtilService.capMotorMoveByNum(-1);//拍子存放模块下降1个拍子位置 + deviceCommandUtilService.capMotorMoveByNum(-1);//拍子存放模块下降1个拍子位置 deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), capStorageCapClawPoint3D);//将携带拍子的机械臂移动至存放区上方 deviceCommandUtilService.gantryZMove(capModuleCapMoveHeight);//下降z轴,使夹拍子落入存放区 deviceCommandUtilService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开,释放夹取的拍子 @@ -96,10 +100,12 @@ public class MoveToSolutionAreaCommand extends BaseCommandHandler { deviceStateService.setHeatModuleStateTrayStatus(heatModuleId, 0);//加热模块是否存在托盘 // trayState.setInHeatModule(false);//托盘是否在加热模块中 deviceCommandUtilService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴 - deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLower);//下降加热模块托盘 - deviceStateService.setHeatModuleStateTrayUp(heatModuleId, 0);//加热模块托盘升降状态 +// deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLower);//下降加热模块托盘 +// deviceStateService.setHeatModuleStateTrayUp(heatModuleId, 0);//加热模块托盘升降状态 + deviceCommandTempUtilService.moveTrayHeatModuleAvoidDown(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId);//TODO 临时避让下降 deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatArea4TrayClawPoint3D);//将携带托盘的机械臂移动至4号加热模块上方 deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint3D); //将携带托盘的机械臂移动至加液模块上方 + deviceCommandTempUtilService.moveTrayHeatModuleAvoidDown(cmdDTO.getCommandId(), cmdDTO.getCommand(), null);//TODO 临时避 恢复抬起状态 deviceCommandUtilService.gantryZMove(solutionModuleTrayMoveHeight);//下降z轴,使托盘落入加液模块 // trayState.setInSolutionModule(true);//托盘是否在加液模块中 deviceStateService.setSolutionModuleStateTrayStatus(1);//加液模块是否存在托盘 diff --git a/src/main/java/com/iflytop/gd/app/cmd/ShakeStartCommand.java b/src/main/java/com/iflytop/gd/app/cmd/ShakeStartCommand.java index 408ead8..c278732 100644 --- a/src/main/java/com/iflytop/gd/app/cmd/ShakeStartCommand.java +++ b/src/main/java/com/iflytop/gd/app/cmd/ShakeStartCommand.java @@ -27,10 +27,13 @@ public class ShakeStartCommand extends BaseCommandHandler { @Override public CompletableFuture handle(CmdDTO cmdDTO) { if (deviceStateService.getCommandState().get().isMoveToHeatAreaCommandExecuting() - || deviceStateService.getCommandState().get().isMoveToSolutionAreaCommandExecuting()) { + || deviceStateService.getCommandState().get().isMoveToSolutionAreaCommandExecuting() + || deviceStateService.getCommandState().get().isSolutionAddCommandExecuting() + || deviceStateService.getCommandState().get().isShakeStartCommandExecuting()) { throw new AppException(ResultCode.CMD_BUSY); } return runAsync(() -> { + deviceStateService.getCommandState().get().setShakeStartCommandExecuting(true); deviceCommandUtilService.shakeStart(cmdDTO.getCommandId(), cmdDTO.getCommand());//开始摇匀 deviceStateService.setSolutionModuleStateShaking(true); }); diff --git a/src/main/java/com/iflytop/gd/app/cmd/ShakeStopCommand.java b/src/main/java/com/iflytop/gd/app/cmd/ShakeStopCommand.java index 65fef10..264810d 100644 --- a/src/main/java/com/iflytop/gd/app/cmd/ShakeStopCommand.java +++ b/src/main/java/com/iflytop/gd/app/cmd/ShakeStopCommand.java @@ -27,13 +27,10 @@ public class ShakeStopCommand extends BaseCommandHandler { @Override public CompletableFuture handle(CmdDTO cmdDTO) { return runAsync(() -> { - if (deviceStateService.getCommandState().get().isMoveToHeatAreaCommandExecuting() - || deviceStateService.getCommandState().get().isMoveToSolutionAreaCommandExecuting()) { - throw new AppException(ResultCode.CMD_BUSY); - } deviceCommandUtilService.shakeStop(cmdDTO.getCommandId(), cmdDTO.getCommand());//停止摇匀 deviceCommandUtilService.shakeOrigin(cmdDTO.getCommandId(), cmdDTO.getCommand());//摇匀回原点 deviceStateService.setSolutionModuleStateShaking(false); + deviceStateService.getCommandState().get().setShakeStartCommandExecuting(false); }); } } diff --git a/src/main/java/com/iflytop/gd/app/cmd/SolutionAddCommand.java b/src/main/java/com/iflytop/gd/app/cmd/SolutionAddCommand.java index fcd8381..0c79668 100644 --- a/src/main/java/com/iflytop/gd/app/cmd/SolutionAddCommand.java +++ b/src/main/java/com/iflytop/gd/app/cmd/SolutionAddCommand.java @@ -34,6 +34,13 @@ public class SolutionAddCommand extends BaseCommandHandler { //TODO 添加溶液UI重新设计 @Override public CompletableFuture handle(CmdDTO cmdDTO) { + if (deviceStateService.getCommandState().get().isMoveToHeatAreaCommandExecuting() + || deviceStateService.getCommandState().get().isMoveToSolutionAreaCommandExecuting() + || deviceStateService.getCommandState().get().isSolutionAddCommandExecuting() + || deviceStateService.getCommandState().get().isShakeStartCommandExecuting()) { + throw new AppException(ResultCode.CMD_BUSY); + } + deviceStateService.getCommandState().get().setSolutionAddCommandExecuting(true); deviceStateService.setSolutionModuleStatePumping(true); return runAsync(() -> { JSONArray dataList = JSONUtil.parseArray(cmdDTO.getParams().get("dataList")); @@ -60,6 +67,7 @@ public class SolutionAddCommand extends BaseCommandHandler { } } deviceCommandUtilService.dualRobotOrigin(); + deviceStateService.getCommandState().get().setSolutionAddCommandExecuting(false); deviceStateService.setSolutionModuleStatePumping(false); }); } diff --git a/src/main/java/com/iflytop/gd/app/cmd/debug/DebugTransportationArmMoveCommand.java b/src/main/java/com/iflytop/gd/app/cmd/debug/DebugTransportationArmMoveCommand.java index 2ea35ce..0a3febc 100644 --- a/src/main/java/com/iflytop/gd/app/cmd/debug/DebugTransportationArmMoveCommand.java +++ b/src/main/java/com/iflytop/gd/app/cmd/debug/DebugTransportationArmMoveCommand.java @@ -40,7 +40,7 @@ public class DebugTransportationArmMoveCommand extends BaseCommandHandler { Double yDimVelocity = cmdDTO.getDoubleParam("yDimVelocity"); Double zDimVelocity = cmdDTO.getDoubleParam("zDimVelocity"); Integer times = cmdDTO.getIntegerParam("times"); - + times = null; List futuresList = new ArrayList<>(); if (xDimVelocity != null) { DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryXSet(xDimVelocity); diff --git a/src/main/java/com/iflytop/gd/app/service/DeviceCommandTempUtilService.java b/src/main/java/com/iflytop/gd/app/service/DeviceCommandTempUtilService.java new file mode 100644 index 0000000..a370464 --- /dev/null +++ b/src/main/java/com/iflytop/gd/app/service/DeviceCommandTempUtilService.java @@ -0,0 +1,106 @@ +package com.iflytop.gd.app.service; + +import com.iflytop.gd.app.core.device.HeatModuleState; +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.HeatModuleCode; +import com.iflytop.gd.common.enums.data.DevicePositionCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; + +/** + * 临时方法 以后应该会废弃 + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class DeviceCommandTempUtilService { + private final DeviceCommandService deviceCommandService; + private final DevicePositionService devicePositionService; + + private final DeviceStateService deviceStateService; + + private List moveTrayHeatModuleAvoidUpStateList = Collections.synchronizedList(new ArrayList<>()); + + /** + * 抬升 + * 临时移动托盘的时候,加热模块升降避让 + * 该方法会恢复之前升起的状态 + */ + public void moveTrayHeatModuleAvoidUp(String cmdId, String cmdCode, HeatModuleCode targetHeatModuleCode) throws Exception { + double trayLift = devicePositionService.getPosition(DevicePositionCode.trayLift).getDistance(); //托盘升降抬升距离 + List futuresList = new ArrayList<>(); + for (HeatModuleCode heatModuleCode : moveTrayHeatModuleAvoidUpStateList) { + DeviceCommandBundle deviceCommand = getHeaterMotorMoveDeviceCommand(heatModuleCode, trayLift); + CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdId, cmdCode, deviceCommand); + futuresList.add(deviceCommandFuture); + } + if(targetHeatModuleCode != null) { + DeviceCommandBundle deviceCommand = getHeaterMotorMoveDeviceCommand(targetHeatModuleCode, trayLift); + CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdId, cmdCode, deviceCommand); + futuresList.add(deviceCommandFuture); + } + commandWait(futuresList.toArray(new CommandFuture[0])); + for (HeatModuleCode heatModuleCode : moveTrayHeatModuleAvoidUpStateList) { + deviceStateService.setHeatModuleStateTrayUp(heatModuleCode, 1);//加热模块托盘升降状态 + } + } + + /** + * 下降 + * 临时移动托盘的时候,加热模块升降避让 + * 该方法会下降所有升起的加热模块并且记录 + */ + public void moveTrayHeatModuleAvoidDown(String cmdId, String cmdCode, HeatModuleCode targetHeatModuleCode) throws Exception { + moveTrayHeatModuleAvoidUpStateList.clear(); + List heatModuleStateList = deviceStateService.getDeviceState().getHeatModule(); + double trayLower = devicePositionService.getPosition(DevicePositionCode.trayLower).getDistance(); //获取加热位下降托盘位置 + List futuresList = new ArrayList<>(); + for (HeatModuleState heatModuleState : heatModuleStateList) { + if (heatModuleState.getTrayUp() == 1) { + HeatModuleCode heatModuleCode = heatModuleState.getModuleCode(); + DeviceCommandBundle deviceCommand = getHeaterMotorMoveDeviceCommand(heatModuleCode, trayLower); + CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdId, cmdCode, deviceCommand); + moveTrayHeatModuleAvoidUpStateList.add(heatModuleCode); + futuresList.add(deviceCommandFuture); + } + } + if(targetHeatModuleCode != null) { + DeviceCommandBundle deviceCommand = getHeaterMotorMoveDeviceCommand(targetHeatModuleCode, trayLower); + CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdId, cmdCode, deviceCommand); + futuresList.add(deviceCommandFuture); + } + commandWait(futuresList.toArray(new CommandFuture[0])); + for (HeatModuleCode heatModuleCode : moveTrayHeatModuleAvoidUpStateList) { + deviceStateService.setHeatModuleStateTrayUp(heatModuleCode, 0);//加热模块托盘升降状态 + } + } + + public DeviceCommandBundle getHeaterMotorMoveDeviceCommand(HeatModuleCode heatModuleCode, Double position) { + return switch (heatModuleCode) { + case heat_module_01 -> DeviceCommandGenerator.heaterMotor1Move(position); + case heat_module_02 -> DeviceCommandGenerator.heaterMotor2Move(position); + case heat_module_03 -> DeviceCommandGenerator.heaterMotor3Move(position); + case heat_module_04 -> DeviceCommandGenerator.heaterMotor4Move(position); + case heat_module_05 -> DeviceCommandGenerator.heaterMotor5Move(position); + case heat_module_06 -> DeviceCommandGenerator.heaterMotor6Move(position); + }; + } + + protected void commandWait(CommandFuture... futures) throws Exception { + CompletableFuture[] responseFutures = Arrays.stream(futures) + .map(CommandFuture::getResponseFuture) + .toArray(CompletableFuture[]::new); + CompletableFuture.allOf(responseFutures) + .get(120, TimeUnit.SECONDS); + } +} diff --git a/src/main/java/com/iflytop/gd/app/service/DeviceInitService.java b/src/main/java/com/iflytop/gd/app/service/DeviceInitService.java index 751d325..fdfd7f8 100644 --- a/src/main/java/com/iflytop/gd/app/service/DeviceInitService.java +++ b/src/main/java/com/iflytop/gd/app/service/DeviceInitService.java @@ -57,7 +57,7 @@ public class DeviceInitService { public void init() { new Thread(() -> { try { - Thread.sleep(2000); + Thread.sleep(3000); CompletableFuture.runAsync(() -> { try { tricolorLightDriver.open(MId.TriColorLight, TricolorLightDriver.Color.BLUE); diff --git a/src/main/java/com/iflytop/gd/app/service/UserService.java b/src/main/java/com/iflytop/gd/app/service/UserService.java index 098db34..0f90cb2 100644 --- a/src/main/java/com/iflytop/gd/app/service/UserService.java +++ b/src/main/java/com/iflytop/gd/app/service/UserService.java @@ -1,14 +1,11 @@ package com.iflytop.gd.app.service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.iflytop.gd.app.core.device.DeviceState; import com.iflytop.gd.app.mapper.UserMapper; import com.iflytop.gd.app.model.entity.User; import com.iflytop.gd.common.enums.data.Deleted; import com.iflytop.gd.common.enums.data.FixedUser; -import lombok.Getter; import lombok.RequiredArgsConstructor; -import lombok.Setter; import org.springframework.stereotype.Service; import java.util.Arrays; @@ -27,9 +24,9 @@ public class UserService extends ServiceImpl { .toList(); for (Long id : ids) { User user = this.getById(id); - if (user != null && user.getFixedUser() != FixedUser.ENABLE) { + if (user != null && user.getFixedUser() != FixedUser.ENABLE && user.getDeleted() != Deleted.ENABLE) { user.setDeleted(Deleted.ENABLE); - return this.save(user); + return this.updateById(user); } } return true;