Browse Source

fix:喷涂流程调整,暂停方式调整

master
白凤吉 3 weeks ago
parent
commit
fc663e131d
  1. 84
      src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java
  2. 6
      src/main/java/com/qyft/ms/app/device/status/DeviceStatus.java
  3. 14
      src/main/java/com/qyft/ms/app/device/status/SprayTask.java
  4. 8
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayContinue.java
  5. 29
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayPause.java
  6. 2
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart.java
  7. 1
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStop.java
  8. 9
      src/main/java/com/qyft/ms/app/model/bo/Point3D.java
  9. 9
      src/main/java/com/qyft/ms/app/model/bo/SprayTaskPointCollectorPushBO.java
  10. 4
      src/main/java/com/qyft/ms/app/model/bo/SprayTimes.java
  11. 7
      src/main/java/com/qyft/ms/app/service/VirtualDeviceService.java
  12. 1
      src/main/java/com/qyft/ms/system/core/listener/DeviceTcpMessageEventListener.java
  13. 7
      src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java

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

@ -67,41 +67,24 @@ public class SprayTaskExecutor {
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.DEVICE_ERROR, "设备正在喷涂,请先停止喷涂")); webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.DEVICE_ERROR, "设备正在喷涂,请先停止喷涂"));
return; return;
} }
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()}
};
taskThread = new Thread(() -> { taskThread = new Thread(() -> {
try { try {
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.START, "喷涂任务开始执行")); webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.START, "喷涂任务开始执行"));
List<SprayTaskParams> sprayTaskParams = sprayTask.getSprayTaskParams(); List<SprayTaskParams> sprayTaskParams = sprayTask.getSprayTaskParams();
DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenNozzlePipeline();//打开三通阀注射器管路
CommandFuture threeWayValveOpenSyringePipelineCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), threeWayValveOpenSyringePipelineCommand);
commandWait(threeWayValveOpenSyringePipelineCommandFuture);
DeviceCommand nozzleValveOpenCommand = DeviceCommandGenerator.nozzleValveOpen();//开启喷嘴阀
CommandFuture nozzleValveOpenCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), nozzleValveOpenCommand);
commandWait(nozzleValveOpenCommandFuture);
int currentStep = 0; //当前喷涂步骤
int sprayCount = 0;
int sprayNum = 1;
int currentIndex = 0;
int currentStep = 0; //不管是暂停还是新的线程记录当前线程喷涂步骤序号
int sprayNum = 1; //当前玻片是第几次喷涂
for (SprayTaskParams sprayTaskParam : sprayTaskParams) {//循环玻片 for (SprayTaskParams sprayTaskParam : sprayTaskParams) {//循环玻片
if (sprayTask.getCurrentIndex() != null && sprayTaskParam.getIndex() > sprayTask.getCurrentIndex()) {
continue;
}
sprayTask.setCurrentIndex(sprayTaskParam.getIndex());
for (SprayTimes sprayTimes : sprayTaskParam.getTimes()) {//每个拨片有多次喷涂循环每次喷涂 for (SprayTimes sprayTimes : sprayTaskParam.getTimes()) {//每个拨片有多次喷涂循环每次喷涂
sprayTask.setSprayTimes(sprayTimes); sprayTask.setSprayTimes(sprayTimes);
Double[] slide = slideArr[sprayTaskParam.getIndex()];//获取玻片的坐标 Double[] slide = slideArr[sprayTaskParam.getIndex()];//获取玻片的坐标
List<SprayTaskStep> sprayTaskStepList = getSprayPath(sprayTaskParam.getIndex(), sprayTimes);//计算本次喷涂的路线 List<SprayTaskStep> sprayTaskStepList = getSprayPath(sprayTaskParam.getIndex(), sprayTimes);//计算本次喷涂的路线
//先移动到玻片位置
//先移动到玻片左上角位置
DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(slideArr[sprayTaskParam.getIndex()][0], 20.0); DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(slideArr[sprayTaskParam.getIndex()][0], 20.0);
DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(75.5 - slideArr[sprayTaskParam.getIndex()][1], 20.0); DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(75.5 - slideArr[sprayTaskParam.getIndex()][1], 20.0);
CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXPositionSetCommand); CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXPositionSetCommand);
@ -113,10 +96,31 @@ public class SprayTaskExecutor {
DeviceCommand motorZPositionSetAboveSlideCommand = DeviceCommandGenerator.motorZPositionSet(height, 15.0); DeviceCommand motorZPositionSetAboveSlideCommand = DeviceCommandGenerator.motorZPositionSet(height, 15.0);
CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand); CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand);
commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture, motorZPositionSetAboveSlideCommandFuture); commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture, motorZPositionSetAboveSlideCommandFuture);
Thread.sleep(100);
DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenNozzlePipeline();//打开三通阀注射器管路
CommandFuture threeWayValveOpenSyringePipelineCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), threeWayValveOpenSyringePipelineCommand);
DeviceCommand nozzleValveOpenCommand = DeviceCommandGenerator.nozzleValveOpen();//开启喷嘴阀
CommandFuture nozzleValveOpenCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), nozzleValveOpenCommand);
commandWait(threeWayValveOpenSyringePipelineCommandFuture, nozzleValveOpenCommandFuture);
delay(500);
//判断是否有暂停的点位如果有则还原暂停时的点位
Point3D currentPausedPoint = sprayTask.getCurrentPausedPoint();
if (currentPausedPoint != null) {
DeviceCommand motorXRestoreCommand = DeviceCommandGenerator.motorXPositionSet(currentPausedPoint.x, 20.0);
DeviceCommand motorYRestoreCommand = DeviceCommandGenerator.motorYPositionSet(currentPausedPoint.y, 20.0);
DeviceCommand motorZRestoreCommand = DeviceCommandGenerator.motorZPositionSet(currentPausedPoint.z, 20.0);
CommandFuture motorXRestoreCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXRestoreCommand);
CommandFuture motorYRestoreCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYRestoreCommand);
CommandFuture motorZRestoreCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZRestoreCommand);
commandWait(motorXRestoreCommandFuture, motorYRestoreCommandFuture, motorZRestoreCommandFuture);
sprayTask.setCurrentPausedPoint(null);
}
//因为走的是折现所以单词指令只需要移动x或y缓存上一个点位用来判断本次是走x还是y
double cacheXPoint = -1; double cacheXPoint = -1;
double cacheYPoint = -1; double cacheYPoint = -1;
sprayNum++;
for (SprayTaskStep sprayTaskStep : sprayTaskStepList) {//因为田字格喷涂其实是两次 for (SprayTaskStep sprayTaskStep : sprayTaskStepList) {//因为田字格喷涂其实是两次
if (sprayTimes.getHighVoltage()) {//加电 if (sprayTimes.getHighVoltage()) {//加电
DeviceCommand highVoltageOpenCommand = DeviceCommandGenerator.highVoltageOpen(sprayTimes.getHighVoltageValue());//开启高压 DeviceCommand highVoltageOpenCommand = DeviceCommandGenerator.highVoltageOpen(sprayTimes.getHighVoltageValue());//开启高压
@ -128,6 +132,10 @@ public class SprayTaskExecutor {
CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpForwardCommand); CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpForwardCommand);
commandWait(syringePumpForwardCommandFuture); commandWait(syringePumpForwardCommandFuture);
for (int i = 0; i < sprayTaskStep.getSprayPathPointList().size(); i++) {//循环路线 for (int i = 0; i < sprayTaskStep.getSprayPathPointList().size(); i++) {//循环路线
if (currentStep < sprayTask.getCurrentStep()) {
currentStep++;
continue;
}
Point2D currentPoint = sprayTaskStep.getSprayPathPointList().get(i); Point2D currentPoint = sprayTaskStep.getSprayPathPointList().get(i);
List<CommandFuture> commandFutureList = new ArrayList<>(); List<CommandFuture> commandFutureList = new ArrayList<>();
if (cacheXPoint != currentPoint.x) { if (cacheXPoint != currentPoint.x) {
@ -142,19 +150,19 @@ public class SprayTaskExecutor {
commandFutureList.add(commandFuture); commandFutureList.add(commandFuture);
cacheYPoint = currentPoint.y; cacheYPoint = currentPoint.y;
} }
SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayTaskParam.getIndex(), sprayNum, sprayCount, currentPoint);
SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayTaskParam.getIndex(), sprayNum, currentPoint);
webSocketService.pushMsg(WebSocketMessageType.SPRAY_POINT, sprayTaskPointCollectorPushBO);//向前端推送当前路径 webSocketService.pushMsg(WebSocketMessageType.SPRAY_POINT, sprayTaskPointCollectorPushBO);//向前端推送当前路径
CommandFuture[] commandFutureArray = commandFutureList.toArray(new CommandFuture[0]); CommandFuture[] commandFutureArray = commandFutureList.toArray(new CommandFuture[0]);
commandWait(commandFutureArray); commandWait(commandFutureArray);
currentStep++;//当前喷涂步数自增
currentStep++;//当前喷涂步数因为暂停可能本次路线还没走完所以这里只有在走完一次路线后才会自增
sprayTask.setCurrentStep(currentStep);
} }
//一次喷涂完毕后停止推注射泵 //一次喷涂完毕后停止推注射泵
DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop();//停止推动注射泵 DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop();//停止推动注射泵
CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpStopCommand); CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpStopCommand);
commandWait(syringePumpStopCommandFuture); commandWait(syringePumpStopCommandFuture);
} }
sprayCount++;
sprayNum++; sprayNum++;
} }
} }
@ -176,6 +184,10 @@ public class SprayTaskExecutor {
CommandFuture motorZOriginCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZOriginCommand); CommandFuture motorZOriginCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZOriginCommand);
commandWait(motorXOriginCommandFuture, motorYOriginCommandFuture, motorZOriginCommandFuture); commandWait(motorXOriginCommandFuture, motorYOriginCommandFuture, motorZOriginCommandFuture);
SprayTask.getInstance().clear();
deviceStatus.setSpraying(false);//是否正在进行喷涂
deviceStatus.setPaused(false);//是否暂停
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SUCCESS, "喷涂任务执行成功")); webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SUCCESS, "喷涂任务执行成功"));
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束")); webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束"));
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -184,13 +196,10 @@ public class SprayTaskExecutor {
log.info("喷涂任务失败", e); log.info("喷涂任务失败", e);
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.FAIL, "喷涂任务执行失败")); webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.FAIL, "喷涂任务执行失败"));
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束")); webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束"));
SprayTask.getInstance().clear(); SprayTask.getInstance().clear();
deviceStatus.setSpraying(false);//是否正在进行喷涂
deviceStatus.setPaused(false);//是否暂停
} finally { } finally {
SprayTask.getInstance().clear();
deviceStatus.setSpraying(false);
deviceStatus.setPaused(false);
deviceStatus.setSuspendable(false);
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SEND, "喷涂任务线程退出")); webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SEND, "喷涂任务线程退出"));
// 在线程结束后将 taskThread 设置为 null保证状态一致和资源释放 // 在线程结束后将 taskThread 设置为 null保证状态一致和资源释放
synchronized (this) { synchronized (this) {
@ -272,4 +281,11 @@ public class SprayTaskExecutor {
return sprayTaskStepList; return sprayTaskStepList;
} }
private void delay(long millisecond) {
try {
Thread.sleep(millisecond);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
} }

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

@ -23,11 +23,6 @@ public class DeviceStatus {
private volatile boolean paused = false; private volatile boolean paused = false;
/** /**
* 当前状态是否可以暂停
*/
private volatile boolean suspendable = false;
/**
* 是否正在清洗注射器管路 * 是否正在清洗注射器管路
*/ */
private volatile boolean cleaningSyringePipeline = false; private volatile boolean cleaningSyringePipeline = false;
@ -76,7 +71,6 @@ public class DeviceStatus {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.putOnce("spraying", spraying); json.putOnce("spraying", spraying);
json.putOnce("paused", paused); json.putOnce("paused", paused);
json.putOnce("suspendable", suspendable);
json.putOnce("cleaningSyringePipeline", cleaningSyringePipeline); json.putOnce("cleaningSyringePipeline", cleaningSyringePipeline);
json.putOnce("cleaningNozzlePipeline", cleaningNozzlePipeline); json.putOnce("cleaningNozzlePipeline", cleaningNozzlePipeline);
json.putOnce("prefilling", prefilling); json.putOnce("prefilling", prefilling);

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

@ -1,5 +1,6 @@
package com.qyft.ms.app.device.status; package com.qyft.ms.app.device.status;
import com.qyft.ms.app.model.bo.Point3D;
import com.qyft.ms.app.model.bo.SprayTaskParams; import com.qyft.ms.app.model.bo.SprayTaskParams;
import com.qyft.ms.app.model.bo.SprayTimes; import com.qyft.ms.app.model.bo.SprayTimes;
import lombok.Data; import lombok.Data;
@ -22,6 +23,14 @@ public class SprayTask {
*/ */
private volatile int currentStep = 0; private volatile int currentStep = 0;
/** /**
* 当前喷涂的玻片序号
*/
private Integer currentIndex = null;
/**
* 当前暂停点位
*/
private Point3D currentPausedPoint = null;
/**
* 当前喷涂任务所有参数 * 当前喷涂任务所有参数
*/ */
private List<SprayTaskParams> sprayTaskParams = null; private List<SprayTaskParams> sprayTaskParams = null;
@ -33,6 +42,7 @@ public class SprayTask {
* 标志喷涂任务暂停 * 标志喷涂任务暂停
*/ */
private volatile boolean paused = false; private volatile boolean paused = false;
/** /**
* 标志喷涂任务结束 * 标志喷涂任务结束
*/ */
@ -42,7 +52,7 @@ public class SprayTask {
*/ */
private volatile boolean spraying = false; private volatile boolean spraying = false;
private final Object pauseLock = new Object();
private final Object closeLock = new Object(); private final Object closeLock = new Object();
private SprayTask() { private SprayTask() {
@ -60,6 +70,8 @@ public class SprayTask {
currentStep = 0; currentStep = 0;
sprayTaskParams = null; sprayTaskParams = null;
sprayTimes = null; sprayTimes = null;
currentPausedPoint = null;
currentIndex = null;
} }
private static class Holder { private static class Holder {

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

@ -36,9 +36,7 @@ public class MatrixSprayContinue extends BaseCommandHandler {
if (!sprayTask.isSpraying()) { if (!sprayTask.isSpraying()) {
throw new RuntimeException("设备没有正在喷涂"); throw new RuntimeException("设备没有正在喷涂");
} }
sprayTask.setSpraying(true);
sprayTask.setPaused(false);
deviceStatus.setSpraying(true);
sprayTask.setPaused(false);//解除暂停
deviceStatus.setPaused(false); deviceStatus.setPaused(false);
SprayTimes sprayTimes = sprayTask.getSprayTimes(); SprayTimes sprayTimes = sprayTask.getSprayTimes();
return runAsync(() -> { return runAsync(() -> {
@ -60,9 +58,7 @@ public class MatrixSprayContinue extends BaseCommandHandler {
CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpForwardCommand); CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpForwardCommand);
commandWait(syringePumpForwardCommandFuture); commandWait(syringePumpForwardCommandFuture);
synchronized(sprayTask.getPauseLock()) {
sprayTask.getPauseLock().notify();
}
sprayTaskExecutor.startTask();
}); });
} }

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

@ -1,9 +1,11 @@
package com.qyft.ms.app.front.cmd.business; package com.qyft.ms.app.front.cmd.business;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.device.spray.SprayTaskExecutor; import com.qyft.ms.app.device.spray.SprayTaskExecutor;
import com.qyft.ms.app.device.status.DeviceStatus; import com.qyft.ms.app.device.status.DeviceStatus;
import com.qyft.ms.app.device.status.SprayTask; import com.qyft.ms.app.device.status.SprayTask;
import com.qyft.ms.app.model.bo.Point3D;
import com.qyft.ms.system.common.annotation.CommandMapping; 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.CommandFuture;
import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator;
@ -33,10 +35,11 @@ public class MatrixSprayPause extends BaseCommandHandler {
@Override @Override
public CompletableFuture<Void> handle(FrontCmdControlForm form) { public CompletableFuture<Void> handle(FrontCmdControlForm form) {
SprayTask sprayTask = SprayTask.getInstance(); SprayTask sprayTask = SprayTask.getInstance();
sprayTask.setPaused(true);//已暂停
sprayTask.setPaused(true);//设置已暂停
deviceStatus.setPaused(true); deviceStatus.setPaused(true);
deviceStatus.setSuspendable(false);
try { try {
sprayTaskExecutor.stopTask();//终止喷涂任务线程
DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop(); //停止推动注射泵 DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop(); //停止推动注射泵
CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpStopCommand); CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpStopCommand);
DeviceCommand nozzleValveCloseCommand = DeviceCommandGenerator.nozzleValveClose(); //关闭喷嘴阀 DeviceCommand nozzleValveCloseCommand = DeviceCommandGenerator.nozzleValveClose(); //关闭喷嘴阀
@ -53,9 +56,25 @@ public class MatrixSprayPause extends BaseCommandHandler {
CommandFuture motorZStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZStopCommand); CommandFuture motorZStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZStopCommand);
commandWait(motorXStopCommandFuture, motorYStopCommandFuture, motorZStopCommandFuture); commandWait(motorXStopCommandFuture, motorYStopCommandFuture, motorZStopCommandFuture);
while (!sprayTaskExecutor.taskThreadIsWaiting()) {
Thread.sleep(5);
}
//记录当前位置
DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet(); // 生成获得电机XYZ相对原点坐标指令
CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXyzPositionGetCommand);
commandWait(motorXyzPositionGetCommandFuture);
JSONObject motorXyzPositionGetCommandDeviceResult = motorXyzPositionGetCommandFuture.getResponseResult();
Double xAxisPosition = motorXyzPositionGetCommandDeviceResult.getJSONObject("data").getDouble("xAxisPosition");
Double yAxisPosition = motorXyzPositionGetCommandDeviceResult.getJSONObject("data").getDouble("yAxisPosition");
Double zAxisPosition = motorXyzPositionGetCommandDeviceResult.getJSONObject("data").getDouble("zAxisPosition");
Point3D point3D = new Point3D(xAxisPosition, yAxisPosition, zAxisPosition);
sprayTask.setCurrentPausedPoint(point3D);
//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);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

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

@ -71,10 +71,8 @@ public class MatrixSprayStart extends BaseCommandHandler {
} }
sprayTask.setCmdId(form.getCmdId()); sprayTask.setCmdId(form.getCmdId());
sprayTask.setCmdCode(form.getCmdCode()); sprayTask.setCmdCode(form.getCmdCode());
sprayTask.setClose(false);
sprayTask.setSpraying(true);//正在进行喷涂 sprayTask.setSpraying(true);//正在进行喷涂
deviceStatus.setSpraying(true); deviceStatus.setSpraying(true);
return runAsync(() -> { return runAsync(() -> {
//喷涂开始前先回原点 //喷涂开始前先回原点
DeviceCommand overallDeviceStatusGetCommand = DeviceCommandGenerator.overallDeviceStatusGet(); DeviceCommand overallDeviceStatusGetCommand = DeviceCommandGenerator.overallDeviceStatusGet();

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

@ -77,7 +77,6 @@ public class MatrixSprayStop extends BaseCommandHandler {
SprayTask.getInstance().clear(); SprayTask.getInstance().clear();
deviceStatus.setSpraying(false); deviceStatus.setSpraying(false);
deviceStatus.setPaused(false); deviceStatus.setPaused(false);
deviceStatus.setSuspendable(false);
}); });
} }
} }

9
src/main/java/com/qyft/ms/app/model/bo/Point3D.java

@ -4,10 +4,13 @@ import lombok.Data;
@Data @Data
public class Point3D { public class Point3D {
private double x;
private double y;
private double z;
public double x;
public double y;
public double z;
public Point3D(double x, double y, double z) { public Point3D(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
} }
} }

9
src/main/java/com/qyft/ms/app/model/bo/SprayTaskPointCollectorPushBO.java

@ -13,7 +13,7 @@ public class SprayTaskPointCollectorPushBO {
*/ */
String cmdCode; String cmdCode;
/** /**
* 当前是第几个玻片 从0开始
* 当前喷涂的是第几个玻片 从0开始
*/ */
Integer index; Integer index;
/** /**
@ -21,21 +21,16 @@ public class SprayTaskPointCollectorPushBO {
*/ */
Integer number; Integer number;
/** /**
* 总喷涂计数
*/
Integer sprayCount;
/**
* 当前点位坐标 * 当前点位坐标
*/ */
Point2D currentPoint; Point2D currentPoint;
public SprayTaskPointCollectorPushBO(String cmdId, String cmdCode, Integer index, Integer number, Integer sprayCount, Point2D currentPoint) {
public SprayTaskPointCollectorPushBO(String cmdId, String cmdCode, Integer index, Integer number, Point2D currentPoint) {
this.cmdId = cmdId; this.cmdId = cmdId;
this.cmdCode = cmdCode; this.cmdCode = cmdCode;
this.index = index; this.index = index;
this.number = number; this.number = number;
this.sprayCount = sprayCount;
this.currentPoint = currentPoint; this.currentPoint = currentPoint;
} }
} }

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

@ -32,10 +32,10 @@ public class SprayTimes {
private Double movingSpeed; private Double movingSpeed;
@Schema(description = "田字格喷涂中间延时数,非田字格不传递该参数") @Schema(description = "田字格喷涂中间延时数,非田字格不传递该参数")
private Double gridDelay;
private Long gridDelay;
@Schema(description = "本次喷涂结束后延时数") @Schema(description = "本次喷涂结束后延时数")
private Double delay;
private Long delay;
@Schema(description = "喷涂左上角x") @Schema(description = "喷涂左上角x")
private Double x1; private Double x1;

7
src/main/java/com/qyft/ms/app/service/VirtualDeviceService.java

@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
public class VirtualDeviceService { public class VirtualDeviceService {
private final DeviceCommandService deviceCommandService; private final DeviceCommandService deviceCommandService;
public void completeCommandResponse(DeviceCommand cmdToDevice) { public void completeCommandResponse(DeviceCommand cmdToDevice) {
new Thread(() -> { new Thread(() -> {
try { try {
@ -55,6 +56,12 @@ public class VirtualDeviceService {
data.putOnce("temperature", 60); data.putOnce("temperature", 60);
jsonObject.putOnce("data", data); jsonObject.putOnce("data", data);
} }
}else if (device.contains("xyz")) {
JSONObject data = new JSONObject();
data.putOnce("xAxisPosition", 20);
data.putOnce("yAxisPosition", 20);
data.putOnce("zAxisPosition", 15);
jsonObject.putOnce("data", data);
} }
} }

1
src/main/java/com/qyft/ms/system/core/listener/DeviceTcpMessageEventListener.java

@ -38,7 +38,6 @@ public class DeviceTcpMessageEventListener {
SprayTask.getInstance().clear(); SprayTask.getInstance().clear();
deviceStatus.setSpraying(false); deviceStatus.setSpraying(false);
deviceStatus.setPaused(false); deviceStatus.setPaused(false);
deviceStatus.setSuspendable(false);
deviceStatus.setStopPressed(true); deviceStatus.setStopPressed(true);
deviceStatus.setSelfTestCompleted(false); deviceStatus.setSelfTestCompleted(false);
deviceCommandService.releaseAllCommandFutures(); deviceCommandService.releaseAllCommandFutures();

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

@ -75,13 +75,6 @@ public class DeviceCommandService {
public CommandFuture sendCommandSprayTask(String cmdId, String cmdCode, DeviceCommand deviceCommand) throws Exception { public CommandFuture sendCommandSprayTask(String cmdId, String cmdCode, DeviceCommand deviceCommand) throws Exception {
SprayTask sprayTask = SprayTask.getInstance(); SprayTask sprayTask = SprayTask.getInstance();
synchronized (sprayTask.getPauseLock()) {
while (sprayTask.isPaused()) {
log.info("喷涂暂停");
sprayTask.getPauseLock().wait();
log.info("喷涂继续");
}
}
synchronized (sprayTask.getCloseLock()) { synchronized (sprayTask.getCloseLock()) {
if (sprayTask.isClose() || Thread.currentThread().isInterrupted()) { if (sprayTask.isClose() || Thread.currentThread().isInterrupted()) {
throw new InterruptedException(); throw new InterruptedException();

Loading…
Cancel
Save