Browse Source

不记得改了什么

tags/1.0
白凤吉 4 months ago
parent
commit
0594e7a47c
  1. 42
      src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java
  2. 10
      src/main/java/com/qyft/ms/app/device/status/SprayTask.java
  3. 55
      src/main/java/com/qyft/ms/app/front/cmd/business/DeviceSelfTest.java
  4. 3
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayContinue.java
  5. 5
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStop.java
  6. 13
      src/main/java/com/qyft/ms/app/model/bo/SprayTaskPointCollectorPushBO.java
  7. 4
      src/main/java/com/qyft/ms/app/model/bo/SprayTaskSprayed.java
  8. 5
      src/main/java/com/qyft/ms/system/common/device/command/CommandFuture.java
  9. 4
      src/main/java/com/qyft/ms/system/controller/FrontCmdController.java
  10. 3
      src/main/java/com/qyft/ms/system/core/handler/BaseCommandHandler.java
  11. 21
      src/main/java/com/qyft/ms/system/core/listener/DeviceTcpMessageEventListener.java
  12. 9
      src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java

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

@ -24,6 +24,7 @@ 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;
@ -74,8 +75,11 @@ public class SprayTaskExecutor {
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.START, "喷涂任务开始执行"));
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);
@ -88,17 +92,25 @@ public class SprayTaskExecutor {
DeviceCommand motorZPositionSetAboveSlideCommand = DeviceCommandGenerator.motorZPositionSet(height, 15.0);
CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand);
commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture, motorZPositionSetAboveSlideCommandFuture);
}else{
sprayTask.setFirstImmobility(false);
}
DeviceCommand syringePumpForwardCommand = DeviceCommandGenerator.syringePumpForward(sprayTask.getSprayParams().getVolume());//推动移动注射泵
CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpForwardCommand);
commandWait(syringePumpForwardCommandFuture);
Thread.sleep(100);
sprayTask.setSuspendable(true);//可以暂停单次喷涂范围内可以进行暂停
deviceStatus.setSuspendable(true);
double cacheXPoint = -1;
double cacheYPoint = -1;
DecimalFormat df = new DecimalFormat("#.##");
for (int i = 0; i < sprayTaskStep.getSpraySteps().size(); i++) {//单次喷涂
if(currentIndex != sprayTaskStep.getIndex()) {
sprayNum = 0;
currentIndex = sprayTaskStep.getIndex();
}
if (currentStep < reCurrentStep) {
currentStep++;
continue;
@ -112,6 +124,9 @@ public class SprayTaskExecutor {
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.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), xSprayStepCommands);
commandFutureList.add(commandFuture);
@ -123,38 +138,31 @@ public class SprayTaskExecutor {
cacheYPoint = aYPoint;
}
CommandFuture[] commandFutureArray = commandFutureList.toArray(new CommandFuture[0]);
Point2D currentPoint;
Point2D nextPoint = null;
if (i != 0) {
List<DeviceCommand> currentSprayStepCommands = sprayTaskStep.getSpraySteps().get(i - 1);
double currentXPoint = (Double) currentSprayStepCommands.get(0).getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0];
double currentYPoint = 75.5 - (Double) currentSprayStepCommands.get(1).getParam().get("position");
currentPoint = new Point2D(currentXPoint, currentYPoint);
double nextXPoint = (Double) xSprayStepCommands.getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0];
double nextYPoint = 75.5 - (Double) ySprayStepCommands.getParam().get("position");
nextPoint = new Point2D(nextXPoint, nextYPoint);
SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayTaskStep.getIndex(), sprayNum, currentPoint, nextPoint);
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);
}
commandWait(commandFutureArray);
currentStep++;
sprayTask.setCurrentStep(currentStep);//将当前的喷涂进度缓存
if (nextPoint != null) {
//将当前点位缓存
SprayTaskSprayed sprayTaskSprayed = new SprayTaskSprayed();
sprayTaskSprayed.setNumber(sprayNum);
sprayTaskSprayed.setIndex(sprayTaskStep.getIndex());
sprayTaskSprayed.setSprayedPoints(new Point2D(nextPoint.getX(), nextPoint.getY()));
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);
}
}
sprayTask.setSuspendable(false);//不可暂停
deviceStatus.setSuspendable(false);
DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop();//停止推动注射泵
CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpStopCommand);
commandWait(syringePumpStopCommandFuture);
sprayCount++;
sprayNum++;
}

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

@ -45,6 +45,9 @@ public class SprayTask {
* 当前正在执行的步骤序号
*/
private volatile int currentStep = 0;
private volatile boolean firstImmobility = false;
/**
* 缓存前端的参数
*/
@ -114,11 +117,11 @@ public class SprayTask {
public synchronized void addSprayTaskSprayed(SprayTaskSprayed task) {
LinkedHashSet<Integer> distinctNumbers = new LinkedHashSet<>();
for (SprayTaskSprayed item : sprayTaskSprayedList) {
distinctNumbers.add(item.getNumber());
distinctNumbers.add(item.getSprayCount());
}
if (!distinctNumbers.contains(task.getNumber()) && distinctNumbers.size() >= 4) {
if (!distinctNumbers.contains(task.getSprayCount()) && distinctNumbers.size() >= 120) {
Integer oldestNumber = distinctNumbers.iterator().next();
sprayTaskSprayedList.removeIf(item -> item.getNumber().equals(oldestNumber));
sprayTaskSprayedList.removeIf(item -> item.getSprayCount().equals(oldestNumber));
}
sprayTaskSprayedList.add(task);
}
@ -131,6 +134,7 @@ public class SprayTask {
spraying = false;
sprayTaskStepList.clear();
currentStep = 0;
firstImmobility = false;
sprayTaskSprayedList.clear();
cacheParams = null;
}

55
src/main/java/com/qyft/ms/app/front/cmd/business/DeviceSelfTest.java

@ -1,5 +1,6 @@
package com.qyft.ms.app.front.cmd.business;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.device.status.DeviceStatus;
import com.qyft.ms.app.service.SelfTestService;
import com.qyft.ms.system.common.annotation.CommandMapping;
@ -13,7 +14,11 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
/**
* 设备自检指令
@ -30,27 +35,61 @@ public class DeviceSelfTest extends BaseCommandHandler {
@Override
public CompletableFuture<Void> handle(FrontCmdControlForm form) {
return runAsync(() -> {
DeviceCommand motorXOriginCommand = DeviceCommandGenerator.motorXOrigin(); // x轴回原点
CommandFuture motorXOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXOriginCommand);
DeviceCommand overallDeviceStatusGetCommand = DeviceCommandGenerator.overallDeviceStatusGet();
CommandFuture overallDeviceStatusGetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), overallDeviceStatusGetCommand);
commandWait(overallDeviceStatusGetCommandFuture);
DeviceCommand motorYOriginCommand = DeviceCommandGenerator.motorYOrigin();//y轴回原点
CommandFuture motorYOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYOriginCommand);
CommandFuture motorXOriginCommandFuture = null;
CommandFuture motorYOriginCommandFuture = null;
CommandFuture motorZOriginCommandFuture = null;
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轴回原点
CommandFuture motorZOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZOriginCommand);
commandWait(motorXOriginCommandFuture, motorYOriginCommandFuture, motorZOriginCommandFuture);
try {
motorZOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZOriginCommand);
futureList.add(motorZOriginCommandFuture);
}
CommandFuture[] commandFutureArray = futureList.toArray(new CommandFuture[0]);
commandWait(commandFutureArray);
boolean selfTestCompleted = true;
if (motorXOriginCommandFuture != null) {
if (motorXOriginCommandFuture.getResponseResult().getBool("success")) {
selfTestService.getSelfTestStatus().setXAxisAtOrigin(true);
} else {
selfTestCompleted = false;
}
}
if (motorYOriginCommandFuture != null) {
if (motorYOriginCommandFuture.getResponseResult().getBool("success")) {
selfTestService.getSelfTestStatus().setYAxisAtOrigin(true);
} else {
selfTestCompleted = false;
}
}
if (motorZOriginCommandFuture != null) {
if (motorZOriginCommandFuture.getResponseResult().getBool("success")) {
selfTestService.getSelfTestStatus().setZAxisAtOrigin(true);
} else {
selfTestCompleted = false;
}
}
if (selfTestCompleted) {
deviceStatus.setSelfTestCompleted(true);
} catch (Exception ignored) {
} else {
throw new RuntimeException("自检未完成");
}
});
}

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

@ -37,7 +37,9 @@ public class MatrixSprayContinue extends BaseCommandHandler {
throw new RuntimeException("设备没有正在喷涂");
}
sprayTask.setSpraying(true);
sprayTask.setPaused(false);
deviceStatus.setSpraying(true);
deviceStatus.setPaused(false);
return runAsync(() -> {
DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenSyringePipeline();//打开三通阀喷嘴管路
@ -57,6 +59,7 @@ public class MatrixSprayContinue extends BaseCommandHandler {
CommandFuture highVoltageOpenCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageOpenCommand);
commandWait(highVoltageOpenCommandFuture);
}
sprayTask.setFirstImmobility(true);
sprayTaskExecutor.startTask();
});

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

@ -4,11 +4,14 @@ 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.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;
@ -29,6 +32,7 @@ public class MatrixSprayStop extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private final SprayTaskExecutor sprayTaskExecutor;
private final DeviceStatus deviceStatus;
private final WebSocketService webSocketService;
@Override
public CompletableFuture<Void> handle(FrontCmdControlForm form) {
@ -36,6 +40,7 @@ public class MatrixSprayStop extends BaseCommandHandler {
if (!sprayTask.isSpraying()) {
throw new RuntimeException("设备没有正在喷涂");
}
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束"));
SprayTask.getInstance().clear();
deviceStatus.setSpraying(false);
deviceStatus.setPaused(false);

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

@ -21,20 +21,21 @@ public class SprayTaskPointCollectorPushBO {
*/
Integer number;
/**
* 当前点位坐标
* 总喷涂计数
*/
Point2D currentPoint;
Integer sprayCount;
/**
* 下一个点位坐标
* 当前点位坐标
*/
Point2D nextPoint;
Point2D currentPoint;
public SprayTaskPointCollectorPushBO(String cmdId, String cmdCode, Integer index, Integer number, Point2D currentPoint, Point2D nextPoint) {
public SprayTaskPointCollectorPushBO(String cmdId, String cmdCode, Integer index, Integer number, Integer sprayCount, Point2D currentPoint) {
this.cmdId = cmdId;
this.cmdCode = cmdCode;
this.index = index;
this.number = number;
this.sprayCount = sprayCount;
this.currentPoint = currentPoint;
this.nextPoint = nextPoint;
}
}

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

@ -16,6 +16,10 @@ public class SprayTaskSprayed {
*/
Integer number;
/**
* 总喷涂计数
*/
Integer sprayCount;
/**
* 已喷涂点位
*/
private volatile Point2D sprayedPoints;

5
src/main/java/com/qyft/ms/system/common/device/command/CommandFuture.java

@ -7,6 +7,7 @@ import lombok.Setter;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
@Setter
@Getter
public class CommandFuture {
/**
@ -16,11 +17,9 @@ public class CommandFuture {
/**
* 用于保存response反馈
*/
private final CompletableFuture<JSONObject> responseFuture = new CompletableFuture<>();
private CompletableFuture<JSONObject> responseFuture = new CompletableFuture<>();
@Setter
private long startSendTime;
@Setter
private long endSendTime;
/**

4
src/main/java/com/qyft/ms/system/controller/FrontCmdController.java

@ -42,6 +42,10 @@ public class FrontCmdController {
return Result.failed("未进行自检,无法执行业务指令");
}
}
if(deviceStatus.isStopPressed()){
log.error("设备急停中");
return Result.failed("设备急停中");
}
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.RECEIVE, "已收到业务指令请求,开始处理"));
CommandHandler commandHandler = registry.getHandler(cmdCode);
if (commandHandler == null) {

3
src/main/java/com/qyft/ms/system/core/handler/BaseCommandHandler.java

@ -8,7 +8,6 @@ import com.qyft.ms.system.functions.CommandHandler;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
public abstract class BaseCommandHandler implements CommandHandler {
@ -18,7 +17,7 @@ public abstract class BaseCommandHandler implements CommandHandler {
}
protected void commandWait(CommandFuture... futures) throws ExecutionException, InterruptedException {
protected void commandWait(CommandFuture... futures) throws Exception {
CompletableFuture<?>[] responseFutures = Arrays.stream(futures)
.map(CommandFuture::getResponseFuture)
.toArray(CompletableFuture[]::new);

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

@ -1,6 +1,9 @@
package com.qyft.ms.system.core.listener;
import cn.hutool.json.JSONObject;
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.core.event.DeviceTcpMessageEvent;
import com.qyft.ms.system.service.device.DeviceCommandService;
import lombok.extern.slf4j.Slf4j;
@ -12,14 +15,30 @@ import org.springframework.stereotype.Component;
public class DeviceTcpMessageEventListener {
private final DeviceCommandService deviceCommandService;
private final DeviceStatus deviceStatus;
private final SprayTaskExecutor sprayTaskExecutor;
public DeviceTcpMessageEventListener(DeviceCommandService deviceCommandService) {
public DeviceTcpMessageEventListener(DeviceCommandService deviceCommandService, DeviceStatus deviceStatus, SprayTaskExecutor sprayTaskExecutor) {
this.deviceCommandService = deviceCommandService;
this.deviceStatus = deviceStatus;
this.sprayTaskExecutor = sprayTaskExecutor;
}
@EventListener
public void handleDeviceTcpMessageEvent(DeviceTcpMessageEvent event) {
JSONObject deviceResult = event.getDeviceResult();
String tag = deviceResult.getStr("tag");
String eventType = deviceResult.getStr("event_type");
if ("system_e_stop_pressed".equals(eventType)) {//系统急停按钮被按下
sprayTaskExecutor.stopTask();//终止喷涂任务线程
SprayTask.getInstance().clear();
deviceStatus.setSpraying(false);
deviceStatus.setPaused(false);
deviceStatus.setSuspendable(false);
deviceStatus.setStopPressed(true);
} else if ("system_e_stop_released".equals(eventType)) {//系统急停按钮被释放
deviceStatus.setStopPressed(false);
}
deviceCommandService.handleDeviceResult(deviceResult);
}
}

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

@ -2,6 +2,7 @@ package com.qyft.ms.system.service.device;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.qyft.ms.app.device.spray.SprayTaskExecutor;
import com.qyft.ms.app.device.status.DeviceStatus;
import com.qyft.ms.system.common.constant.CommandStatus;
import com.qyft.ms.system.common.device.command.CommandFuture;
@ -26,7 +27,6 @@ public class DeviceCommandService {
private final ConcurrentMap<Integer, CommandFuture> commandFutureMap = new ConcurrentHashMap<>();
private final DeviceTcpClient deviceTcpClient;
private final DeviceStatus deviceStatus;
private final WebSocketService webSocketService;
@ -110,12 +110,7 @@ public class DeviceCommandService {
log.info("RESPONSE {}", JSONUtil.toJsonStr(deviceResult));
completeCommandResponse(deviceResult);
} else if ("EVENT".equals(tag)) {
String eventType = deviceResult.getStr("event_type");
if ("system_e_stop_pressed".equals(eventType)) {//系统急停按钮被按下
deviceStatus.setStopPressed(true);
} else if ("system_e_stop_released".equals(eventType)) {//系统急停按钮被释放
deviceStatus.setStopPressed(false);
}
} else if ("STATUS".equals(tag)) {
}

Loading…
Cancel
Save