Browse Source

feat:停止喷涂功能

master
白凤吉 3 weeks ago
parent
commit
381df1047a
  1. 96
      src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor_bak.java
  2. 3
      src/main/java/com/qyft/ms/app/device/status/SprayTask.java
  3. 1
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart.java
  4. 5
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStop.java
  5. 7
      src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java

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

@ -2,10 +2,12 @@
//
//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.bo.Point2D;
//import com.qyft.ms.app.model.bo.SprayTaskPointCollectorPushBO;
//import com.qyft.ms.app.model.bo.SprayTaskSprayed;
//import com.qyft.ms.app.model.bo.SprayTaskStep;
//import com.qyft.ms.app.model.entity.Position;
//import com.qyft.ms.app.model.entity.SysSettings;
//import com.qyft.ms.app.service.PositionService;
@ -27,14 +29,13 @@
//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 {
//public class SprayTaskExecutor {
// private final WebSocketService webSocketService;
// private final DeviceCommandService deviceCommandService;
// private final SysSettingsService sysSettingsService;
@ -71,6 +72,7 @@
//
// taskThread = new Thread(() -> {
// try {
// webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.START, "喷涂任务开始执行"));
// int reCurrentStep = sprayTask.getCurrentStep();
// int currentStep = 0; //当前喷涂步骤
// int sprayCount = 0;
@ -81,6 +83,8 @@
// //先移动到玻片位置
// 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.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXPositionSetCommand);
// CommandFuture motorYPositionSetCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYPositionSetCommand);
// CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXPositionSetCommand);
// CommandFuture motorYPositionSetCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYPositionSetCommand);
//
@ -88,6 +92,7 @@
// Double slideHeight = Double.parseDouble(slideHeightSysSettings.getValue());
// Double height = slideHeight - sprayTask.getSprayParams().getMotorZHeight();//下降z轴高度
// DeviceCommand motorZPositionSetAboveSlideCommand = DeviceCommandGenerator.motorZPositionSet(height, 15.0);
// CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand);
// CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand);
// commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture, motorZPositionSetAboveSlideCommandFuture);
// }
@ -97,7 +102,7 @@
// double cacheXPoint = -1;
// double cacheYPoint = -1;
// DecimalFormat df = new DecimalFormat("#.##");
// for (int i = 0; i < sprayTaskStep.getSprayPathPointList().size(); i++) {//单次喷涂
// for (int i = 0; i < sprayTaskStep.getSpraySteps().size(); i++) {//单次喷涂
// if (currentIndex != sprayTaskStep.getIndex()) {
// sprayNum = 0;
// currentIndex = sprayTaskStep.getIndex();
@ -108,11 +113,12 @@
// }
// if(i == 1){
// DeviceCommand syringePumpForwardCommand = DeviceCommandGenerator.syringePumpForward(sprayTask.getSprayParams().getVolume());//推动移动注射泵
// CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpForwardCommand);
// CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpForwardCommand);
// commandWait(syringePumpForwardCommandFuture);
// }
// sprayTask.setFirstImmobility(true);
// List<DeviceCommand> sprayStepCommands = sprayTaskStep.getSprayPathPointList().get(i);
// List<DeviceCommand> sprayStepCommands = sprayTaskStep.getSpraySteps().get(i);
// DeviceCommand xSprayStepCommands = sprayStepCommands.get(0);
// xSprayStepCommands.getParam().put("speed", sprayTask.getSprayParams().getMovingSpeed());//防止修改了移动速度这里重新设置移动速度
// DeviceCommand ySprayStepCommands = sprayStepCommands.get(1);
@ -125,11 +131,13 @@
// ySprayStepCommands.getParam().put("position", Double.parseDouble(df.format(aYPoint)));
//
// if (cacheXPoint != aXPoint) {
// CommandFuture commandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), xSprayStepCommands);
// CommandFuture commandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), xSprayStepCommands);
// commandFutureList.add(commandFuture);
// cacheXPoint = aXPoint;
// }
// if (cacheYPoint != aYPoint) {
// CommandFuture commandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), ySprayStepCommands);
// CommandFuture commandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), ySprayStepCommands);
// commandFutureList.add(commandFuture);
// cacheYPoint = aYPoint;
@ -158,6 +166,7 @@
// deviceStatus.setSuspendable(false);
// if (currentStep >= reCurrentStep) {
// DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop();//停止推动注射泵
// CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpStopCommand);
// CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpStopCommand);
// commandWait(syringePumpStopCommandFuture);
// }
@ -166,10 +175,12 @@
// }
//
// DeviceCommand highVoltageCloseCommand = DeviceCommandGenerator.highVoltageClose();//关闭高压
// CommandFuture highVoltageCloseCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), highVoltageCloseCommand);
// CommandFuture highVoltageCloseCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), highVoltageCloseCommand);
// commandWait(highVoltageCloseCommandFuture);
// Thread.sleep(500);
// DeviceCommand nozzleValveCloseCommand = DeviceCommandGenerator.nozzleValveClose();//关闭喷嘴阀
// CommandFuture nozzleValveCloseCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), nozzleValveCloseCommand);
// CommandFuture nozzleValveCloseCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), nozzleValveCloseCommand);
// commandWait(nozzleValveCloseCommandFuture);
//
@ -177,6 +188,9 @@
// DeviceCommand motorXOriginCommand = DeviceCommandGenerator.motorXOrigin();
// DeviceCommand motorYOriginCommand = DeviceCommandGenerator.motorYOrigin();
// DeviceCommand motorZOriginCommand = DeviceCommandGenerator.motorZOrigin();
// CommandFuture motorXOriginCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXOriginCommand);
// CommandFuture motorYOriginCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYOriginCommand);
// CommandFuture motorZOriginCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZOriginCommand);
// 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);
@ -214,6 +228,9 @@
//
// /**
// * 停止任务线程
// * 1. 直接中断线程不再关心 CompletableFuture 的等待和结果
// * 2. 可选择等待一定时间让线程自行退出 join 超时 2
// * 3. 清空线程引用防止内存泄露
// */
// public synchronized void stopTask() {
// if (taskThread != null && taskThread.isAlive()) {
@ -231,70 +248,5 @@
// .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;
// }
//}
//

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

@ -41,6 +41,9 @@ public class SprayTask {
*/
private volatile boolean spraying = false;
private final Object pauseLock = new Object();
private final Object closeLock = new Object();
private SprayTask() {
}

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

@ -71,6 +71,7 @@ public class MatrixSprayStart extends BaseCommandHandler {
}
sprayTask.setCmdId(form.getCmdId());
sprayTask.setCmdCode(form.getCmdCode());
sprayTask.setClose(false);
sprayTask.setSpraying(true);//正在进行喷涂
deviceStatus.setSpraying(true);

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

@ -47,7 +47,6 @@ public class MatrixSprayStop extends BaseCommandHandler {
return runAsync(() -> {
sprayTask.setClose(true);
try {
sprayTaskExecutor.stopTask();//终止喷涂任务线程
DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop(); //停止推动注射泵
@ -79,10 +78,6 @@ public class MatrixSprayStop extends BaseCommandHandler {
deviceStatus.setSpraying(false);
deviceStatus.setPaused(false);
deviceStatus.setSuspendable(false);
} finally {
sprayTask.setClose(false);
}
});
}
}

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

@ -30,7 +30,6 @@ 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();
@ -76,14 +75,16 @@ public class DeviceCommandService {
public CommandFuture sendCommandSprayTask(String cmdId, String cmdCode, DeviceCommand deviceCommand) throws Exception {
SprayTask sprayTask = SprayTask.getInstance();
synchronized (pauseLock) {
synchronized (sprayTask.getPauseLock()) {
while (sprayTask.isPaused()) {
pauseLock.wait();
sprayTask.getPauseLock().wait();
}
}
synchronized (sprayTask.getCloseLock()) {
if (sprayTask.isClose() || Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
}
return sendCommand(cmdId, cmdCode, deviceCommand);
}

Loading…
Cancel
Save