18 changed files with 1270 additions and 824 deletions
-
42src/main/java/com/qyft/ms/app/common/generator/PathGenerator.java
-
5src/main/java/com/qyft/ms/app/controller/SprayTaskController.java
-
213src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java
-
300src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor_bak.java
-
2src/main/java/com/qyft/ms/app/device/status/DeviceStatus.java
-
111src/main/java/com/qyft/ms/app/device/status/SprayTask.java
-
150src/main/java/com/qyft/ms/app/device/status/SprayTask_bak.java
-
192src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayChangeParam.java
-
134src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayContinue.java
-
128src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayPause.java
-
38src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart.java
-
730src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart_bak.java
-
6src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStop.java
-
4src/main/java/com/qyft/ms/app/model/bo/Point2D.java
-
10src/main/java/com/qyft/ms/app/model/bo/SprayTaskStep.java
-
6src/main/java/com/qyft/ms/app/model/bo/SprayTimes.java
-
15src/main/java/com/qyft/ms/app/service/SprayTaskService.java
-
8src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.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()}; //范围左上角 x1,y1 |
|||
// Double[] lowerRight = {sprayTimes.getX2(), sprayTimes.getY2()}; //范围左上角 x1,y1 |
|||
// 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; |
|||
// } |
|||
//} |
@ -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(); |
|||
} |
|||
|
|||
} |
@ -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); |
|||
// |
|||
// }); |
|||
// |
|||
// } |
|||
//} |
@ -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(); |
|||
// }); |
|||
// |
|||
// } |
|||
//} |
@ -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); |
|||
// }); |
|||
// } |
|||
//} |
@ -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()}; //范围左上角 x1,y1 |
|||
Double[] lowerRight = {((Number) position.get("x2")).doubleValue(), ((Number) position.get("y2")).doubleValue()}; //范围右下角 x2,y2 |
|||
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()}; //范围左上角 x1,y1 |
|||
// Double[] lowerRight = {((Number) position.get("x2")).doubleValue(), ((Number) position.get("y2")).doubleValue()}; //范围右下角 x2,y2 |
|||
// 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, "已开启喷涂线程")); |
|||
// }); |
|||
// } |
|||
// |
|||
// |
|||
//} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue