|
|
@ -1,20 +1,23 @@ |
|
|
|
package com.qyft.ms.app.device.spray; |
|
|
|
|
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.qyft.ms.app.common.constant.WebSocketMessageType; |
|
|
|
import com.qyft.ms.app.device.status.DeviceStatus; |
|
|
|
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.bo.SprayTaskSprayed; |
|
|
|
import com.qyft.ms.app.model.bo.SprayTaskStep; |
|
|
|
import com.qyft.ms.app.model.entity.Position; |
|
|
|
import com.qyft.ms.app.model.entity.SysSettings; |
|
|
|
import com.qyft.ms.app.service.PositionService; |
|
|
|
import com.qyft.ms.app.service.SysSettingsService; |
|
|
|
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 org.springframework.stereotype.Component; |
|
|
|
|
|
|
@ -33,8 +36,25 @@ public class SprayTaskExecutor { |
|
|
|
private final SprayTaskPointCollector sprayTaskPointCollector; |
|
|
|
private final SysSettingsService sysSettingsService; |
|
|
|
private final DeviceStatus deviceStatus; |
|
|
|
private final PositionService positionService; |
|
|
|
|
|
|
|
private Thread taskThread; |
|
|
|
private Double[][] slideArr; |
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
private void init() { |
|
|
|
Position slidePosition1 = positionService.getOne(new LambdaQueryWrapper<Position>().eq(Position::getPointCode, "slide_position1")); |
|
|
|
Position slidePosition2 = positionService.getOne(new LambdaQueryWrapper<Position>().eq(Position::getPointCode, "slide_position2")); |
|
|
|
Position slidePosition3 = positionService.getOne(new LambdaQueryWrapper<Position>().eq(Position::getPointCode, "slide_position3")); |
|
|
|
Position slidePosition4 = positionService.getOne(new LambdaQueryWrapper<Position>().eq(Position::getPointCode, "slide_position4")); |
|
|
|
slideArr = new Double[][]{ |
|
|
|
{slidePosition1.getX(), slidePosition1.getY()}, |
|
|
|
{slidePosition2.getX(), slidePosition2.getY()}, |
|
|
|
{slidePosition3.getX(), slidePosition3.getY()}, |
|
|
|
{slidePosition4.getX(), slidePosition4.getY()} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 启动任务线程,如果线程已存在且正在运行则不重复启动 |
|
|
@ -89,29 +109,40 @@ public class SprayTaskExecutor { |
|
|
|
List<Point2D> sprayStepList = new ArrayList<>(); |
|
|
|
sprayTask.setSuspendable(true);//可以暂停,单次喷涂范围内可以进行暂停 |
|
|
|
deviceStatus.setSuspendable(true); |
|
|
|
for (List<DeviceCommand> sprayStepCommands : sprayTaskStep.getSpraySteps()) {//单次喷涂 |
|
|
|
if (reCurrentStep < currentStep) { |
|
|
|
for (int i = 0; i < sprayTaskStep.getSpraySteps().size(); i++) {//单次喷涂 |
|
|
|
if (currentStep < reCurrentStep) { |
|
|
|
break; |
|
|
|
} |
|
|
|
List<DeviceCommand> sprayStepCommands = sprayTaskStep.getSpraySteps().get(i); |
|
|
|
List<CommandFuture> commandFutureList = new ArrayList<>(); |
|
|
|
for (DeviceCommand sprayStep : sprayStepCommands) { |
|
|
|
CommandFuture commandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayStep); |
|
|
|
commandFutureList.add(commandFuture); |
|
|
|
} |
|
|
|
|
|
|
|
CommandFuture[] commandFutureArray = commandFutureList.toArray(new CommandFuture[0]); |
|
|
|
sprayTaskPointCollector.startCollecting(sprayTaskStep.getIndex()); //开启点位推送 |
|
|
|
// sprayTaskPointCollector.startCollecting(sprayTaskStep.getIndex()); //开启点位推送 |
|
|
|
|
|
|
|
Point2D currentPoint = null; |
|
|
|
try { |
|
|
|
List<DeviceCommand> currentSprayStepCommands = sprayTaskStep.getSpraySteps().get(i - 1); |
|
|
|
double currentXPoint = (Double) currentSprayStepCommands.get(0).getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0]; |
|
|
|
double currentYPoint = 75.5 - (Double) currentSprayStepCommands.get(1).getParam().get("position"); |
|
|
|
currentPoint = new Point2D(currentXPoint, currentYPoint); |
|
|
|
} catch (Exception ignored) { |
|
|
|
} |
|
|
|
|
|
|
|
double nextXPoint = (Double) sprayStepCommands.get(0).getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0]; |
|
|
|
double nextYPoint = 75.5 - (Double) sprayStepCommands.get(1).getParam().get("position"); |
|
|
|
Point2D nextPoint = new Point2D(nextXPoint, nextYPoint); |
|
|
|
SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTaskStep.getIndex(), currentPoint, nextPoint); |
|
|
|
webSocketService.pushMsg(WebSocketMessageType.SPRAY_POINT, sprayTaskPointCollectorPushBO); |
|
|
|
commandWait(commandFutureArray); |
|
|
|
sprayTaskPointCollector.stopCollecting();//关闭点位推送 |
|
|
|
// sprayTaskPointCollector.stopCollecting();//关闭点位推送 |
|
|
|
currentStep++; |
|
|
|
sprayTask.setCurrentStep(currentStep);//将当前的喷涂进度缓存 |
|
|
|
//将当前点位缓存 |
|
|
|
DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet(); //生成电机XYZ相对原点坐标指令 |
|
|
|
CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXyzPositionGetCommand); |
|
|
|
commandWait(motorXyzPositionGetCommandFuture); |
|
|
|
JSONObject motorXyzPositionGetCommandResult = motorXyzPositionGetCommandFuture.getResponseResult(); |
|
|
|
Double xAxisPosition = motorXyzPositionGetCommandResult.getDouble("xAxisPosition"); |
|
|
|
Double yAxisPosition = motorXyzPositionGetCommandResult.getDouble("yAxisPosition"); |
|
|
|
sprayStepList.add(new Point2D(xAxisPosition, yAxisPosition)); |
|
|
|
sprayStepList.add(new Point2D(nextXPoint, nextYPoint)); |
|
|
|
} |
|
|
|
sprayTask.setSuspendable(false);//不可暂停 |
|
|
|
deviceStatus.setSuspendable(false); |
|
|
|