From c192360fc2ff72dbabb90bf06e220481bd4c243c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Wed, 19 Mar 2025 19:41:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=9B=9E=E6=98=BE=E7=BB=99=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E7=9A=84=E5=9D=90=E6=A0=87=E9=9C=80=E8=A6=81=E7=BB=8F?= =?UTF-8?q?=E8=BF=87=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/device/spray/SprayTaskPointCollector.java | 24 +++++++++++++++++++++- .../service/device/DeviceCommandService.java | 24 ++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/qyft/ms/app/device/spray/SprayTaskPointCollector.java b/src/main/java/com/qyft/ms/app/device/spray/SprayTaskPointCollector.java index f3f876d..724cf7c 100644 --- a/src/main/java/com/qyft/ms/app/device/spray/SprayTaskPointCollector.java +++ b/src/main/java/com/qyft/ms/app/device/spray/SprayTaskPointCollector.java @@ -2,15 +2,19 @@ package com.qyft.ms.app.device.spray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.qyft.ms.app.common.constant.WebSocketMessageType; import com.qyft.ms.app.device.status.SprayTask; import com.qyft.ms.app.model.bo.Point2D; import com.qyft.ms.app.model.bo.SprayTaskPointCollectorPushBO; +import com.qyft.ms.app.model.entity.Position; +import com.qyft.ms.app.service.PositionService; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; import com.qyft.ms.system.model.bo.DeviceCommand; import com.qyft.ms.system.service.WebSocketService; import com.qyft.ms.system.service.device.DeviceCommandService; +import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.TaskScheduler; @@ -26,6 +30,7 @@ import java.util.concurrent.ScheduledFuture; public class SprayTaskPointCollector { private final WebSocketService webSocketService; private final DeviceCommandService deviceCommandService; + private final PositionService positionService; private final TaskScheduler taskScheduler; @@ -33,6 +38,21 @@ public class SprayTaskPointCollector { private int currentSprayIndex; + private Double[][] slideArr; + + @PostConstruct + private void init(){ + Position slidePosition1 = positionService.getOne(new LambdaQueryWrapper().eq(Position::getPointCode, "slide_position1")); + Position slidePosition2 = positionService.getOne(new LambdaQueryWrapper().eq(Position::getPointCode, "slide_position2")); + Position slidePosition3 = positionService.getOne(new LambdaQueryWrapper().eq(Position::getPointCode, "slide_position3")); + Position slidePosition4 = positionService.getOne(new LambdaQueryWrapper().eq(Position::getPointCode, "slide_position4")); + slideArr = new Double[][] { + {slidePosition1.getX(), slidePosition1.getY()}, + {slidePosition2.getX(), slidePosition2.getY()}, + {slidePosition3.getX(), slidePosition3.getY()}, + {slidePosition4.getX(), slidePosition4.getY()} + }; + } public void startCollecting(int currentSprayIndex) { if (scheduledFuture == null || scheduledFuture.isCancelled()) { @@ -60,10 +80,12 @@ public class SprayTaskPointCollector { stopCollecting(); } DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet(); //生成电机XYZ相对原点坐标指令 - CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommand(motorXyzPositionGetCommand); + CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommandNoFront(motorXyzPositionGetCommand); JSONObject motorXyzPositionGetCommandResult = motorXyzPositionGetCommandFuture.getResponseResult(); Double xAxisPosition = motorXyzPositionGetCommandResult.getDouble("xAxisPosition"); Double yAxisPosition = motorXyzPositionGetCommandResult.getDouble("yAxisPosition"); + xAxisPosition = xAxisPosition - slideArr[currentSprayIndex][0]; + yAxisPosition = 75.5 - yAxisPosition; Point2D point2D = new Point2D(xAxisPosition, yAxisPosition); SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(currentSprayIndex, point2D); log.info("喷涂点位采集,采集到点位:{}", JSONUtil.toJsonStr(sprayTaskPointCollectorPushBO)); diff --git a/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java b/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java index c0a0771..3c90c11 100644 --- a/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java +++ b/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java @@ -41,6 +41,30 @@ public class DeviceCommandService { return cmdFuture; } + + public CommandFuture sendCommandNoFront(DeviceCommand deviceCommand) { + CommandFuture commandFuture = executeCommand(deviceCommand); + commandFuture.getAckFuture().thenApply(result -> { + Boolean status = result.getBool("status"); + if (!status) { //ack失败 + String message = deviceCommand.getCommandName() + "指令,设备ack错误"; + throw new RuntimeException(message); + } + return result; + }); + + commandFuture.getResponseFuture().thenApply(result -> { + Boolean status = result.getBool("status"); + if (!status) { //response失败 + String message = deviceCommand.getCommandName() + "指令,设备response错误"; + throw new RuntimeException(message); + } + return result.get("data"); + }); + + return commandFuture; + } + public CommandFuture sendCommand(DeviceCommand deviceCommand) throws IOException { return sendCommand(deviceCommand, null, null); }