diff --git a/matrix-spray.db b/matrix-spray.db index d046a76..71ea234 100644 Binary files a/matrix-spray.db and b/matrix-spray.db differ 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