Browse Source

feat:新喷涂配置实现

master
白凤吉 3 weeks ago
parent
commit
4e8d249061
  1. 42
      src/main/java/com/qyft/ms/app/common/generator/PathGenerator.java
  2. 5
      src/main/java/com/qyft/ms/app/controller/SprayTaskController.java
  3. 213
      src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java
  4. 300
      src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor_bak.java
  5. 2
      src/main/java/com/qyft/ms/app/device/status/DeviceStatus.java
  6. 111
      src/main/java/com/qyft/ms/app/device/status/SprayTask.java
  7. 150
      src/main/java/com/qyft/ms/app/device/status/SprayTask_bak.java
  8. 192
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayChangeParam.java
  9. 134
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayContinue.java
  10. 128
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayPause.java
  11. 38
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart.java
  12. 730
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart_bak.java
  13. 6
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStop.java
  14. 4
      src/main/java/com/qyft/ms/app/model/bo/Point2D.java
  15. 10
      src/main/java/com/qyft/ms/app/model/bo/SprayTaskStep.java
  16. 6
      src/main/java/com/qyft/ms/app/model/bo/SprayTimes.java
  17. 15
      src/main/java/com/qyft/ms/app/service/SprayTaskService.java
  18. 8
      src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java

42
src/main/java/com/qyft/ms/app/common/generator/PathGenerator.java

@ -1,5 +1,6 @@
package com.qyft.ms.app.common.generator;
import com.qyft.ms.app.model.bo.Point2D;
import lombok.Getter;
import java.util.ArrayList;
@ -24,7 +25,7 @@ public class PathGenerator {
* @param mode HORIZONTAL_ZIGZAG_TOP_DOWN VERTICAL_ZIGZAG_LEFT_RIGHT
* @return 之字形路径拐点列表 (每个拐点是 (x,y) 的int坐标)
*/
public static List<Points> generatePathPoints(
public static List<Point2D> generatePathPoints(
double left,
double right,
double top,
@ -77,7 +78,7 @@ public class PathGenerator {
* 4) 下移 spacing
* 重复直到无法再下移
*/
private static List<Points> generateHorizontalZigzagTopDown(
private static List<Point2D> generateHorizontalZigzagTopDown(
double effLeft,
double effRight,
double effTop,
@ -85,13 +86,13 @@ public class PathGenerator {
double spacing
) {
List<Points> result = new ArrayList<>();
List<Point2D> result = new ArrayList<>();
double currentX = effLeft;
double currentY = effTop;
boolean goingRight = true;
// 起点
result.add(new Points(currentX, currentY));
result.add(new Point2D(currentX, currentY));
while (true) {
// 水平移动到对侧
@ -100,7 +101,7 @@ public class PathGenerator {
} else {
currentX = effLeft;
}
result.add(new Points(currentX, currentY));
result.add(new Point2D(currentX, currentY));
// 往下移动 spacing
double nextY = currentY + spacing;
@ -108,7 +109,7 @@ public class PathGenerator {
break; // 无法再往下
}
currentY = nextY;
result.add(new Points(currentX, currentY));
result.add(new Point2D(currentX, currentY));
// 反转方向
goingRight = !goingRight;
@ -127,20 +128,20 @@ public class PathGenerator {
* 4) 右移 spacing
* 重复直到无法再右移
*/
private static List<Points> generateVerticalZigzagLeftRight(
private static List<Point2D> generateVerticalZigzagLeftRight(
double effLeft,
double effRight,
double effTop,
double effBottom,
double spacing
) {
List<Points> result = new ArrayList<>();
List<Point2D> result = new ArrayList<>();
double currentX = effLeft;
double currentY = effTop;
boolean goingDown = true; // 第一列先从上往下
// 起点
result.add(new Points(currentX, currentY));
result.add(new Point2D(currentX, currentY));
while (true) {
// 垂直移动到对侧
@ -149,7 +150,7 @@ public class PathGenerator {
} else {
currentY = effTop;
}
result.add(new Points(currentX, currentY));
result.add(new Point2D(currentX, currentY));
// 向右移动 spacing
double nextX = currentX + spacing;
@ -157,7 +158,7 @@ public class PathGenerator {
break; // 无法再右移
}
currentX = nextX;
result.add(new Points(currentX, currentY));
result.add(new Point2D(currentX, currentY));
// 反转
goingDown = !goingDown;
@ -173,19 +174,19 @@ public class PathGenerator {
// 1) 测试水平之字形(从上往下)
System.out.println("=== HORIZONTAL_ZIGZAG_TOP_DOWN ===");
List<Points> horizontalPath = generatePathPoints(
List<Point2D> horizontalPath = generatePathPoints(
left, right, top, bottom, spacing, MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN
);
for (Points p : horizontalPath) {
for (Point2D p : horizontalPath) {
System.out.println(p.x + "," + p.y);
}
// 2) 测试垂直之字形(从左往右)
System.out.println("\n=== VERTICAL_ZIGZAG_LEFT_RIGHT ===");
List<Points> verticalPath = generatePathPoints(
List<Point2D> verticalPath = generatePathPoints(
left, right, top, bottom, spacing, MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT
);
for (Points p : verticalPath) {
for (Point2D p : verticalPath) {
System.out.println(p.x + "," + p.y);
}
}
@ -207,14 +208,5 @@ public class PathGenerator {
VERTICAL_ZIGZAG_LEFT_RIGHT
}
@Getter
public static class Points {
double x;
double y;
public Points(double x, double y) {
this.x = x;
this.y = y;
}
}
}

5
src/main/java/com/qyft/ms/app/controller/SprayTaskController.java

@ -29,14 +29,15 @@ public class SprayTaskController {
SprayTaskStatusVO sprayTaskStatusVO = new SprayTaskStatusVO();
sprayTaskStatusVO.setCmdId(sprayTask.getCmdId());
sprayTaskStatusVO.setCmdCode(sprayTask.getCmdCode());
sprayTaskStatusVO.setSprayTaskSprayedList(sprayTask.getSprayTaskSprayedList());
sprayTaskStatusVO.setSprayParams(sprayTask.getCacheParams());
// sprayTaskStatusVO.setSprayTaskSprayedList(sprayTask.getSprayTaskSprayedList());
// sprayTaskStatusVO.setSprayParams(sprayTask.getCacheParams());
return Result.success(sprayTaskStatusVO);
}
@Operation(summary = "设置喷涂参数")
@PostMapping("/set-params")
public Result<?> setSprayParams(@RequestBody SetSprayTaskParamsDTO setSprayTaskParamsDTO) {
sprayTaskService.setSprayParams(setSprayTaskParamsDTO);
return Result.success();
}

213
src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java

@ -2,12 +2,10 @@ package com.qyft.ms.app.device.spray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qyft.ms.app.common.constant.WebSocketMessageType;
import com.qyft.ms.app.common.generator.PathGenerator;
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.bo.*;
import com.qyft.ms.app.model.entity.Position;
import com.qyft.ms.app.model.entity.SysSettings;
import com.qyft.ms.app.service.PositionService;
@ -29,6 +27,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@ -73,100 +72,81 @@ public class SprayTaskExecutor {
taskThread = new Thread(() -> {
try {
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.START, "喷涂任务开始执行"));
int reCurrentStep = sprayTask.getCurrentStep();
List<SprayTaskParams> sprayTaskParams = sprayTask.getSprayTaskParams();
DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenNozzlePipeline();//打开三通阀注射器管路
CommandFuture threeWayValveOpenSyringePipelineCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), threeWayValveOpenSyringePipelineCommand);
commandWait(threeWayValveOpenSyringePipelineCommandFuture);
DeviceCommand nozzleValveOpenCommand = DeviceCommandGenerator.nozzleValveOpen();//开启喷嘴阀
CommandFuture nozzleValveOpenCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), nozzleValveOpenCommand);
commandWait(nozzleValveOpenCommandFuture);
int currentStep = 0; //当前喷涂步骤
int sprayCount = 0;
int sprayNum = 1;
int currentIndex = 0;
for (SprayTaskStep sprayTaskStep : sprayTask.getSprayTaskStepList()) {//循环进行多次喷涂
if (!sprayTask.isFirstImmobility()) {
for (SprayTaskParams sprayTaskParam : sprayTaskParams) {//循环玻片
for (SprayTimes sprayTimes : sprayTaskParam.getTimes()) {//每个拨片有多次喷涂循环每次喷涂
List<SprayTaskStep> sprayTaskStepList = getSprayPath(sprayTaskParam.getIndex(), sprayTimes);//计算本次喷涂的路线
//先移动到玻片位置
DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(slideArr[sprayTaskStep.getIndex()][0], 20.0);
DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(75.5 - slideArr[sprayTaskStep.getIndex()][1], 20.0);
DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(slideArr[sprayTaskParam.getIndex()][0], 20.0);
DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(75.5 - slideArr[sprayTaskParam.getIndex()][1], 20.0);
CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXPositionSetCommand);
CommandFuture motorYPositionSetCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYPositionSetCommand);
SysSettings slideHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper<SysSettings>().eq(SysSettings::getCode, "slide_height"));
Double slideHeight = Double.parseDouble(slideHeightSysSettings.getValue());
Double height = slideHeight - sprayTask.getSprayParams().getMotorZHeight();//下降z轴高度
Double height = slideHeight - sprayTimes.getMotorZHeight();//下降z轴高度
DeviceCommand motorZPositionSetAboveSlideCommand = DeviceCommandGenerator.motorZPositionSet(height, 15.0);
CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand);
commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture, motorZPositionSetAboveSlideCommandFuture);
}
Thread.sleep(100);
sprayTask.setSuspendable(true);//可以暂停单次喷涂范围内可以进行暂停
deviceStatus.setSuspendable(true);
double cacheXPoint = -1;
double cacheYPoint = -1;
DecimalFormat df = new DecimalFormat("#.##");
for (int i = 0; i < sprayTaskStep.getSpraySteps().size(); i++) {//单次喷涂
if (currentIndex != sprayTaskStep.getIndex()) {
sprayNum = 0;
currentIndex = sprayTaskStep.getIndex();
}
if (currentStep < reCurrentStep) {
currentStep++;
continue;
}
if(i == 1){
DeviceCommand syringePumpForwardCommand = DeviceCommandGenerator.syringePumpForward(sprayTask.getSprayParams().getVolume());//推动移动注射泵
Thread.sleep(100);
double cacheXPoint = -1;
double cacheYPoint = -1;
sprayNum++;
for (SprayTaskStep sprayTaskStep : sprayTaskStepList) {//因为田字格喷涂其实是两次
if (sprayTimes.getHighVoltage()) {//加电
DeviceCommand highVoltageOpenCommand = DeviceCommandGenerator.highVoltageOpen(sprayTimes.getHighVoltageValue());//开启高压
CommandFuture highVoltageOpenCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), highVoltageOpenCommand);
commandWait(highVoltageOpenCommandFuture);
}
DeviceCommand syringePumpForwardCommand = DeviceCommandGenerator.syringePumpForward(sprayTimes.getVolume());//推动移动注射泵
CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpForwardCommand);
commandWait(syringePumpForwardCommandFuture);
for (int i = 0; i < sprayTaskStep.getSprayPathPointList().size(); i++) {//循环路线
Point2D currentPoint = sprayTaskStep.getSprayPathPointList().get(i);
List<CommandFuture> commandFutureList = new ArrayList<>();
if (cacheXPoint != currentPoint.x) {
DeviceCommand deviceCommand = DeviceCommandGenerator.motorXPositionSet(currentPoint.x, sprayTimes.getMovingSpeed());
CommandFuture commandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), deviceCommand);
commandFutureList.add(commandFuture);
cacheXPoint = currentPoint.x;
}
if (cacheYPoint != currentPoint.y) {
DeviceCommand deviceCommand = DeviceCommandGenerator.motorXPositionSet(currentPoint.y, sprayTimes.getMovingSpeed());
CommandFuture commandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), deviceCommand);
commandFutureList.add(commandFuture);
cacheYPoint = currentPoint.y;
}
SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayTaskParam.getIndex(), sprayNum, sprayCount, currentPoint);
webSocketService.pushMsg(WebSocketMessageType.SPRAY_POINT, sprayTaskPointCollectorPushBO);//向前端推送当前路径
CommandFuture[] commandFutureArray = commandFutureList.toArray(new CommandFuture[0]);
commandWait(commandFutureArray);
currentStep++;//当前喷涂步数自增
}
//一次喷涂完毕后停止推注射泵
DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop();//停止推动注射泵
CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpStopCommand);
commandWait(syringePumpStopCommandFuture);
}
sprayTask.setFirstImmobility(true);
List<DeviceCommand> sprayStepCommands = sprayTaskStep.getSpraySteps().get(i);
DeviceCommand xSprayStepCommands = sprayStepCommands.get(0);
xSprayStepCommands.getParam().put("speed", sprayTask.getSprayParams().getMovingSpeed());//防止修改了移动速度这里重新设置移动速度
DeviceCommand ySprayStepCommands = sprayStepCommands.get(1);
ySprayStepCommands.getParam().put("speed", sprayTask.getSprayParams().getMovingSpeed());
List<CommandFuture> commandFutureList = new ArrayList<>();
double aXPoint = (double) xSprayStepCommands.getParam().get("position");
double aYPoint = (double) ySprayStepCommands.getParam().get("position");
xSprayStepCommands.getParam().put("position", Double.parseDouble(df.format(aXPoint)));
ySprayStepCommands.getParam().put("position", Double.parseDouble(df.format(aYPoint)));
if (cacheXPoint != aXPoint) {
CommandFuture commandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), xSprayStepCommands);
commandFutureList.add(commandFuture);
cacheXPoint = aXPoint;
}
if (cacheYPoint != aYPoint) {
CommandFuture commandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), ySprayStepCommands);
commandFutureList.add(commandFuture);
cacheYPoint = aYPoint;
}
CommandFuture[] commandFutureArray = commandFutureList.toArray(new CommandFuture[0]);
double currentXPoint = Double.parseDouble(df.format((Double) xSprayStepCommands.getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0]));
double currentYPoint = Double.parseDouble(df.format(75.5 - (Double) ySprayStepCommands.getParam().get("position")));
Point2D currentPoint = new Point2D(currentXPoint, currentYPoint);
SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayTaskStep.getIndex(), sprayNum, sprayCount, currentPoint);
webSocketService.pushMsg(WebSocketMessageType.SPRAY_POINT, sprayTaskPointCollectorPushBO);
//将当前点位缓存
SprayTaskSprayed sprayTaskSprayed = new SprayTaskSprayed();
sprayTaskSprayed.setNumber(sprayNum);
sprayTaskSprayed.setIndex(sprayTaskStep.getIndex());
sprayTaskSprayed.setSprayCount(sprayCount);
sprayTaskSprayed.setSprayedPoints(new Point2D(Double.parseDouble(df.format(aXPoint - slideArr[sprayTaskStep.getIndex()][0])), Double.parseDouble(df.format(75.5 - aYPoint))));
sprayTask.addSprayTaskSprayed(sprayTaskSprayed);
commandWait(commandFutureArray);
currentStep++;
sprayTask.setCurrentStep(currentStep);//将当前的喷涂进度缓存
sprayCount++;
sprayNum++;
}
sprayTask.setSuspendable(false);//不可暂停
deviceStatus.setSuspendable(false);
if (currentStep >= reCurrentStep) {
DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop();//停止推动注射泵
CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpStopCommand);
commandWait(syringePumpStopCommandFuture);
}
sprayCount++;
sprayNum++;
}
//喷涂完毕
DeviceCommand highVoltageCloseCommand = DeviceCommandGenerator.highVoltageClose();//关闭高压
CommandFuture highVoltageCloseCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), highVoltageCloseCommand);
commandWait(highVoltageCloseCommandFuture);
@ -184,14 +164,8 @@ public class SprayTaskExecutor {
CommandFuture motorZOriginCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZOriginCommand);
commandWait(motorXOriginCommandFuture, motorYOriginCommandFuture, motorZOriginCommandFuture);
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SUCCESS, "喷涂任务执行成功"));
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束"));
SprayTask.getInstance().clear();
deviceStatus.setSpraying(false);//是否正在进行喷涂
deviceStatus.setPaused(false);//是否暂停
deviceStatus.setSuspendable(false);//是否可以暂停
} catch (InterruptedException e) {
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SEND, "喷涂任务线程停止"));
} catch (Exception e) {
@ -200,10 +174,11 @@ public class SprayTaskExecutor {
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束"));
SprayTask.getInstance().clear();
} finally {
SprayTask.getInstance().clear();
deviceStatus.setSpraying(false);
deviceStatus.setPaused(false);
deviceStatus.setSuspendable(false);
} finally {
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SEND, "喷涂任务线程退出"));
// 在线程结束后将 taskThread 设置为 null保证状态一致和资源释放
synchronized (this) {
@ -216,9 +191,6 @@ public class SprayTaskExecutor {
/**
* 停止任务线程
* 1. 直接中断线程不再关心 CompletableFuture 的等待和结果
* 2. 可选择等待一定时间让线程自行退出 join 超时 2
* 3. 清空线程引用防止内存泄露
*/
public synchronized void stopTask() {
if (taskThread != null && taskThread.isAlive()) {
@ -236,4 +208,65 @@ public class SprayTaskExecutor {
.orTimeout(120, TimeUnit.SECONDS)
.get();
}
private List<SprayTaskStep> getSprayPath(Integer index, SprayTimes sprayTimes) {
String matrixPathType = sprayTimes.getMatrixPathType();
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"));
Double[][] slideArr = {
{slidePosition1.getX(), slidePosition1.getY()},
{slidePosition2.getX(), slidePosition2.getY()},
{slidePosition3.getX(), slidePosition3.getY()},
{slidePosition4.getX(), slidePosition4.getY()}
};
Double[] upperLeft = {sprayTimes.getX1(), sprayTimes.getY1()}; //范围左上角 x1y1
Double[] lowerRight = {sprayTimes.getX2(), sprayTimes.getY2()}; //范围左上角 x1y1
Double[] slide = slideArr[index];//获取玻片的坐标
DecimalFormat df = new DecimalFormat("#.##");
double left = Double.parseDouble(df.format(slide[0] + upperLeft[0]));
double right = Double.parseDouble(df.format(slide[0] + lowerRight[0]));
double top = Double.parseDouble(df.format(slide[1] + upperLeft[1]));
double bottom = Double.parseDouble(df.format(slide[1] + lowerRight[1]));
Double spacing = sprayTimes.getSpacing();
List<SprayTaskStep> sprayTaskStepList = new CopyOnWriteArrayList<>();
if ("horizontal".equals(matrixPathType)) {//喷涂路径类型 horizontal 横向 | vertical 纵向 | grid 网格先横向后纵向
List<Point2D> pathList = PathGenerator.generatePathPoints(
left, right, top, bottom,
spacing,
PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN
);
SprayTaskStep sprayTaskStep = new SprayTaskStep();
sprayTaskStep.setSprayPathPointList(pathList);
sprayTaskStepList.add(sprayTaskStep);
} else if ("vertical".equals(matrixPathType)) {
List<Point2D> pathList = PathGenerator.generatePathPoints(
left, right, top, bottom,
spacing,
PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT
);
SprayTaskStep sprayTaskStep = new SprayTaskStep();
sprayTaskStep.setSprayPathPointList(pathList);
sprayTaskStepList.add(sprayTaskStep);
} else if ("grid".equals(matrixPathType)) {
List<Point2D> pathList1 = PathGenerator.generatePathPoints(
left, right, top, bottom,
spacing,
PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN
);
SprayTaskStep sprayTaskStep1 = new SprayTaskStep();
sprayTaskStep1.setSprayPathPointList(pathList1);
sprayTaskStepList.add(sprayTaskStep1);
List<Point2D> pathList2 = PathGenerator.generatePathPoints(
left, right, top, bottom,
spacing,
PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT
);
SprayTaskStep sprayTaskStep2 = new SprayTaskStep();
sprayTaskStep2.setSprayPathPointList(pathList2);
sprayTaskStepList.add(sprayTaskStep2);
}
return sprayTaskStepList;
}
}

300
src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor_bak.java

@ -0,0 +1,300 @@
//package com.qyft.ms.app.device.spray;
//
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.qyft.ms.app.common.constant.WebSocketMessageType;
//import com.qyft.ms.app.common.generator.PathGenerator;
//import com.qyft.ms.app.device.status.DeviceStatus;
//import com.qyft.ms.app.device.status.SprayTask;
//import com.qyft.ms.app.model.bo.*;
//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.constant.CommandStatus;
//import com.qyft.ms.system.common.device.command.CommandFuture;
//import com.qyft.ms.system.common.device.command.DeviceCommandGenerator;
//import com.qyft.ms.system.common.device.command.FrontResponseGenerator;
//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.stereotype.Component;
//
//import java.text.DecimalFormat;
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.List;
//import java.util.concurrent.CompletableFuture;
//import java.util.concurrent.CopyOnWriteArrayList;
//import java.util.concurrent.ExecutionException;
//import java.util.concurrent.TimeUnit;
//
//@Slf4j
//@Component
//@RequiredArgsConstructor
//public class SprayTaskExecutor_bak {
// private final WebSocketService webSocketService;
// private final DeviceCommandService deviceCommandService;
// private final SysSettingsService sysSettingsService;
// private final DeviceStatus deviceStatus;
// private final PositionService positionService;
//
// private Thread taskThread;
// private Double[][] slideArr;
//
// @PostConstruct
// public 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()}
// };
// }
//
//
// /**
// * 启动任务线程如果线程已存在且正在运行则不重复启动
// */
// public synchronized void startTask() {
// SprayTask sprayTask = SprayTask.getInstance();
// if (taskThread != null && taskThread.isAlive()) {
// webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.DEVICE_ERROR, "设备正在喷涂,请先停止喷涂"));
// return;
// }
//
// taskThread = new Thread(() -> {
// try {
// int reCurrentStep = sprayTask.getCurrentStep();
// int currentStep = 0; //当前喷涂步骤
// int sprayCount = 0;
// int sprayNum = 1;
// int currentIndex = 0;
// for (SprayTaskStep sprayTaskStep : sprayTask.getSprayTaskStepList()) {//循环进行多次喷涂
// if (!sprayTask.isFirstImmobility()) {
// //先移动到玻片位置
// DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(slideArr[sprayTaskStep.getIndex()][0], 20.0);
// DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(75.5 - slideArr[sprayTaskStep.getIndex()][1], 20.0);
// CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXPositionSetCommand);
// CommandFuture motorYPositionSetCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYPositionSetCommand);
//
// SysSettings slideHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper<SysSettings>().eq(SysSettings::getCode, "slide_height"));
// Double slideHeight = Double.parseDouble(slideHeightSysSettings.getValue());
// Double height = slideHeight - sprayTask.getSprayParams().getMotorZHeight();//下降z轴高度
// DeviceCommand motorZPositionSetAboveSlideCommand = DeviceCommandGenerator.motorZPositionSet(height, 15.0);
// CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand);
// commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture, motorZPositionSetAboveSlideCommandFuture);
// }
// Thread.sleep(100);
// sprayTask.setSuspendable(true);//可以暂停单次喷涂范围内可以进行暂停
// deviceStatus.setSuspendable(true);
// double cacheXPoint = -1;
// double cacheYPoint = -1;
// DecimalFormat df = new DecimalFormat("#.##");
// for (int i = 0; i < sprayTaskStep.getSprayPathPointList().size(); i++) {//单次喷涂
// if (currentIndex != sprayTaskStep.getIndex()) {
// sprayNum = 0;
// currentIndex = sprayTaskStep.getIndex();
// }
// if (currentStep < reCurrentStep) {
// currentStep++;
// continue;
// }
// if (i == 1) {
// DeviceCommand syringePumpForwardCommand = DeviceCommandGenerator.syringePumpForward(sprayTask.getSprayParams().getVolume());//推动移动注射泵
// CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpForwardCommand);
// commandWait(syringePumpForwardCommandFuture);
// }
// sprayTask.setFirstImmobility(true);
// List<DeviceCommand> sprayStepCommands = sprayTaskStep.getSprayPathPointList().get(i);
// DeviceCommand xSprayStepCommands = sprayStepCommands.get(0);
// xSprayStepCommands.getParam().put("speed", sprayTask.getSprayParams().getMovingSpeed());//防止修改了移动速度这里重新设置移动速度
// DeviceCommand ySprayStepCommands = sprayStepCommands.get(1);
// ySprayStepCommands.getParam().put("speed", sprayTask.getSprayParams().getMovingSpeed());
// List<CommandFuture> commandFutureList = new ArrayList<>();
// double aXPoint = (double) xSprayStepCommands.getParam().get("position");
// double aYPoint = (double) ySprayStepCommands.getParam().get("position");
//
// xSprayStepCommands.getParam().put("position", Double.parseDouble(df.format(aXPoint)));
// ySprayStepCommands.getParam().put("position", Double.parseDouble(df.format(aYPoint)));
//
// if (cacheXPoint != aXPoint) {
// CommandFuture commandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), xSprayStepCommands);
// commandFutureList.add(commandFuture);
// cacheXPoint = aXPoint;
// }
// if (cacheYPoint != aYPoint) {
// CommandFuture commandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), ySprayStepCommands);
// commandFutureList.add(commandFuture);
// cacheYPoint = aYPoint;
// }
// CommandFuture[] commandFutureArray = commandFutureList.toArray(new CommandFuture[0]);
//
// double currentXPoint = Double.parseDouble(df.format((Double) xSprayStepCommands.getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0]));
// double currentYPoint = Double.parseDouble(df.format(75.5 - (Double) ySprayStepCommands.getParam().get("position")));
// Point2D currentPoint = new Point2D(currentXPoint, currentYPoint);
// SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayTaskStep.getIndex(), sprayNum, sprayCount, currentPoint);
// webSocketService.pushMsg(WebSocketMessageType.SPRAY_POINT, sprayTaskPointCollectorPushBO);
//
// //将当前点位缓存
// SprayTaskSprayed sprayTaskSprayed = new SprayTaskSprayed();
// sprayTaskSprayed.setNumber(sprayNum);
// sprayTaskSprayed.setIndex(sprayTaskStep.getIndex());
// sprayTaskSprayed.setSprayCount(sprayCount);
// sprayTaskSprayed.setSprayedPoints(new Point2D(Double.parseDouble(df.format(aXPoint - slideArr[sprayTaskStep.getIndex()][0])), Double.parseDouble(df.format(75.5 - aYPoint))));
// sprayTask.addSprayTaskSprayed(sprayTaskSprayed);
//
// commandWait(commandFutureArray);
// currentStep++;
// sprayTask.setCurrentStep(currentStep);//将当前的喷涂进度缓存
// }
// sprayTask.setSuspendable(false);//不可暂停
// deviceStatus.setSuspendable(false);
// if (currentStep >= reCurrentStep) {
// DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop();//停止推动注射泵
// CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpStopCommand);
// commandWait(syringePumpStopCommandFuture);
// }
// sprayCount++;
// sprayNum++;
// }
//
// DeviceCommand highVoltageCloseCommand = DeviceCommandGenerator.highVoltageClose();//关闭高压
// CommandFuture highVoltageCloseCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), highVoltageCloseCommand);
// commandWait(highVoltageCloseCommandFuture);
// Thread.sleep(500);
// DeviceCommand nozzleValveCloseCommand = DeviceCommandGenerator.nozzleValveClose();//关闭喷嘴阀
// CommandFuture nozzleValveCloseCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), nozzleValveCloseCommand);
// commandWait(nozzleValveCloseCommandFuture);
//
// //XYZ回原点
// DeviceCommand motorXOriginCommand = DeviceCommandGenerator.motorXOrigin();
// DeviceCommand motorYOriginCommand = DeviceCommandGenerator.motorYOrigin();
// DeviceCommand motorZOriginCommand = DeviceCommandGenerator.motorZOrigin();
// CommandFuture motorXOriginCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXOriginCommand);
// CommandFuture motorYOriginCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYOriginCommand);
// CommandFuture motorZOriginCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZOriginCommand);
// commandWait(motorXOriginCommandFuture, motorYOriginCommandFuture, motorZOriginCommandFuture);
//
//
// webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SUCCESS, "喷涂任务执行成功"));
// webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束"));
//
// SprayTask.getInstance().clear();
// deviceStatus.setSpraying(false);//是否正在进行喷涂
// deviceStatus.setPaused(false);//是否暂停
// deviceStatus.setSuspendable(false);//是否可以暂停
// } catch (InterruptedException e) {
// webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SEND, "喷涂任务线程停止"));
// } catch (Exception e) {
// log.info("喷涂任务失败", e);
// webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.FAIL, "喷涂任务执行失败"));
// webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束"));
//
// SprayTask.getInstance().clear();
// deviceStatus.setSpraying(false);
// deviceStatus.setPaused(false);
// deviceStatus.setSuspendable(false);
// } finally {
// webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SEND, "喷涂任务线程退出"));
// // 在线程结束后将 taskThread 设置为 null保证状态一致和资源释放
// synchronized (this) {
// taskThread = null;
// }
// }
// });
// taskThread.start();
// }
//
// /**
// * 停止任务线程
// */
// public synchronized void stopTask() {
// if (taskThread != null && taskThread.isAlive()) {
// // 中断线程使得 future.get() 能够抛出 InterruptedException从而退出等待
// taskThread.interrupt();
// }
// taskThread = null;
// }
//
// private void commandWait(CommandFuture... futures) throws ExecutionException, InterruptedException {
// CompletableFuture<?>[] responseFutures = Arrays.stream(futures)
// .map(CommandFuture::getResponseFuture)
// .toArray(CompletableFuture[]::new);
// CompletableFuture.allOf(responseFutures)
// .orTimeout(120, TimeUnit.SECONDS)
// .get();
// }
//
//
// private List<SprayTaskStep> getSprayPath(Integer index, SprayTimes sprayTimes) {
// String matrixPathType = sprayTimes.getMatrixPathType();
// 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"));
// Double[][] slideArr = {
// {slidePosition1.getX(), slidePosition1.getY()},
// {slidePosition2.getX(), slidePosition2.getY()},
// {slidePosition3.getX(), slidePosition3.getY()},
// {slidePosition4.getX(), slidePosition4.getY()}
// };
// Double[] upperLeft = {sprayTimes.getX1(), sprayTimes.getY1()}; //范围左上角 x1y1
// Double[] lowerRight = {sprayTimes.getX2(), sprayTimes.getY2()}; //范围左上角 x1y1
// Double[] slide = slideArr[index];//获取玻片的坐标
// DecimalFormat df = new DecimalFormat("#.##");
// double left = Double.parseDouble(df.format(slide[0] + upperLeft[0]));
// double right = Double.parseDouble(df.format(slide[0] + lowerRight[0]));
// double top = Double.parseDouble(df.format(slide[1] + upperLeft[1]));
// double bottom = Double.parseDouble(df.format(slide[1] + lowerRight[1]));
// Double spacing = sprayTimes.getSpacing();
// List<SprayTaskStep> sprayTaskStepList = new CopyOnWriteArrayList<>();
// if ("horizontal".equals(matrixPathType)) {//喷涂路径类型 horizontal 横向 | vertical 纵向 | grid 网格先横向后纵向
// List<Point2D> pathList = PathGenerator.generatePathPoints(
// left, right, top, bottom,
// spacing,
// PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN
// );
// SprayTaskStep sprayTaskStep = new SprayTaskStep();
// sprayTaskStep.setIndex(index);
// sprayTaskStep.setSprayPathPointList(pathList);
// sprayTaskStepList.add(sprayTaskStep);
// } else if ("vertical".equals(matrixPathType)) {
// List<Point2D> pathList = PathGenerator.generatePathPoints(
// left, right, top, bottom,
// spacing,
// PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT
// );
// SprayTaskStep sprayTaskStep = new SprayTaskStep();
// sprayTaskStep.setIndex(index);
// sprayTaskStep.setSprayPathPointList(pathList);
// sprayTaskStepList.add(sprayTaskStep);
// } else if ("grid".equals(matrixPathType)) {
// List<Point2D> pathList1 = PathGenerator.generatePathPoints(
// left, right, top, bottom,
// spacing,
// PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN
// );
// SprayTaskStep sprayTaskStep1 = new SprayTaskStep();
// sprayTaskStep1.setIndex(index);
// sprayTaskStep1.setSprayPathPointList(pathList1);
// sprayTaskStepList.add(sprayTaskStep1);
// List<Point2D> pathList2 = PathGenerator.generatePathPoints(
// left, right, top, bottom,
// spacing,
// PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT
// );
// SprayTaskStep sprayTaskStep2 = new SprayTaskStep();
// sprayTaskStep2.setIndex(index);
// sprayTaskStep2.setSprayPathPointList(pathList2);
// sprayTaskStepList.add(sprayTaskStep2);
// }
// return sprayTaskStepList;
// }
//}

2
src/main/java/com/qyft/ms/app/device/status/DeviceStatus.java

@ -84,6 +84,8 @@ public class DeviceStatus {
json.putOnce("selfTestCompleted", selfTestCompleted);
json.putOnce("stopPressed", stopPressed);
json.putOnce("virtual", virtual);
json.putOnce("nozzleHeating", nozzleHeating);
json.putOnce("slidePlatHeating", slidePlatHeating);
return json;
}

111
src/main/java/com/qyft/ms/app/device/status/SprayTask.java

@ -1,27 +1,14 @@
package com.qyft.ms.app.device.status;
import com.qyft.ms.app.model.bo.SprayParams;
import com.qyft.ms.app.model.bo.SprayTaskSprayed;
import com.qyft.ms.app.model.bo.SprayTaskStep;
import com.qyft.ms.app.model.bo.SprayTaskParams;
import lombok.Data;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
@Data
public class SprayTask {
/**
* 喷涂步骤列表
*/
private final List<SprayTaskStep> sprayTaskStepList = new CopyOnWriteArrayList<>();
/**
* 喷涂参数
*/
private final SprayParams sprayParams = new SprayParams();
/**
* 前端指令id
*/
private String cmdId;
@ -30,7 +17,15 @@ public class SprayTask {
*/
private String cmdCode;
/**
* 喷涂任务暂停状态
* 当前正在执行的步骤序号
*/
private volatile int currentStep = 0;
/**
* 当前喷涂参数
*/
private List<SprayTaskParams> sprayTaskParams = null;
/**
* 标志喷涂任务暂停
*/
private volatile boolean paused = false;
/**
@ -38,29 +33,13 @@ public class SprayTask {
*/
private volatile boolean suspendable = false;
/**
* 是否正在结束
* 标志喷涂任务结束
*/
private volatile boolean closing = false;
private volatile boolean close = false;
/**
* 设备是否正在进行的喷涂
*/
private volatile boolean spraying = false;
/**
* 当前正在执行的步骤序号
*/
private volatile int currentStep = 0;
private volatile boolean firstImmobility = false;
/**
* 缓存前端的参数
*/
private Map<String, Object> cacheParams = null;
/**
* 已喷涂点位
*/
private volatile List<SprayTaskSprayed> sprayTaskSprayedList = new CopyOnWriteArrayList<>();
private SprayTask() {
}
@ -69,78 +48,14 @@ public class SprayTask {
return Holder.INSTANCE;
}
public void setChangeSprayParam(Double motorZHeight,
Double gasPressure,
Double volume,
Boolean highVoltage,
Double highVoltageValue,
Double movingSpeed) {
if (motorZHeight != null) {
sprayParams.setMotorZHeight(motorZHeight);
}
if (gasPressure != null) {
sprayParams.setGasPressure(gasPressure);
}
if (volume != null) {
sprayParams.setVolume(volume);
}
if (highVoltage != null) {
sprayParams.setHighVoltage(highVoltage);
}
if (highVoltageValue != null) {
sprayParams.setHighVoltageValue(highVoltageValue);
}
if (movingSpeed != null) {
sprayParams.setMovingSpeed(movingSpeed);
}
}
public void setSprayParam(String matrixPathType,
Double motorZHeight,
Double gasPressure,
Double volume,
Boolean highVoltage,
Double highVoltageValue,
Double spacing,
Double movingSpeed,
Double times,
List<Map<String, Object>> positionList) {
sprayParams.setMatrixPathType(matrixPathType);
sprayParams.setMotorZHeight(motorZHeight);
sprayParams.setGasPressure(gasPressure);
sprayParams.setVolume(volume);
sprayParams.setHighVoltage(highVoltage);
sprayParams.setHighVoltageValue(highVoltageValue);
sprayParams.setSpacing(spacing);
sprayParams.setMovingSpeed(movingSpeed);
sprayParams.setTimes(times);
sprayParams.setPositionList(positionList);
}
public synchronized void addSprayTaskSprayed(SprayTaskSprayed task) {
LinkedHashSet<Integer> distinctNumbers = new LinkedHashSet<>();
for (SprayTaskSprayed item : sprayTaskSprayedList) {
distinctNumbers.add(item.getSprayCount());
}
if (!distinctNumbers.contains(task.getSprayCount()) && distinctNumbers.size() >= 120) {
Integer oldestNumber = distinctNumbers.iterator().next();
sprayTaskSprayedList.removeIf(item -> item.getSprayCount().equals(oldestNumber));
}
sprayTaskSprayedList.add(task);
}
public void clear() {
cmdId = null;
cmdCode = null;
paused = false;
suspendable = false;
spraying = false;
sprayTaskStepList.clear();
currentStep = 0;
firstImmobility = false;
sprayTaskSprayedList.clear();
cacheParams = null;
sprayTaskParams = null;
}
private static class Holder {

150
src/main/java/com/qyft/ms/app/device/status/SprayTask_bak.java

@ -0,0 +1,150 @@
package com.qyft.ms.app.device.status;
import com.qyft.ms.app.model.bo.SprayParams;
import com.qyft.ms.app.model.bo.SprayTaskSprayed;
import com.qyft.ms.app.model.bo.SprayTaskStep;
import lombok.Data;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
@Data
public class SprayTask_bak {
/**
* 喷涂步骤列表
*/
private final List<SprayTaskStep> sprayTaskStepList = new CopyOnWriteArrayList<>();
/**
* 喷涂参数
*/
private final SprayParams sprayParams = new SprayParams();
/**
* 前端指令id
*/
private String cmdId;
/**
* 前端指令code
*/
private String cmdCode;
/**
* 喷涂任务暂停状态
*/
private volatile boolean paused = false;
/**
* 当前状态是否可以暂停
*/
private volatile boolean suspendable = false;
/**
* 是否正在结束
*/
private volatile boolean closing = false;
/**
* 设备是否正在进行的喷涂
*/
private volatile boolean spraying = false;
/**
* 当前正在执行的步骤序号
*/
private volatile int currentStep = 0;
private volatile boolean firstImmobility = false;
/**
* 缓存前端的参数
*/
private Map<String, Object> cacheParams = null;
/**
* 已喷涂点位
*/
private volatile List<SprayTaskSprayed> sprayTaskSprayedList = new CopyOnWriteArrayList<>();
private SprayTask_bak() {
}
public static SprayTask_bak getInstance() {
return Holder.INSTANCE;
}
public void setChangeSprayParam(Double motorZHeight,
Double gasPressure,
Double volume,
Boolean highVoltage,
Double highVoltageValue,
Double movingSpeed) {
if (motorZHeight != null) {
sprayParams.setMotorZHeight(motorZHeight);
}
if (gasPressure != null) {
sprayParams.setGasPressure(gasPressure);
}
if (volume != null) {
sprayParams.setVolume(volume);
}
if (highVoltage != null) {
sprayParams.setHighVoltage(highVoltage);
}
if (highVoltageValue != null) {
sprayParams.setHighVoltageValue(highVoltageValue);
}
if (movingSpeed != null) {
sprayParams.setMovingSpeed(movingSpeed);
}
}
public void setSprayParam(String matrixPathType,
Double motorZHeight,
Double gasPressure,
Double volume,
Boolean highVoltage,
Double highVoltageValue,
Double spacing,
Double movingSpeed,
Double times,
List<Map<String, Object>> positionList) {
sprayParams.setMatrixPathType(matrixPathType);
sprayParams.setMotorZHeight(motorZHeight);
sprayParams.setGasPressure(gasPressure);
sprayParams.setVolume(volume);
sprayParams.setHighVoltage(highVoltage);
sprayParams.setHighVoltageValue(highVoltageValue);
sprayParams.setSpacing(spacing);
sprayParams.setMovingSpeed(movingSpeed);
sprayParams.setTimes(times);
sprayParams.setPositionList(positionList);
}
public synchronized void addSprayTaskSprayed(SprayTaskSprayed task) {
LinkedHashSet<Integer> distinctNumbers = new LinkedHashSet<>();
for (SprayTaskSprayed item : sprayTaskSprayedList) {
distinctNumbers.add(item.getSprayCount());
}
if (!distinctNumbers.contains(task.getSprayCount()) && distinctNumbers.size() >= 120) {
Integer oldestNumber = distinctNumbers.iterator().next();
sprayTaskSprayedList.removeIf(item -> item.getSprayCount().equals(oldestNumber));
}
sprayTaskSprayedList.add(task);
}
public void clear() {
cmdId = null;
cmdCode = null;
paused = false;
suspendable = false;
spraying = false;
sprayTaskStepList.clear();
currentStep = 0;
firstImmobility = false;
sprayTaskSprayedList.clear();
cacheParams = null;
}
private static class Holder {
private static final SprayTask_bak INSTANCE = new SprayTask_bak();
}
}

192
src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayChangeParam.java

@ -1,96 +1,96 @@
package com.qyft.ms.app.front.cmd.business;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qyft.ms.app.device.status.SprayTask;
import com.qyft.ms.app.model.entity.SysSettings;
import com.qyft.ms.app.service.SysSettingsService;
import com.qyft.ms.system.common.annotation.CommandMapping;
import com.qyft.ms.system.common.constant.CommandStatus;
import com.qyft.ms.system.common.device.command.CommandFuture;
import com.qyft.ms.system.common.device.command.DeviceCommandGenerator;
import com.qyft.ms.system.common.device.command.FrontResponseGenerator;
import com.qyft.ms.system.core.handler.BaseCommandHandler;
import com.qyft.ms.system.model.bo.DeviceCommand;
import com.qyft.ms.system.model.form.FrontCmdControlForm;
import com.qyft.ms.system.service.WebSocketService;
import com.qyft.ms.system.service.device.DeviceCommandService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 喷涂_喷涂过程中参数实时调整
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("matrix_spray_change_param")//业务指令注解
public class MatrixSprayChangeParam extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private final SysSettingsService sysSettingsService;
private final WebSocketService webSocketService;
@Override
public CompletableFuture<Void> handle(FrontCmdControlForm form) {
SprayTask sprayTask = SprayTask.getInstance();
if (!sprayTask.isSpraying() || sprayTask.isClosing()) {//判断设备是否正在喷涂
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "目前无法修改喷涂参数"));
throw new RuntimeException("目前无法修改喷涂参数");
}
Double motorZHeight = form.getDoubleParam("motorZHeight");
Double gasPressure = form.getDoubleParam("gasPressure");
Double volume = form.getDoubleParam("volume");
Boolean highVoltage = form.getBooleanParam("highVoltage");
Double highVoltageValue = form.getDoubleParam("highVoltageValue");
Double movingSpeed = form.getDoubleParam("movingSpeed");
if (highVoltageValue!= null && highVoltageValue > 6000) {
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "电压不能大于6000V"));
throw new RuntimeException("电压不能大于6000V");
}
sprayTask.setChangeSprayParam(motorZHeight, gasPressure, volume, highVoltage, highVoltageValue, movingSpeed);
return runAsync(() -> {
if (!sprayTask.isPaused()) {
//4.是否打开高压
if (highVoltage) {//打开高压
DeviceCommand highVoltageOpenCommand = DeviceCommandGenerator.highVoltageOpen(highVoltageValue);//开启高压
CommandFuture highVoltageOpenCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageOpenCommand);
commandWait(highVoltageOpenCommandFuture);
} else {//关闭高压
DeviceCommand highVoltageCloseCommand = DeviceCommandGenerator.highVoltageClose();//关闭高压
CommandFuture highVoltageCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageCloseCommand);
commandWait(highVoltageCloseCommandFuture);
}
}
//3.z轴高度
SysSettings slideHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper<SysSettings>().eq(SysSettings::getCode, "slide_height"));
Double slideHeight = Double.parseDouble(slideHeightSysSettings.getValue());
Double height = slideHeight - motorZHeight;
DeviceCommand smotorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(height, sprayTask.getSprayParams().getMovingSpeed());//移动z轴到指定位置
CommandFuture smotorZPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), smotorZPositionSetCommand);
//1.速度
DeviceCommand motorXSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorXSpeedSet(movingSpeed);//x轴电机速度设置
DeviceCommand motorYSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorYSpeedSet(movingSpeed);//y轴电机速度设置
DeviceCommand motorZSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorZSpeedSet(movingSpeed);//z轴电机速度设置
CommandFuture motorXSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXSpeedSetCmdToDeviceCommand);
CommandFuture motorYSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYSpeedSetCmdToDeviceCommand);
CommandFuture motorZSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZSpeedSetCmdToDeviceCommand);
//2.流速
DeviceCommand syringePumpVolumeSetCommand = DeviceCommandGenerator.syringePumpVolumeSet(volume);//注射泵流速设置
CommandFuture syringePumpVolumeSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpVolumeSetCommand);
commandWait(motorXSpeedSetCmdToDeviceCommandFuture, motorYSpeedSetCmdToDeviceCommandFuture, motorZSpeedSetCmdToDeviceCommandFuture, smotorZPositionSetCommandFuture, syringePumpVolumeSetCommandFuture);
});
}
}
//package com.qyft.ms.app.front.cmd.business;
//
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.qyft.ms.app.device.status.SprayTask;
//import com.qyft.ms.app.model.entity.SysSettings;
//import com.qyft.ms.app.service.SysSettingsService;
//import com.qyft.ms.system.common.annotation.CommandMapping;
//import com.qyft.ms.system.common.constant.CommandStatus;
//import com.qyft.ms.system.common.device.command.CommandFuture;
//import com.qyft.ms.system.common.device.command.DeviceCommandGenerator;
//import com.qyft.ms.system.common.device.command.FrontResponseGenerator;
//import com.qyft.ms.system.core.handler.BaseCommandHandler;
//import com.qyft.ms.system.model.bo.DeviceCommand;
//import com.qyft.ms.system.model.form.FrontCmdControlForm;
//import com.qyft.ms.system.service.WebSocketService;
//import com.qyft.ms.system.service.device.DeviceCommandService;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//import java.util.concurrent.CompletableFuture;
//
///**
// * 喷涂_喷涂过程中参数实时调整
// */
//@Slf4j
//@Component
//@RequiredArgsConstructor
//@CommandMapping("matrix_spray_change_param")//业务指令注解
//public class MatrixSprayChangeParam extends BaseCommandHandler {
//
// private final DeviceCommandService deviceCommandService;
// private final SysSettingsService sysSettingsService;
// private final WebSocketService webSocketService;
//
// @Override
// public CompletableFuture<Void> handle(FrontCmdControlForm form) {
// SprayTask sprayTask = SprayTask.getInstance();
// if (!sprayTask.isSpraying() || sprayTask.isClosing()) {//判断设备是否正在喷涂
// webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "目前无法修改喷涂参数"));
// throw new RuntimeException("目前无法修改喷涂参数");
// }
//
// Double motorZHeight = form.getDoubleParam("motorZHeight");
// Double gasPressure = form.getDoubleParam("gasPressure");
// Double volume = form.getDoubleParam("volume");
// Boolean highVoltage = form.getBooleanParam("highVoltage");
// Double highVoltageValue = form.getDoubleParam("highVoltageValue");
// Double movingSpeed = form.getDoubleParam("movingSpeed");
//
// if (highVoltageValue!= null && highVoltageValue > 6000) {
// webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "电压不能大于6000V"));
// throw new RuntimeException("电压不能大于6000V");
// }
//
// sprayTask.setChangeSprayParam(motorZHeight, gasPressure, volume, highVoltage, highVoltageValue, movingSpeed);
//
// return runAsync(() -> {
// if (!sprayTask.isPaused()) {
// //4.是否打开高压
// if (highVoltage) {//打开高压
// DeviceCommand highVoltageOpenCommand = DeviceCommandGenerator.highVoltageOpen(highVoltageValue);//开启高压
// CommandFuture highVoltageOpenCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageOpenCommand);
// commandWait(highVoltageOpenCommandFuture);
// } else {//关闭高压
// DeviceCommand highVoltageCloseCommand = DeviceCommandGenerator.highVoltageClose();//关闭高压
// CommandFuture highVoltageCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageCloseCommand);
// commandWait(highVoltageCloseCommandFuture);
// }
// }
//
// //3.z轴高度
// SysSettings slideHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper<SysSettings>().eq(SysSettings::getCode, "slide_height"));
// Double slideHeight = Double.parseDouble(slideHeightSysSettings.getValue());
// Double height = slideHeight - motorZHeight;
// DeviceCommand smotorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(height, sprayTask.getSprayParams().getMovingSpeed());//移动z轴到指定位置
// CommandFuture smotorZPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), smotorZPositionSetCommand);
//
// //1.速度
// DeviceCommand motorXSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorXSpeedSet(movingSpeed);//x轴电机速度设置
// DeviceCommand motorYSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorYSpeedSet(movingSpeed);//y轴电机速度设置
// DeviceCommand motorZSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorZSpeedSet(movingSpeed);//z轴电机速度设置
// CommandFuture motorXSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXSpeedSetCmdToDeviceCommand);
// CommandFuture motorYSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYSpeedSetCmdToDeviceCommand);
// CommandFuture motorZSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZSpeedSetCmdToDeviceCommand);
//
// //2.流速
// DeviceCommand syringePumpVolumeSetCommand = DeviceCommandGenerator.syringePumpVolumeSet(volume);//注射泵流速设置
// CommandFuture syringePumpVolumeSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpVolumeSetCommand);
//
// commandWait(motorXSpeedSetCmdToDeviceCommandFuture, motorYSpeedSetCmdToDeviceCommandFuture, motorZSpeedSetCmdToDeviceCommandFuture, smotorZPositionSetCommandFuture, syringePumpVolumeSetCommandFuture);
//
// });
//
// }
//}

134
src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayContinue.java

@ -1,67 +1,67 @@
package com.qyft.ms.app.front.cmd.business;
import com.qyft.ms.app.device.spray.SprayTaskExecutor;
import com.qyft.ms.app.device.status.DeviceStatus;
import com.qyft.ms.app.device.status.SprayTask;
import com.qyft.ms.system.common.annotation.CommandMapping;
import com.qyft.ms.system.common.device.command.CommandFuture;
import com.qyft.ms.system.common.device.command.DeviceCommandGenerator;
import com.qyft.ms.system.core.handler.BaseCommandHandler;
import com.qyft.ms.system.model.bo.DeviceCommand;
import com.qyft.ms.system.model.form.FrontCmdControlForm;
import com.qyft.ms.system.service.device.DeviceCommandService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 喷涂_基质喷涂继续
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("matrix_spray_continue")//业务指令注解
public class MatrixSprayContinue extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private final SprayTaskExecutor sprayTaskExecutor;
private final DeviceStatus deviceStatus;
@Override
public CompletableFuture<Void> handle(FrontCmdControlForm form) {
SprayTask sprayTask = SprayTask.getInstance();
if (!sprayTask.isSpraying()) {
throw new RuntimeException("设备没有正在喷涂");
}
sprayTask.setSpraying(true);
sprayTask.setPaused(false);
deviceStatus.setSpraying(true);
deviceStatus.setPaused(false);
return runAsync(() -> {
if (sprayTask.getSprayParams().getHighVoltage()) {
DeviceCommand highVoltageOpenCommand = DeviceCommandGenerator.highVoltageOpen(sprayTask.getSprayParams().getHighVoltageValue()); //打开高压
CommandFuture highVoltageOpenCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageOpenCommand);
commandWait(highVoltageOpenCommandFuture);
}
DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenSyringePipeline();//打开三通阀喷嘴管路
CommandFuture threeWayValveOpenSyringePipelineCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), threeWayValveOpenSyringePipelineCommand);
commandWait(threeWayValveOpenSyringePipelineCommandFuture);
DeviceCommand nozzleValveOpenCommand = DeviceCommandGenerator.nozzleValveOpen(); //打开喷嘴阀
CommandFuture nozzleValveOpenCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), nozzleValveOpenCommand);
commandWait(nozzleValveOpenCommandFuture);
DeviceCommand syringePumpForwardCommand = DeviceCommandGenerator.syringePumpForward(sprayTask.getSprayParams().getVolume()); //推动注射泵
CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpForwardCommand);
commandWait(syringePumpForwardCommandFuture);
sprayTask.setFirstImmobility(true);
sprayTaskExecutor.startTask();
});
}
}
//package com.qyft.ms.app.front.cmd.business;
//
//import com.qyft.ms.app.device.spray.SprayTaskExecutor;
//import com.qyft.ms.app.device.status.DeviceStatus;
//import com.qyft.ms.app.device.status.SprayTask;
//import com.qyft.ms.system.common.annotation.CommandMapping;
//import com.qyft.ms.system.common.device.command.CommandFuture;
//import com.qyft.ms.system.common.device.command.DeviceCommandGenerator;
//import com.qyft.ms.system.core.handler.BaseCommandHandler;
//import com.qyft.ms.system.model.bo.DeviceCommand;
//import com.qyft.ms.system.model.form.FrontCmdControlForm;
//import com.qyft.ms.system.service.device.DeviceCommandService;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//import java.util.concurrent.CompletableFuture;
//
///**
// * 喷涂_基质喷涂继续
// */
//@Slf4j
//@Component
//@RequiredArgsConstructor
//@CommandMapping("matrix_spray_continue")//业务指令注解
//public class MatrixSprayContinue extends BaseCommandHandler {
//
// private final DeviceCommandService deviceCommandService;
// private final SprayTaskExecutor sprayTaskExecutor;
// private final DeviceStatus deviceStatus;
//
// @Override
// public CompletableFuture<Void> handle(FrontCmdControlForm form) {
// SprayTask sprayTask = SprayTask.getInstance();
// if (!sprayTask.isSpraying()) {
// throw new RuntimeException("设备没有正在喷涂");
// }
// sprayTask.setSpraying(true);
// sprayTask.setPaused(false);
// deviceStatus.setSpraying(true);
// deviceStatus.setPaused(false);
//
// return runAsync(() -> {
// if (sprayTask.getSprayParams().getHighVoltage()) {
// DeviceCommand highVoltageOpenCommand = DeviceCommandGenerator.highVoltageOpen(sprayTask.getSprayParams().getHighVoltageValue()); //打开高压
// CommandFuture highVoltageOpenCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageOpenCommand);
// commandWait(highVoltageOpenCommandFuture);
// }
//
// DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenSyringePipeline();//打开三通阀喷嘴管路
// CommandFuture threeWayValveOpenSyringePipelineCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), threeWayValveOpenSyringePipelineCommand);
// commandWait(threeWayValveOpenSyringePipelineCommandFuture);
//
// DeviceCommand nozzleValveOpenCommand = DeviceCommandGenerator.nozzleValveOpen(); //打开喷嘴阀
// CommandFuture nozzleValveOpenCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), nozzleValveOpenCommand);
// commandWait(nozzleValveOpenCommandFuture);
//
// DeviceCommand syringePumpForwardCommand = DeviceCommandGenerator.syringePumpForward(sprayTask.getSprayParams().getVolume()); //推动注射泵
// CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpForwardCommand);
// commandWait(syringePumpForwardCommandFuture);
//
// sprayTask.setFirstImmobility(true);
// sprayTaskExecutor.startTask();
// });
//
// }
//}

128
src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayPause.java

@ -1,64 +1,64 @@
package com.qyft.ms.app.front.cmd.business;
import com.qyft.ms.app.device.spray.SprayTaskExecutor;
import com.qyft.ms.app.device.status.DeviceStatus;
import com.qyft.ms.app.device.status.SprayTask;
import com.qyft.ms.system.common.annotation.CommandMapping;
import com.qyft.ms.system.common.device.command.CommandFuture;
import com.qyft.ms.system.common.device.command.DeviceCommandGenerator;
import com.qyft.ms.system.core.handler.BaseCommandHandler;
import com.qyft.ms.system.model.bo.DeviceCommand;
import com.qyft.ms.system.model.form.FrontCmdControlForm;
import com.qyft.ms.system.service.device.DeviceCommandService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 喷涂_基质喷涂暂停
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("matrix_spray_pause")//业务指令注解
public class MatrixSprayPause extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private final SprayTaskExecutor sprayTaskExecutor;
private final DeviceStatus deviceStatus;
@Override
public CompletableFuture<Void> handle(FrontCmdControlForm form) {
SprayTask sprayTask = SprayTask.getInstance();
if (!sprayTask.isSuspendable() || sprayTask.isClosing()) {
throw new RuntimeException("当前喷涂任务不可暂停");
}
sprayTask.setPaused(true);//已暂停
deviceStatus.setPaused(true);
sprayTask.setSuspendable(false);//不可暂停
deviceStatus.setSuspendable(false);
sprayTask.setFirstImmobility(true);
return runAsync(() -> {
sprayTaskExecutor.stopTask();//终止喷涂任务线程
DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop(); //停止推动注射泵
CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpStopCommand);
DeviceCommand nozzleValveCloseCommand = DeviceCommandGenerator.nozzleValveClose(); //关闭喷嘴阀
CommandFuture nozzleValveCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), nozzleValveCloseCommand);
DeviceCommand highVoltageCloseCommand = DeviceCommandGenerator.highVoltageClose(); //关闭高压
CommandFuture highVoltageCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageCloseCommand);
commandWait(syringePumpStopCommandFuture, nozzleValveCloseCommandFuture, highVoltageCloseCommandFuture);
DeviceCommand motorXStopCommand = DeviceCommandGenerator.motorXStop(); //x轴停止移动
DeviceCommand motorYStopCommand = DeviceCommandGenerator.motorYStop(); //y轴停止移动
DeviceCommand motorZStopCommand = DeviceCommandGenerator.motorZStop(); //z轴停止移动
CommandFuture motorXStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXStopCommand);
CommandFuture motorYStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYStopCommand);
CommandFuture motorZStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZStopCommand);
commandWait(motorXStopCommandFuture, motorYStopCommandFuture, motorZStopCommandFuture);
});
}
}
//package com.qyft.ms.app.front.cmd.business;
//
//
//import com.qyft.ms.app.device.spray.SprayTaskExecutor;
//import com.qyft.ms.app.device.status.DeviceStatus;
//import com.qyft.ms.app.device.status.SprayTask;
//import com.qyft.ms.system.common.annotation.CommandMapping;
//import com.qyft.ms.system.common.device.command.CommandFuture;
//import com.qyft.ms.system.common.device.command.DeviceCommandGenerator;
//import com.qyft.ms.system.core.handler.BaseCommandHandler;
//import com.qyft.ms.system.model.bo.DeviceCommand;
//import com.qyft.ms.system.model.form.FrontCmdControlForm;
//import com.qyft.ms.system.service.device.DeviceCommandService;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//import java.util.concurrent.CompletableFuture;
//
///**
// * 喷涂_基质喷涂暂停
// */
//@Slf4j
//@Component
//@RequiredArgsConstructor
//@CommandMapping("matrix_spray_pause")//业务指令注解
//public class MatrixSprayPause extends BaseCommandHandler {
//
// private final DeviceCommandService deviceCommandService;
// private final SprayTaskExecutor sprayTaskExecutor;
// private final DeviceStatus deviceStatus;
//
// @Override
// public CompletableFuture<Void> handle(FrontCmdControlForm form) {
// SprayTask sprayTask = SprayTask.getInstance();
// if (!sprayTask.isSuspendable() || sprayTask.isClose()) {
// throw new RuntimeException("当前喷涂任务不可暂停");
// }
// sprayTask.setPaused(true);//已暂停
// deviceStatus.setPaused(true);
// sprayTask.setSuspendable(false);//不可暂停
// deviceStatus.setSuspendable(false);
// sprayTask.setFirstImmobility(true);
// return runAsync(() -> {
// sprayTaskExecutor.stopTask();//终止喷涂任务线程
//
// DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop(); //停止推动注射泵
// CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpStopCommand);
// DeviceCommand nozzleValveCloseCommand = DeviceCommandGenerator.nozzleValveClose(); //关闭喷嘴阀
// CommandFuture nozzleValveCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), nozzleValveCloseCommand);
// DeviceCommand highVoltageCloseCommand = DeviceCommandGenerator.highVoltageClose(); //关闭高压
// CommandFuture highVoltageCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageCloseCommand);
// commandWait(syringePumpStopCommandFuture, nozzleValveCloseCommandFuture, highVoltageCloseCommandFuture);
//
// DeviceCommand motorXStopCommand = DeviceCommandGenerator.motorXStop(); //x轴停止移动
// DeviceCommand motorYStopCommand = DeviceCommandGenerator.motorYStop(); //y轴停止移动
// DeviceCommand motorZStopCommand = DeviceCommandGenerator.motorZStop(); //z轴停止移动
// CommandFuture motorXStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXStopCommand);
// CommandFuture motorYStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYStopCommand);
// CommandFuture motorZStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZStopCommand);
// commandWait(motorXStopCommandFuture, motorYStopCommandFuture, motorZStopCommandFuture);
// });
// }
//}

38
src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart.java

@ -60,8 +60,46 @@ public class MatrixSprayStart extends BaseCommandHandler {
@Override
public CompletableFuture<Void> handle(FrontCmdControlForm form) {
SprayTask sprayTask = SprayTask.getInstance();
if (sprayTask.isSpraying()) {//判断设备是否正在喷涂
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "设备正在喷涂,请先停止喷涂"));
throw new RuntimeException("设备正在喷涂,请先停止喷涂");
}
if(sprayTask.getSprayTaskParams() == null){
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "未设置喷涂参数"));
throw new RuntimeException("未设置喷涂参数");
}
sprayTask.setCmdId(form.getCmdId());
sprayTask.setCmdCode(form.getCmdCode());
sprayTask.setSpraying(true);//正在进行喷涂
deviceStatus.setSpraying(true);
return runAsync(() -> {
//喷涂开始前先回原点
DeviceCommand overallDeviceStatusGetCommand = DeviceCommandGenerator.overallDeviceStatusGet();
CommandFuture overallDeviceStatusGetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), overallDeviceStatusGetCommand);
commandWait(overallDeviceStatusGetCommandFuture);
List<CommandFuture> futureList = new ArrayList<>();
if (!overallDeviceStatusGetCommandFuture.getResponseResult().getJSONObject("data").getBool("xAxisAtOrigin")) {
DeviceCommand motorXOriginCommand = DeviceCommandGenerator.motorXOrigin(); // x轴回原点
CommandFuture motorXOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXOriginCommand);
futureList.add(motorXOriginCommandFuture);
}
if (!overallDeviceStatusGetCommandFuture.getResponseResult().getJSONObject("data").getBool("yAxisAtOrigin")) {
DeviceCommand motorYOriginCommand = DeviceCommandGenerator.motorYOrigin();//y轴回原点
CommandFuture motorYOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYOriginCommand);
futureList.add(motorYOriginCommandFuture);
}
if (!overallDeviceStatusGetCommandFuture.getResponseResult().getJSONObject("data").getBool("zAxisAtOrigin")) {
DeviceCommand motorZOriginCommand = DeviceCommandGenerator.motorZOrigin();//z轴回原点
CommandFuture motorZOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZOriginCommand);
futureList.add(motorZOriginCommandFuture);
}
commandWait(futureList.toArray(new CommandFuture[0]));
sprayTaskExecutor.startTask();
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.SEND, "已开启喷涂线程"));
});
}

730
src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart_bak.java

@ -1,365 +1,365 @@
package com.qyft.ms.app.front.cmd.business;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qyft.ms.app.common.generator.PathGenerator;
import com.qyft.ms.app.device.spray.SprayTaskExecutor;
import com.qyft.ms.app.device.status.DeviceStatus;
import com.qyft.ms.app.device.status.SprayTask;
import com.qyft.ms.app.model.bo.SprayTaskStep;
import com.qyft.ms.app.model.entity.OperationLog;
import com.qyft.ms.app.model.entity.Position;
import com.qyft.ms.app.service.OperationLogService;
import com.qyft.ms.app.service.PositionService;
import com.qyft.ms.system.common.annotation.CommandMapping;
import com.qyft.ms.system.common.constant.CommandStatus;
import com.qyft.ms.system.common.device.command.CommandFuture;
import com.qyft.ms.system.common.device.command.DeviceCommandGenerator;
import com.qyft.ms.system.common.device.command.FrontResponseGenerator;
import com.qyft.ms.system.common.utils.CheckedRunnable;
import com.qyft.ms.system.common.utils.LambdaUtil;
import com.qyft.ms.system.core.handler.BaseCommandHandler;
import com.qyft.ms.system.model.bo.DeviceCommand;
import com.qyft.ms.system.model.form.FrontCmdControlForm;
import com.qyft.ms.system.service.WebSocketService;
import com.qyft.ms.system.service.device.DeviceCommandService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.text.DecimalFormat;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* 喷涂_基质喷涂开始
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("matrix_spray_start_bak")//业务指令注解
public class MatrixSprayStart_bak extends BaseCommandHandler {
private static final ExecutorService singleExecutor = Executors.newSingleThreadExecutor();
private final SprayTaskExecutor sprayTaskExecutor;
private final PositionService positionService;
private final DeviceStatus deviceStatus;
private final OperationLogService operationLogService;
private final WebSocketService webSocketService;
private final DeviceCommandService deviceCommandService;
private void nonNullCheck(String cmdId, String cmdCode,
String matrixPathType,
Double motorZHeight,
Double gasPressure,
Double volume,
Boolean highVoltage,
Double spacing,
Double movingSpeed,
Double times,
Object position) {
Map<String, Object> paramMap = new LinkedHashMap<>();
paramMap.put("matrix_path_type", matrixPathType);
paramMap.put("motor_z_height", motorZHeight);
paramMap.put("gas_pressure", gasPressure);
paramMap.put("volume", volume);
paramMap.put("high_voltage", highVoltage);
paramMap.put("spacing", spacing);
paramMap.put("moving_speed", movingSpeed);
paramMap.put("times", times);
paramMap.put("position", position);
// 遍历 Map 检查是否为 null
for (Map.Entry<String, Object> entry : paramMap.entrySet()) {
if (entry.getValue() == null) {
String errorMsg = "参数 " + entry.getKey() + " 必填";
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.DEVICE_ERROR, errorMsg));
throw new RuntimeException(errorMsg);
}
}
}
/**
* 使用单线程执行器保证线程安全防止喷涂指令被多次调用
*/
@Override
protected CompletableFuture<Void> runAsync(CheckedRunnable task) {
return CompletableFuture.runAsync(LambdaUtil.unchecked(task), singleExecutor);
}
/**
* {
* cmdName:'matrix_spray_start'
* cmdId:'',
* param:{
* matrix_path_type:horizontal | vertical | grid;//喷涂路径类型
* motor_z_height:;//高度 Z轴距离玻片的高度
* gas_pressure://Mpa兆帕 不处理
* volume:20//单位uL微升 基质流速(控制注射泵速度)
* high_voltage:true/false;//是否打开高压
* high_voltage_value:4000;//高压值
* spacing:''//毫米 间距
* moving_speed:8mm/s;//移动速度 轴速度
* times:;//喷涂遍数
* position:[{x1,y1,x2,y2,index}]
* }
* }
*/
@Override
public CompletableFuture<Void> handle(FrontCmdControlForm form) {
SprayTask sprayTask = SprayTask.getInstance();
if (sprayTask.isSpraying()) {//判断设备是否正在喷涂
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "设备正在喷涂,请先停止喷涂"));
throw new RuntimeException("设备正在喷涂,请先停止喷涂");
}
sprayTask.setCmdId(form.getCmdId());
sprayTask.setCmdCode(form.getCmdCode());
sprayTask.setSpraying(true);//正在进行喷涂
deviceStatus.setSpraying(true);
// 1. 参数校验
String matrixPathType = form.getStringParam("matrixPathType");
Double motorZHeight = form.getDoubleParam("motorZHeight");
Double gasPressure = form.getDoubleParam("gasPressure");
Double volume = form.getDoubleParam("volume");
Boolean highVoltage = form.getBooleanParam("highVoltage");
Double highVoltageValue = form.getDoubleParam("highVoltageValue");
Double spacing = form.getDoubleParam("spacing");
Double movingSpeed = form.getDoubleParam("movingSpeed");
Double times = form.getDoubleParam("times");
@SuppressWarnings("unchecked")
List<Map<String, Object>> positionList = (List<Map<String, Object>>) form.getParams().get("position");
nonNullCheck(matrixPathType, form.getCmdId(), form.getCmdCode(), motorZHeight, gasPressure, volume, highVoltage, spacing, movingSpeed, times, positionList);
if (highVoltageValue != null && highVoltageValue > 6000) {
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "电压不能大于6000V"));
throw new RuntimeException("电压不能大于6000V");
}
if (positionList.isEmpty()) {
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "喷涂区域不能为空"));
throw new RuntimeException("喷涂区域不能为空");
}
// 3. 设定喷涂参数
sprayTask.setSprayParam(matrixPathType, motorZHeight, gasPressure, volume, highVoltage, highVoltageValue, spacing, movingSpeed, times, positionList);
sprayTask.setCacheParams(form.getParams());
OperationLog operationLog = new OperationLog();
Long matrixCraftId = Long.valueOf(Optional.ofNullable(sprayTask.getCacheParams().get("matrixCraftId"))
.filter(Number.class::isInstance)
.map(Number.class::cast)
.map(Number::intValue)
.orElse(0));
operationLog.setMatrixId(matrixCraftId);
operationLog.setMatrixInfo(JSONUtil.toJsonStr(sprayTask.getCacheParams()));
operationLogService.add(operationLog);
// 7.循环喷涂区域
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"));
Double[][] slideArr = {
{slidePosition1.getX(), slidePosition1.getY()},
{slidePosition2.getX(), slidePosition2.getY()},
{slidePosition3.getX(), slidePosition3.getY()},
{slidePosition4.getX(), slidePosition4.getY()}
};
for (Map<String, Object> position : positionList) {
int index = (int) position.get("index"); //index 第几个玻片
Double[] upperLeft = {((Number) position.get("x1")).doubleValue(), ((Number) position.get("y1")).doubleValue()}; //范围左上角 x1y1
Double[] lowerRight = {((Number) position.get("x2")).doubleValue(), ((Number) position.get("y2")).doubleValue()}; //范围右下角 x2y2
Double[] slide = slideArr[index];//获取玻片的坐标
//规划路线坐标
DecimalFormat df = new DecimalFormat("#.##");
double left = Double.parseDouble(df.format(slide[0] + upperLeft[0]));
double right = Double.parseDouble(df.format(slide[0] + lowerRight[0]));
double top = Double.parseDouble(df.format(slide[1] + upperLeft[1]));
double bottom = Double.parseDouble(df.format(slide[1] + lowerRight[1]));
if ("horizontal".equals(matrixPathType)) {//喷涂路径类型 horizontal 横向 | vertical 纵向 | grid 网格先横向后纵向
for (int i = 1; i <= times; i++) {
double topReal = top;
double bottomReal = bottom;
double leftReal = left;
double rightReal = right;
if (i % 2 == 0) {//双数喷涂插空移动边界
double halfSpacing = spacing / 2;
topReal = top + halfSpacing;
bottomReal = bottomReal - halfSpacing;
leftReal = left + halfSpacing;
rightReal = right - halfSpacing;
}
List<PathGenerator.Points> pathList = PathGenerator.generatePathPoints(
leftReal, rightReal, topReal, bottomReal,
spacing,
PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN
);
List<List<DeviceCommand>> deviceCommandList = new ArrayList<>();
for (int j = 0; j < pathList.size(); j++) {
PathGenerator.Points p = pathList.get(j);
List<DeviceCommand> deviceCommands = new ArrayList<>();
if (j == pathList.size() - 1) {
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
} else {
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX(), movingSpeed));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
}
deviceCommandList.add(deviceCommands);
}
SprayTaskStep sprayTaskStep = new SprayTaskStep();
sprayTaskStep.setIndex(index);
sprayTaskStep.setSpraySteps(deviceCommandList);
sprayTask.getSprayTaskStepList().add(sprayTaskStep);
}
} else if ("vertical".equals(matrixPathType)) {
for (int i = 1; i <= times; i++) {
double topReal = top;
double bottomReal = bottom;
double leftReal = left;
double rightReal = right;
if (i % 2 == 0) {//双数喷涂插空移动边界
double halfSpacing = spacing / 2;
topReal = top + halfSpacing;
bottomReal = bottomReal - halfSpacing;
leftReal = left + halfSpacing;
rightReal = right - halfSpacing;
}
List<PathGenerator.Points> pathList = PathGenerator.generatePathPoints(
leftReal, rightReal, topReal, bottomReal,
spacing,
PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT
);
List<List<DeviceCommand>> deviceCommandList = new ArrayList<>();
for (int j = 0; j < pathList.size(); j++) {
PathGenerator.Points p = pathList.get(j);
List<DeviceCommand> deviceCommands = new ArrayList<>();
if (j == pathList.size() - 1) {
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
} else {
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
}
deviceCommandList.add(deviceCommands);
}
SprayTaskStep sprayTaskStep = new SprayTaskStep();
sprayTaskStep.setIndex(index);
sprayTaskStep.setSpraySteps(deviceCommandList);
sprayTask.getSprayTaskStepList().add(sprayTaskStep);
}
} else if ("grid".equals(matrixPathType)) {
for (int i = 1; i <= times; i++) {
double topReal = top;
double bottomReal = bottom;
double leftReal = left;
double rightReal = right;
double halfSpacing = spacing / 2;
if (i % 2 == 0) {//双数喷涂插空移动边界
topReal = top + halfSpacing;
bottomReal = bottomReal - halfSpacing;
leftReal = left + halfSpacing;
rightReal = right - halfSpacing;
}
List<PathGenerator.Points> pathList = PathGenerator.generatePathPoints(
leftReal, rightReal, topReal, bottomReal,
spacing,
PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN
);
List<List<DeviceCommand>> deviceCommandList = new ArrayList<>();
for (int j = 0; j < pathList.size(); j++) {
PathGenerator.Points p = pathList.get(j);
List<DeviceCommand> deviceCommands = new ArrayList<>();
if (j == pathList.size() - 1) {
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
} else {
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
}
deviceCommandList.add(deviceCommands);
}
SprayTaskStep sprayTaskStep = new SprayTaskStep();
sprayTaskStep.setIndex(index);
sprayTaskStep.setSpraySteps(deviceCommandList);
sprayTask.getSprayTaskStepList().add(sprayTaskStep);
pathList = PathGenerator.generatePathPoints(
leftReal, rightReal, topReal, bottomReal,
spacing,
PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT
);
deviceCommandList = new ArrayList<>();
for (int j = 0; j < pathList.size(); j++) {
PathGenerator.Points p = pathList.get(j);
List<DeviceCommand> deviceCommands = new ArrayList<>();
if (j == pathList.size() - 1) {
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
} else {
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
}
deviceCommandList.add(deviceCommands);
}
SprayTaskStep sprayTaskStep2 = new SprayTaskStep();
sprayTaskStep2.setIndex(index);
sprayTaskStep2.setSpraySteps(deviceCommandList);
sprayTask.getSprayTaskStepList().add(sprayTaskStep2);
}
}
}
return runAsync(() -> {
DeviceCommand overallDeviceStatusGetCommand = DeviceCommandGenerator.overallDeviceStatusGet();
CommandFuture overallDeviceStatusGetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), overallDeviceStatusGetCommand);
commandWait(overallDeviceStatusGetCommandFuture);
CommandFuture motorXOriginCommandFuture;
CommandFuture motorYOriginCommandFuture;
CommandFuture motorZOriginCommandFuture;
List<CommandFuture> futureList = new ArrayList<>();
if (!overallDeviceStatusGetCommandFuture.getResponseResult().getJSONObject("data").getBool("xAxisAtOrigin")) {
DeviceCommand motorXOriginCommand = DeviceCommandGenerator.motorXOrigin(); // x轴回原点
motorXOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXOriginCommand);
futureList.add(motorXOriginCommandFuture);
}
if (!overallDeviceStatusGetCommandFuture.getResponseResult().getJSONObject("data").getBool("yAxisAtOrigin")) {
DeviceCommand motorYOriginCommand = DeviceCommandGenerator.motorYOrigin();//y轴回原点
motorYOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYOriginCommand);
futureList.add(motorYOriginCommandFuture);
}
if (!overallDeviceStatusGetCommandFuture.getResponseResult().getJSONObject("data").getBool("zAxisAtOrigin")) {
DeviceCommand motorZOriginCommand = DeviceCommandGenerator.motorZOrigin();//z轴回原点
motorZOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZOriginCommand);
futureList.add(motorZOriginCommandFuture);
}
CommandFuture[] commandFutureArray = futureList.toArray(new CommandFuture[0]);
commandWait(commandFutureArray);
DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenNozzlePipeline();//打开三通阀注射器管路
CommandFuture threeWayValveOpenSyringePipelineCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), threeWayValveOpenSyringePipelineCommand);
commandWait(threeWayValveOpenSyringePipelineCommandFuture);
if (sprayTask.getSprayParams().getHighVoltage()) {//加电
DeviceCommand highVoltageOpenCommand = DeviceCommandGenerator.highVoltageOpen(highVoltageValue);//开启高压
CommandFuture highVoltageOpenCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), highVoltageOpenCommand);
commandWait(highVoltageOpenCommandFuture);
}
DeviceCommand nozzleValveOpenCommand = DeviceCommandGenerator.nozzleValveOpen();//开启喷嘴阀
CommandFuture nozzleValveOpenCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), nozzleValveOpenCommand);
commandWait(nozzleValveOpenCommandFuture);
// 10. 启动喷涂线程开始喷涂
sprayTaskExecutor.startTask();
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.SEND, "已开启喷涂线程"));
});
}
}
//package com.qyft.ms.app.front.cmd.business;
//
//import cn.hutool.json.JSONUtil;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.qyft.ms.app.common.generator.PathGenerator;
//import com.qyft.ms.app.device.spray.SprayTaskExecutor;
//import com.qyft.ms.app.device.status.DeviceStatus;
//import com.qyft.ms.app.device.status.SprayTask;
//import com.qyft.ms.app.model.bo.SprayTaskStep;
//import com.qyft.ms.app.model.entity.OperationLog;
//import com.qyft.ms.app.model.entity.Position;
//import com.qyft.ms.app.service.OperationLogService;
//import com.qyft.ms.app.service.PositionService;
//import com.qyft.ms.system.common.annotation.CommandMapping;
//import com.qyft.ms.system.common.constant.CommandStatus;
//import com.qyft.ms.system.common.device.command.CommandFuture;
//import com.qyft.ms.system.common.device.command.DeviceCommandGenerator;
//import com.qyft.ms.system.common.device.command.FrontResponseGenerator;
//import com.qyft.ms.system.common.utils.CheckedRunnable;
//import com.qyft.ms.system.common.utils.LambdaUtil;
//import com.qyft.ms.system.core.handler.BaseCommandHandler;
//import com.qyft.ms.system.model.bo.DeviceCommand;
//import com.qyft.ms.system.model.form.FrontCmdControlForm;
//import com.qyft.ms.system.service.WebSocketService;
//import com.qyft.ms.system.service.device.DeviceCommandService;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//import java.text.DecimalFormat;
//import java.util.*;
//import java.util.concurrent.CompletableFuture;
//import java.util.concurrent.ExecutorService;
//import java.util.concurrent.Executors;
//
///**
// * 喷涂_基质喷涂开始
// */
//@Slf4j
//@Component
//@RequiredArgsConstructor
//@CommandMapping("matrix_spray_start_bak")//业务指令注解
//public class MatrixSprayStart_bak extends BaseCommandHandler {
// private static final ExecutorService singleExecutor = Executors.newSingleThreadExecutor();
//
// private final SprayTaskExecutor sprayTaskExecutor;
// private final PositionService positionService;
// private final DeviceStatus deviceStatus;
// private final OperationLogService operationLogService;
// private final WebSocketService webSocketService;
// private final DeviceCommandService deviceCommandService;
//
// private void nonNullCheck(String cmdId, String cmdCode,
// String matrixPathType,
// Double motorZHeight,
// Double gasPressure,
// Double volume,
// Boolean highVoltage,
// Double spacing,
// Double movingSpeed,
// Double times,
// Object position) {
//
// Map<String, Object> paramMap = new LinkedHashMap<>();
// paramMap.put("matrix_path_type", matrixPathType);
// paramMap.put("motor_z_height", motorZHeight);
// paramMap.put("gas_pressure", gasPressure);
// paramMap.put("volume", volume);
// paramMap.put("high_voltage", highVoltage);
// paramMap.put("spacing", spacing);
// paramMap.put("moving_speed", movingSpeed);
// paramMap.put("times", times);
// paramMap.put("position", position);
//
// // 遍历 Map 检查是否为 null
// for (Map.Entry<String, Object> entry : paramMap.entrySet()) {
// if (entry.getValue() == null) {
// String errorMsg = "参数 " + entry.getKey() + " 必填";
// webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.DEVICE_ERROR, errorMsg));
// throw new RuntimeException(errorMsg);
// }
// }
// }
//
// /**
// * 使用单线程执行器保证线程安全防止喷涂指令被多次调用
// */
// @Override
// protected CompletableFuture<Void> runAsync(CheckedRunnable task) {
// return CompletableFuture.runAsync(LambdaUtil.unchecked(task), singleExecutor);
// }
//
// /**
// * {
// * cmdName:'matrix_spray_start'
// * cmdId:'',
// * param:{
// * matrix_path_type:horizontal | vertical | grid;//喷涂路径类型
// * motor_z_height:;//高度 Z轴距离玻片的高度
// * gas_pressure://Mpa兆帕 不处理
// * volume:20//单位uL微升 基质流速(控制注射泵速度)
// * high_voltage:true/false;//是否打开高压
// * high_voltage_value:4000;//高压值
// * spacing:''//毫米 间距
// * moving_speed:8mm/s;//移动速度 轴速度
// * times:;//喷涂遍数
// * position:[{x1,y1,x2,y2,index}]
// * }
// * }
// */
// @Override
// public CompletableFuture<Void> handle(FrontCmdControlForm form) {
// SprayTask sprayTask = SprayTask.getInstance();
// if (sprayTask.isSpraying()) {//判断设备是否正在喷涂
// webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "设备正在喷涂,请先停止喷涂"));
// throw new RuntimeException("设备正在喷涂,请先停止喷涂");
// }
// sprayTask.setCmdId(form.getCmdId());
// sprayTask.setCmdCode(form.getCmdCode());
// sprayTask.setSpraying(true);//正在进行喷涂
// deviceStatus.setSpraying(true);
//
// // 1. 参数校验
// String matrixPathType = form.getStringParam("matrixPathType");
// Double motorZHeight = form.getDoubleParam("motorZHeight");
// Double gasPressure = form.getDoubleParam("gasPressure");
// Double volume = form.getDoubleParam("volume");
// Boolean highVoltage = form.getBooleanParam("highVoltage");
// Double highVoltageValue = form.getDoubleParam("highVoltageValue");
// Double spacing = form.getDoubleParam("spacing");
// Double movingSpeed = form.getDoubleParam("movingSpeed");
// Double times = form.getDoubleParam("times");
// @SuppressWarnings("unchecked")
// List<Map<String, Object>> positionList = (List<Map<String, Object>>) form.getParams().get("position");
//
// nonNullCheck(matrixPathType, form.getCmdId(), form.getCmdCode(), motorZHeight, gasPressure, volume, highVoltage, spacing, movingSpeed, times, positionList);
// if (highVoltageValue != null && highVoltageValue > 6000) {
// webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "电压不能大于6000V"));
// throw new RuntimeException("电压不能大于6000V");
// }
// if (positionList.isEmpty()) {
// webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "喷涂区域不能为空"));
// throw new RuntimeException("喷涂区域不能为空");
// }
// // 3. 设定喷涂参数
// sprayTask.setSprayParam(matrixPathType, motorZHeight, gasPressure, volume, highVoltage, highVoltageValue, spacing, movingSpeed, times, positionList);
// sprayTask.setCacheParams(form.getParams());
//
// OperationLog operationLog = new OperationLog();
// Long matrixCraftId = Long.valueOf(Optional.ofNullable(sprayTask.getCacheParams().get("matrixCraftId"))
// .filter(Number.class::isInstance)
// .map(Number.class::cast)
// .map(Number::intValue)
// .orElse(0));
// operationLog.setMatrixId(matrixCraftId);
// operationLog.setMatrixInfo(JSONUtil.toJsonStr(sprayTask.getCacheParams()));
// operationLogService.add(operationLog);
//
// // 7.循环喷涂区域
// 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"));
// Double[][] slideArr = {
// {slidePosition1.getX(), slidePosition1.getY()},
// {slidePosition2.getX(), slidePosition2.getY()},
// {slidePosition3.getX(), slidePosition3.getY()},
// {slidePosition4.getX(), slidePosition4.getY()}
// };
// for (Map<String, Object> position : positionList) {
// int index = (int) position.get("index"); //index 第几个玻片
// Double[] upperLeft = {((Number) position.get("x1")).doubleValue(), ((Number) position.get("y1")).doubleValue()}; //范围左上角 x1y1
// Double[] lowerRight = {((Number) position.get("x2")).doubleValue(), ((Number) position.get("y2")).doubleValue()}; //范围右下角 x2y2
// Double[] slide = slideArr[index];//获取玻片的坐标
// //规划路线坐标
// DecimalFormat df = new DecimalFormat("#.##");
// double left = Double.parseDouble(df.format(slide[0] + upperLeft[0]));
// double right = Double.parseDouble(df.format(slide[0] + lowerRight[0]));
// double top = Double.parseDouble(df.format(slide[1] + upperLeft[1]));
// double bottom = Double.parseDouble(df.format(slide[1] + lowerRight[1]));
// if ("horizontal".equals(matrixPathType)) {//喷涂路径类型 horizontal 横向 | vertical 纵向 | grid 网格先横向后纵向
// for (int i = 1; i <= times; i++) {
// double topReal = top;
// double bottomReal = bottom;
// double leftReal = left;
// double rightReal = right;
// if (i % 2 == 0) {//双数喷涂插空移动边界
// double halfSpacing = spacing / 2;
// topReal = top + halfSpacing;
// bottomReal = bottomReal - halfSpacing;
// leftReal = left + halfSpacing;
// rightReal = right - halfSpacing;
// }
// List<PathGenerator.Points> pathList = PathGenerator.generatePathPoints(
// leftReal, rightReal, topReal, bottomReal,
// spacing,
// PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN
// );
// List<List<DeviceCommand>> deviceCommandList = new ArrayList<>();
//
// for (int j = 0; j < pathList.size(); j++) {
// PathGenerator.Points p = pathList.get(j);
// List<DeviceCommand> deviceCommands = new ArrayList<>();
// if (j == pathList.size() - 1) {
// deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
// deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
// } else {
// deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX(), movingSpeed));//移动x轴
// deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
// }
// deviceCommandList.add(deviceCommands);
// }
//
// SprayTaskStep sprayTaskStep = new SprayTaskStep();
// sprayTaskStep.setIndex(index);
// sprayTaskStep.setSprayPathPointList(deviceCommandList);
// sprayTask.getSprayTaskStepList().add(sprayTaskStep);
// }
// } else if ("vertical".equals(matrixPathType)) {
// for (int i = 1; i <= times; i++) {
// double topReal = top;
// double bottomReal = bottom;
// double leftReal = left;
// double rightReal = right;
// if (i % 2 == 0) {//双数喷涂插空移动边界
// double halfSpacing = spacing / 2;
// topReal = top + halfSpacing;
// bottomReal = bottomReal - halfSpacing;
// leftReal = left + halfSpacing;
// rightReal = right - halfSpacing;
// }
// List<PathGenerator.Points> pathList = PathGenerator.generatePathPoints(
// leftReal, rightReal, topReal, bottomReal,
// spacing,
// PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT
// );
// List<List<DeviceCommand>> deviceCommandList = new ArrayList<>();
// for (int j = 0; j < pathList.size(); j++) {
// PathGenerator.Points p = pathList.get(j);
// List<DeviceCommand> deviceCommands = new ArrayList<>();
// if (j == pathList.size() - 1) {
// deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
// deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
// } else {
// deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
// deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
// }
// deviceCommandList.add(deviceCommands);
// }
// SprayTaskStep sprayTaskStep = new SprayTaskStep();
// sprayTaskStep.setIndex(index);
// sprayTaskStep.setSprayPathPointList(deviceCommandList);
// sprayTask.getSprayTaskStepList().add(sprayTaskStep);
// }
// } else if ("grid".equals(matrixPathType)) {
// for (int i = 1; i <= times; i++) {
// double topReal = top;
// double bottomReal = bottom;
// double leftReal = left;
// double rightReal = right;
// double halfSpacing = spacing / 2;
// if (i % 2 == 0) {//双数喷涂插空移动边界
// topReal = top + halfSpacing;
// bottomReal = bottomReal - halfSpacing;
// leftReal = left + halfSpacing;
// rightReal = right - halfSpacing;
// }
// List<PathGenerator.Points> pathList = PathGenerator.generatePathPoints(
// leftReal, rightReal, topReal, bottomReal,
// spacing,
// PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN
// );
// List<List<DeviceCommand>> deviceCommandList = new ArrayList<>();
// for (int j = 0; j < pathList.size(); j++) {
// PathGenerator.Points p = pathList.get(j);
// List<DeviceCommand> deviceCommands = new ArrayList<>();
// if (j == pathList.size() - 1) {
// deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
// deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
// } else {
// deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
// deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
// }
// deviceCommandList.add(deviceCommands);
// }
// SprayTaskStep sprayTaskStep = new SprayTaskStep();
// sprayTaskStep.setIndex(index);
// sprayTaskStep.setSprayPathPointList(deviceCommandList);
// sprayTask.getSprayTaskStepList().add(sprayTaskStep);
//
// pathList = PathGenerator.generatePathPoints(
// leftReal, rightReal, topReal, bottomReal,
// spacing,
// PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT
// );
// deviceCommandList = new ArrayList<>();
// for (int j = 0; j < pathList.size(); j++) {
// PathGenerator.Points p = pathList.get(j);
// List<DeviceCommand> deviceCommands = new ArrayList<>();
// if (j == pathList.size() - 1) {
// deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
// deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
// } else {
// deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
// deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
// }
// deviceCommandList.add(deviceCommands);
// }
// SprayTaskStep sprayTaskStep2 = new SprayTaskStep();
// sprayTaskStep2.setIndex(index);
// sprayTaskStep2.setSprayPathPointList(deviceCommandList);
// sprayTask.getSprayTaskStepList().add(sprayTaskStep2);
// }
// }
// }
// return runAsync(() -> {
// DeviceCommand overallDeviceStatusGetCommand = DeviceCommandGenerator.overallDeviceStatusGet();
// CommandFuture overallDeviceStatusGetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), overallDeviceStatusGetCommand);
// commandWait(overallDeviceStatusGetCommandFuture);
//
// CommandFuture motorXOriginCommandFuture;
// CommandFuture motorYOriginCommandFuture;
// CommandFuture motorZOriginCommandFuture;
//
// List<CommandFuture> futureList = new ArrayList<>();
// if (!overallDeviceStatusGetCommandFuture.getResponseResult().getJSONObject("data").getBool("xAxisAtOrigin")) {
// DeviceCommand motorXOriginCommand = DeviceCommandGenerator.motorXOrigin(); // x轴回原点
// motorXOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXOriginCommand);
// futureList.add(motorXOriginCommandFuture);
// }
// if (!overallDeviceStatusGetCommandFuture.getResponseResult().getJSONObject("data").getBool("yAxisAtOrigin")) {
// DeviceCommand motorYOriginCommand = DeviceCommandGenerator.motorYOrigin();//y轴回原点
// motorYOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYOriginCommand);
// futureList.add(motorYOriginCommandFuture);
// }
// if (!overallDeviceStatusGetCommandFuture.getResponseResult().getJSONObject("data").getBool("zAxisAtOrigin")) {
// DeviceCommand motorZOriginCommand = DeviceCommandGenerator.motorZOrigin();//z轴回原点
// motorZOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZOriginCommand);
// futureList.add(motorZOriginCommandFuture);
// }
// CommandFuture[] commandFutureArray = futureList.toArray(new CommandFuture[0]);
// commandWait(commandFutureArray);
//
// DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenNozzlePipeline();//打开三通阀注射器管路
// CommandFuture threeWayValveOpenSyringePipelineCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), threeWayValveOpenSyringePipelineCommand);
// commandWait(threeWayValveOpenSyringePipelineCommandFuture);
//
// if (sprayTask.getSprayParams().getHighVoltage()) {//加电
// DeviceCommand highVoltageOpenCommand = DeviceCommandGenerator.highVoltageOpen(highVoltageValue);//开启高压
// CommandFuture highVoltageOpenCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), highVoltageOpenCommand);
// commandWait(highVoltageOpenCommandFuture);
// }
//
// DeviceCommand nozzleValveOpenCommand = DeviceCommandGenerator.nozzleValveOpen();//开启喷嘴阀
// CommandFuture nozzleValveOpenCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), nozzleValveOpenCommand);
// commandWait(nozzleValveOpenCommandFuture);
//
// // 10. 启动喷涂线程开始喷涂
// sprayTaskExecutor.startTask();
// webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.SEND, "已开启喷涂线程"));
// });
// }
//
//
//}

6
src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStop.java

@ -40,13 +40,13 @@ public class MatrixSprayStop extends BaseCommandHandler {
if (!sprayTask.isSpraying()) {
throw new RuntimeException("设备没有正在喷涂");
}
if (sprayTask.isClosing()) {
if (sprayTask.isClose()) {
throw new RuntimeException("正在结束喷涂,请稍后");
}
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束"));
return runAsync(() -> {
sprayTask.setClosing(true);
sprayTask.setClose(true);
try {
sprayTaskExecutor.stopTask();//终止喷涂任务线程
@ -80,7 +80,7 @@ public class MatrixSprayStop extends BaseCommandHandler {
deviceStatus.setPaused(false);
deviceStatus.setSuspendable(false);
} finally {
sprayTask.setClosing(false);
sprayTask.setClose(false);
}
});

4
src/main/java/com/qyft/ms/app/model/bo/Point2D.java

@ -4,8 +4,8 @@ import lombok.Data;
@Data
public class Point2D {
private double x;
private double y;
public double x;
public double y;
public Point2D(double x, double y) {
this.x = x;

10
src/main/java/com/qyft/ms/app/model/bo/SprayTaskStep.java

@ -1,6 +1,5 @@
package com.qyft.ms.app.model.bo;
import com.qyft.ms.system.model.bo.DeviceCommand;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -10,13 +9,8 @@ import java.util.List;
@Schema(description = "喷涂任务点位步骤")
public class SprayTaskStep {
/**
* 玻片序号
*/
@Schema(description = "玻片序号")
private Integer index;
/**
* 单词喷涂的完整路线步骤
*/
@Schema(description = "单喷涂的完整路线步骤")
private List<List<DeviceCommand>> spraySteps;
@Schema(description = "单次喷涂的完整路线步骤")
private List<Point2D> sprayPathPointList;
}

6
src/main/java/com/qyft/ms/app/model/bo/SprayTimes.java

@ -25,16 +25,16 @@ public class SprayTimes {
@Schema(description = "高压值")
private Double highVoltageValue;
@Schema(description = " 喷涂间距(毫米)")
@Schema(description = "喷涂间距(毫米)")
private Double spacing;
@Schema(description = "轴移动速度")
private Double movingSpeed;
@Schema(description = "田字格喷涂中间延时毫秒数,非田字格不传递该参数")
@Schema(description = "田字格喷涂中间延时数,非田字格不传递该参数")
private Double gridDelay;
@Schema(description = "本次喷涂结束后延时毫秒数")
@Schema(description = "本次喷涂结束后延时数")
private Double delay;
@Schema(description = "喷涂左上角x")

15
src/main/java/com/qyft/ms/app/service/SprayTaskService.java

@ -1,8 +1,14 @@
package com.qyft.ms.app.service;
import com.qyft.ms.app.device.status.SprayTask;
import com.qyft.ms.app.model.bo.SprayTaskParams;
import com.qyft.ms.app.model.dto.SetSprayTaskParamsDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Comparator;
import java.util.List;
/**
* 喷涂任务服务
*/
@ -10,4 +16,13 @@ import org.springframework.stereotype.Service;
@RequiredArgsConstructor
public class SprayTaskService {
public void setSprayParams(SetSprayTaskParamsDTO setSprayTaskParamsDTO){
if(setSprayTaskParamsDTO.getSprayTaskParams() != null){
SprayTask sprayTask = SprayTask.getInstance();
List<SprayTaskParams> sprayTaskParams = setSprayTaskParamsDTO.getSprayTaskParams();
sprayTaskParams.sort(Comparator.comparing(SprayTaskParams::getIndex));
sprayTask.setSprayTaskParams(sprayTaskParams);
}
}
}

8
src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java

@ -30,6 +30,7 @@ public class DeviceCommandService {
private final WebSocketService webSocketService;
private final DeviceStatus deviceStatus;
private final ApplicationEventPublisher publisher;
private final Object pauseLock = new Object();
public CommandFuture executeCommand(DeviceCommand cmdToDevice) {
int cmdId = CyclicNumberGenerator.getInstance().generateNumber();
@ -75,7 +76,12 @@ public class DeviceCommandService {
public CommandFuture sendCommandSprayTask(String cmdId, String cmdCode, DeviceCommand deviceCommand) throws Exception {
SprayTask sprayTask = SprayTask.getInstance();
if (sprayTask.isClosing() || Thread.currentThread().isInterrupted()) {
synchronized (pauseLock) {
while (sprayTask.isPaused()) {
pauseLock.wait();
}
}
if (sprayTask.isClose() || Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
return sendCommand(cmdId, cmdCode, deviceCommand);

Loading…
Cancel
Save