From 28df7537cb6b3c348f8abf1c05cf8741f0866d38 Mon Sep 17 00:00:00 2001 From: guoapeng Date: Thu, 6 Mar 2025 04:39:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=B0=83=E8=AF=95bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- matrix-spray.db | Bin 36864 -> 36864 bytes .../com/qyft/ms/app/controller/CMDController.java | 2 +- .../java/com/qyft/ms/app/service/CMDService.java | 78 +++++++++++++++------ .../app/service/impl/ISysSettingsServiceImpl.java | 4 +- 4 files changed, 58 insertions(+), 26 deletions(-) diff --git a/matrix-spray.db b/matrix-spray.db index d046a7633296c46f5958ddb0641b19f3e5c76a18..71ea234441f63eb5bebf9bef6e9b1944db7c97c8 100644 GIT binary patch delta 495 zcmZozz|^pSX@WFk<3t%}#>R~aPWp_3n-}XRI*4(yZ)4!+;1l4L;8Eb#bl$iT={*T7iU07cT$#N5(ZfP;ZSl#{{H-N?w;1g_3B#K_pnz|zXpNYB#H zz|g`FRmK!3X{cvzWMOG!VrF2_Si%oz%SK?D)kOC@E zeBQVFd1t%vlfAvq_pU3>$xKPrX9a6kpUmGUBWY;~(rf_H$ZyBMqR#@Aeb_6*YHkFS zogCQr&T%CJC#R~m_;YKXCdF{l8A#V7ynmEq7~g{lE^m@Et@2llye+lv0p~e0A?%$1JqccZ5%qxP-7eV PWmt^Nbqpro=+^)MOQk{w diff --git a/src/main/java/com/qyft/ms/app/controller/CMDController.java b/src/main/java/com/qyft/ms/app/controller/CMDController.java index 7f2a0ee..ef2aea2 100644 --- a/src/main/java/com/qyft/ms/app/controller/CMDController.java +++ b/src/main/java/com/qyft/ms/app/controller/CMDController.java @@ -165,7 +165,7 @@ public class CMDController { } } - @Operation(summary = "以指定转速、方向和时间开启注射泵") + @Operation(summary = "以指定转速、方向开启注射泵") @PostMapping("/turnOnSyringePump") public Result turnOnSyringePump(@RequestBody CMDForm cmdForm) { try { diff --git a/src/main/java/com/qyft/ms/app/service/CMDService.java b/src/main/java/com/qyft/ms/app/service/CMDService.java index baa37d2..330c698 100644 --- a/src/main/java/com/qyft/ms/app/service/CMDService.java +++ b/src/main/java/com/qyft/ms/app/service/CMDService.java @@ -121,7 +121,12 @@ public class CMDService { .map(Number.class::cast) .map(Number::doubleValue) .orElse(0.0); - cmdList.add(() -> deviceTcpCMDService.turnOnSyringePump(rotationSpeed)); + int direction = (int) params.get("direction"); + if(direction == 0) { + rotationSpeed = -rotationSpeed; + } + double finalRotationSpeed = rotationSpeed; + cmdList.add(() -> deviceTcpCMDService.turnOnSyringePump(finalRotationSpeed)); initExecutorThread(cmdList, form); return true; } @@ -190,9 +195,6 @@ public class CMDService { cmdList.add(() -> deviceTcpCMDService.setMotorSpeed("Z", 10)); // 回到原点 - cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("Z", 5)); - cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("X", 5)); - cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("Y", 5)); cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("Z")); cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("X")); @@ -225,7 +227,7 @@ public class CMDService { List horizontalPath = generatePathPoints( left, right, top, bottom, space, routeType == 1 ? PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN : PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT ); - log.info("horizontalPath:{}", horizontalPath); + log.info("horizontalPath:{}", JSONUtil.toJsonStr(horizontalPath)); if(horizontalPath.isEmpty()) { return "路径规划失败"; } @@ -239,9 +241,10 @@ public class CMDService { if(height < 15) { return "高度设置太低,有撞针的风险"; } - cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("Z",z - height )); + cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("X", left)); cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("Y", top)); + cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("Z",z - height )); // 是否加电 电压 Object voltage = params.get("voltage"); @@ -271,27 +274,37 @@ public class CMDService { return true; }); } - + double currentX = left; + double currentY = top; // 执行轨迹 for (PathGenerator.Points point : horizontalPath) { double nextX = (int) point.getX(); double nextY = (int) point.getY(); log.info("当前喷针位置x:{}, y:{}", nextX, nextY ); - cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("X", nextX)); - cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("Y", nextY)); + if (currentX != nextX) { + cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("X", nextX)); + } + if (currentY != nextY) { + cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("Y", nextY)); + } +// cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("X", nextX)); +// cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("Y", nextY)); + currentX= nextX; + currentY= nextY; } // 停止喷涂 cmdList.add(deviceTcpCMDService::turnOffSyringePump); // 关闭喷嘴阀 - cmdList.add(() -> deviceTcpCMDService.controlValve("Nozzle", true)); + cmdList.add(() -> deviceTcpCMDService.controlValve("Nozzle", false)); } // 关闭高压 cmdList.add(deviceTcpCMDService::turnOffHighVoltage); // 回到原点 + cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("Z")); cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("X")); cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("Y")); - cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("Z")); + // 结束日志 cmdList.add( () -> { @@ -366,8 +379,10 @@ public class CMDService { // 关闭喷嘴阀 cmdList.add(() -> deviceTcpCMDService.controlValve("Nozzle", true)); // 回到原点 - cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("X")); cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("Z")); + cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("X")); + cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("Y")); + // 结束日志 cmdList.add( () -> { OperationLog operationLog = operationLogService.getIng(); @@ -400,17 +415,23 @@ public class CMDService { Map params = form.getParams(); String type = (String) params.get("type"); + cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("Z")); + cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("X")); + cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("Y")); + + Map wasteLiquorPosition = sysSettingsService.getWasteLiquorPosition(); + + cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("X", wasteLiquorPosition.get("x"))); + cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("Z", wasteLiquorPosition.get("z"))); + // type: "injector" | "nozzle" if(Objects.equals(type, "injector")) { cmdList.add(() -> deviceTcpCMDService.switchThreeWayValve("clear_spray")); - cmdList.add(() -> deviceTcpCMDService.controlValve("Cleaning", true)); + cmdList.add(() -> deviceTcpCMDService.turnOnSyringePump(1000)); } else if (Objects.equals(type, "nozzle")) { - Map wasteLiquorPosition = sysSettingsService.getWasteLiquorPosition(); - cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("X", wasteLiquorPosition.get("x"))); - cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("Y", wasteLiquorPosition.get("y"))); - cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("Z", wasteLiquorPosition.get("z"))); + cmdList.add(() -> deviceTcpCMDService.switchThreeWayValve("clear_nozzle")); - cmdList.add(() -> deviceTcpCMDService.controlValve("Nozzle", true)); + cmdList.add(() -> deviceTcpCMDService.controlValve("Cleaning", true)); } cmdList.add(() -> { sysSettingsService.updateWorkStatus("washing"); @@ -426,6 +447,7 @@ public class CMDService { cmdList.add(() -> deviceTcpCMDService.switchThreeWayValve("close_all")); cmdList.add(() -> deviceTcpCMDService.controlValve("Cleaning", false)); cmdList.add(() -> deviceTcpCMDService.controlValve("Nozzle", false)); + cmdList.add(deviceTcpCMDService::turnOffSyringePump); cmdList.add(() -> { sysSettingsService.updateWorkStatus("idle"); return true; @@ -462,11 +484,15 @@ public class CMDService { public boolean startPrefill(CMDForm form) { List> cmdList = new ArrayList<>(); Map params = form.getParams(); - +double rotationSpeed = Optional.ofNullable(params.get("rotationSpeed")) + .filter(Number.class::isInstance) + .map(Number.class::cast) + .map(Number::doubleValue) + .orElse(0.0); cmdList.add(() -> deviceTcpCMDService.switchThreeWayValve("clear_spray")); cmdList.add(() -> deviceTcpCMDService.controlValve("Nozzle", true)); - cmdList.add(() -> deviceTcpCMDService.turnOnSyringePump((Double) params.get("rotationSpeed"))); + cmdList.add(() -> deviceTcpCMDService.turnOnSyringePump(rotationSpeed)); cmdList.add(() -> { sysSettingsService.updateWorkStatus("prefilling"); return true; @@ -517,7 +543,9 @@ public class CMDService { while (true) { double targetHumidity = sysSettingsService.getTargetHumidity(); DeviceStatus deviceStatus = deviceStatusService.getDeviceStatus(); - if (deviceStatus.getHumidity()<=targetHumidity ) { +// log.info("当前湿度:{}", deviceStatus.getHumidity()); +// log.info("目标湿度:{}", targetHumidity); + if (deviceStatus.getHumidity()<=targetHumidity) { deviceTcpCMDService.controlValve("Dehumidification", false); sysSettingsService.updateWorkStatus("idle"); Map result = new HashMap<>(); @@ -561,17 +589,20 @@ public class CMDService { return true; } - // 托盘推入 + // 托盘推出 public boolean trayOut(CMDForm form) { List> cmdList = new ArrayList<>(); + cmdList.add(() -> deviceTcpCMDService.setMotorSpeed("Y", 20)); cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("Y", 150)); + initExecutorThread(cmdList, form); return true; } - // 托盘推出 + // 托盘推入 public boolean trayIn(CMDForm form) { List> cmdList = new ArrayList<>(); + cmdList.add(() -> deviceTcpCMDService.setMotorSpeed("Y", 20)); cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("Y", 0)); initExecutorThread(cmdList, form); return true; @@ -604,6 +635,7 @@ public class CMDService { executionResult.setStatus(CMDResultCode.SUCCESS.getCode()); executionResult.setMessage(CMDResultCode.SUCCESS.getMsg()); webSocketService.pushMsg(WebSocketMessageType.CMD, executionResult); + } } diff --git a/src/main/java/com/qyft/ms/app/service/impl/ISysSettingsServiceImpl.java b/src/main/java/com/qyft/ms/app/service/impl/ISysSettingsServiceImpl.java index f7e66ab..a96ab15 100644 --- a/src/main/java/com/qyft/ms/app/service/impl/ISysSettingsServiceImpl.java +++ b/src/main/java/com/qyft/ms/app/service/impl/ISysSettingsServiceImpl.java @@ -47,8 +47,8 @@ public class ISysSettingsServiceImpl extends ServiceImpl